| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "messages": { |
| 5 | "cases": [ |
| 6 | { |
| 7 | "if": "{ |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | $project = "5IZAANLACSTY5ILLCJ6N5P4OX73ZWRJY" ; |
| 13 | $min_poolsize = 3 ; |
| 14 | $processors_per_round = 2 ; |
| 15 | $storage = 1000 ; |
| 16 | |
| 17 | $min_round_cost = $processors_per_round * 21000 + $storage * 3 ; |
| 18 | if( !var[ $project ][ "count" ] ) bounce( "$project AA missing 'count'") ; |
| 19 | if( var[ $project ][ "count" ] < $min_poolsize ) bounce( "waiting for " || $project || " to have " || $min_poolsize || " registered obots" ) ; |
| 20 | if( trigger.data.computation_rounds ) bounce( " computation_rounds = " || var[ 'computation_rounds' ] ) ; |
| 21 | $min_poolsize >= 3 |
| 22 | }", |
| 23 | "messages": { |
| 24 | "cases": [ |
| 25 | { |
| 26 | "if": "{ |
| 27 | if( !trigger.data.message AND !trigger.data.round AND trigger.output[[asset=base]] < $min_round_cost ) bounce( 'need to send ' || $min_round_cost || ' to request a new round'); |
| 28 | |
| 29 | ( !trigger.data.message AND !trigger.data.round ) |
| 30 | }", |
| 31 | "init": "{ |
| 32 | |
| 33 | $process = '{ "args": ' || '"obotic"' || ', "processor": 1, "round": ' || ( var[ "round" ] + 1 ) || ' }' ; |
| 34 | |
| 35 | }", |
| 36 | "messages": [ |
| 37 | { |
| 38 | "app": "data", |
| 39 | "payload": { |
| 40 | "message": "{ $process }", |
| 41 | "nosend": true |
| 42 | } |
| 43 | }, |
| 44 | { |
| 45 | "app": "payment", |
| 46 | "payload": { |
| 47 | "asset": "base", |
| 48 | "outputs": [ |
| 49 | { |
| 50 | "address": "{ $project }", |
| 51 | "amount": "{ trigger.output[[asset=base]] - $storage }" |
| 52 | } |
| 53 | ] |
| 54 | } |
| 55 | }, |
| 56 | { |
| 57 | "app": "state", |
| 58 | "state": "{ var[ "round" ] += 1 ; }" |
| 59 | } |
| 60 | ] |
| 61 | }, |
| 62 | { |
| 63 | "if": "{ |
| 64 | trigger.address == $project AND trigger.data.message AND trigger.data.choosen |
| 65 | }", |
| 66 | "init": "{ |
| 67 | $process = json_parse( trigger.data.message ) ; |
| 68 | $args = json_stringify( $process.args ) ; |
| 69 | $processor = json_parse( $process.processor ) ; |
| 70 | $round = $process.round ; |
| 71 | $obot = trigger.data.choosen ; |
| 72 | $fee = var[ $obot ][ "fee" ] otherwise 21000 ; |
| 73 | }", |
| 74 | "messages": [ |
| 75 | { |
| 76 | "if": "{ $processor <= $processors_per_round AND trigger.output[[asset=base]] > ( $fee + $storage ) |
| 77 | }", |
| 78 | "init": "{ |
| 79 | $morebot = '{ "more": "here", "args": ' || $args || ', "processor": ' || ( $processor + 1 ) || ', "round": ' || $round || ' }' ; |
| 80 | response[ "morebot" ] = $morebot ; |
| 81 | }", |
| 82 | "app": "payment", |
| 83 | "payload": { |
| 84 | "asset": "base", |
| 85 | "outputs": [ |
| 86 | { |
| 87 | "address": "{ $obot }", |
| 88 | "amount": "{ $fee }" |
| 89 | } |
| 90 | ] |
| 91 | } |
| 92 | }, |
| 93 | { |
| 94 | "if": "{ $processor <= $processors_per_round AND trigger.output[[asset=base]] > ( $fee + $storage ) |
| 95 | }", |
| 96 | "app": "data", |
| 97 | "payload": { |
| 98 | "message": "{ $morebot }", |
| 99 | "args": "{ $args }", |
| 100 | "round": "{ $round }", |
| 101 | "nosend": true |
| 102 | } |
| 103 | }, |
| 104 | { |
| 105 | "app": "state", |
| 106 | "state": "{ |
| 107 | response[ "processor" ] = $processor ; |
| 108 | |
| 109 | response[ "args" ] = $args ; |
| 110 | response[ "round" ] = $round ; |
| 111 | |
| 112 | /* |
| 113 | var[ $round || "_" || $processor ] = $obot ; |
| 114 | |
| 115 | if( $round ){ |
| 116 | var[ "g" || $round ] = timestamp + 43200; |
| 117 | response[ "message" ] = $message; |
| 118 | response[ "round" ] = $round; |
| 119 | response[ "redplayer" ] = $sendred; |
| 120 | response[ "blueplayer" ] = $sendblue; |
| 121 | } |
| 122 | if( trigger.address == $project ){ |
| 123 | var[ "redaddr" ] += 1; |
| 124 | var[ "r" || var[ "redaddr" ] ] = trigger.data.choosen; |
| 125 | } |
| 126 | if( trigger.address == $blue ){ |
| 127 | var[ "blueaddr" ] += 1; |
| 128 | var[ "b" || var[ "blueaddr" ] ] = trigger.data.choosen; |
| 129 | } |
| 130 | */ |
| 131 | }" |
| 132 | } |
| 133 | ] |
| 134 | } |
| 135 | ] |
| 136 | } |
| 137 | } |
| 138 | ] |
| 139 | } |
| 140 | } |
| 141 | ] |