| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "messages": { |
| 5 | "cases": [ |
| 6 | { |
| 7 | "messages": [ |
| 8 | { |
| 9 | "app": "state", |
| 10 | "state": "{var[$perm_key] = $value;if(var[$perm_key] == 0) var[$perm_key] = false;var[$byte_key] += $base_inp;var[$TOTAL] += $base_inp;response['message'] = 'Approved '||$approve||' to spend '||$value ||' from your account';}" |
| 11 | } |
| 12 | ], |
| 13 | "if": "{trigger.data.approve AND $base == $BYTE_INP}", |
| 14 | "init": "{$approve = trigger.data.approve;$perm_key = $PERM || $addr || $approve;if(!is_valid_address($approve) OR $approve == $addr) bounce('approve param invalid, specify address to approve instead of any other value');if(!$value) bounce('Value param missing');if(typeof($value) != 'number' OR $value < 0) bounce('Value param invalid');}" |
| 15 | }, |
| 16 | { |
| 17 | "messages": [ |
| 18 | { |
| 19 | "app": "payment", |
| 20 | "payload": { |
| 21 | "asset": "base", |
| 22 | "outputs": [ |
| 23 | { |
| 24 | "address": "{$addr}", |
| 25 | "amount": "{$w_amount + $base - $w_fee}" |
| 26 | } |
| 27 | ] |
| 28 | } |
| 29 | }, |
| 30 | { |
| 31 | "app": "state", |
| 32 | "state": "{var[$byte_key] = false;var[$TOTAL] -= $w_amount;response['message'] = 'Withdrawn '||$w_amount||' bytes less '||$w_fee||' fee from your account';}" |
| 33 | } |
| 34 | ], |
| 35 | "if": "{trigger.data.withdraw_bytes AND $base == $BYTE_INP}", |
| 36 | "init": "{$user_bal = var[$byte_key];if(!$user_bal) bounce('No bytes to withdraw');$w_amount = $balance < $user_bal ? $balance : $user_bal;$wt = round($w_amount / $BYTE_INP);$w_fee = !!$ATTESTOR_ADDR AND $free_mode ?0 : (($wt > 2) ? 462+$wt*60 : 522);}" |
| 37 | }, |
| 38 | { |
| 39 | "messages": [ |
| 40 | { |
| 41 | "app": "state", |
| 42 | "state": "{var[$addr_key] += $asset_inp;var[$byte_key] += $base_inp;var[$TOTAL] += $base_inp;response['message'] = 'Added '||$asset_inp||' to your account';}" |
| 43 | } |
| 44 | ], |
| 45 | "if": "{$asset AND $base == $BYTE_INP}", |
| 46 | "init": "{if($asset == 'ambiguous') bounce('Only 1 asset per tx');if($asset != $ASSET) bounce('You must deposit '||$ASSET);$asset_inp = trigger.output[[asset!=base]];}" |
| 47 | }, |
| 48 | { |
| 49 | "messages": [ |
| 50 | { |
| 51 | "app": "payment", |
| 52 | "payload": { |
| 53 | "asset": "{$ASSET}", |
| 54 | "outputs": [ |
| 55 | { |
| 56 | "address": "{$addr}", |
| 57 | "amount": "{$w_amount}" |
| 58 | } |
| 59 | ] |
| 60 | } |
| 61 | }, |
| 62 | { |
| 63 | "app": "state", |
| 64 | "state": "{if(!!$ATTESTOR_ADDR AND $free_mode)$w_fee = 0;else$w_fee = unit[response_unit].headers_commission + unit[response_unit].payload_commission;var[$addr_key] -= $w_amount;if(var[$addr_key] == 0) var[$addr_key]=false;var[$byte_key] += ($base_inp-$w_fee);var[$TOTAL] += ($base_inp-$w_fee);response['message'] = 'Withdrawn '||$w_amount||' from your account';}" |
| 65 | } |
| 66 | ], |
| 67 | "if": "{trigger.data.withdraw AND $base == $BYTE_INP}", |
| 68 | "init": "{if(!$addr_q) bounce('Nothing to withdraw');$max_w = $addr_q-($addr_q % 1);if(!$value) bounce('Value param missing, max to withdraw '||$max_w) ;$w_amount = $value - ($value % 1);if($w_amount <= 0) bounce('Max to withdraw '||$max_w);if($w_amount > $max_w) bounce('Not enough asset, max to withdraw '||$max_w);}" |
| 69 | }, |
| 70 | { |
| 71 | "messages": [ |
| 72 | { |
| 73 | "app": "state", |
| 74 | "state": "{var[$ADDR|| $to] += $value;var[$addr_key] -= $value;if(var[$addr_key] == 0) var[$addr_key] = false;var[$byte_key] += $base_inp;var[$TOTAL] += $base_inp;response['message'] = 'Transferred '||$value||' to '||$to;}" |
| 75 | } |
| 76 | ], |
| 77 | "if": "{trigger.data.transfer AND $base == $BYTE_INP}", |
| 78 | "init": "{$to = trigger.data.transfer;if(!is_valid_address($to) OR $to == $addr) bounce('transfer param invalid, specify address to instead of any other value');if(!$addr_q) bounce('No funds found');if(!$value) bounce('Value param missing');if($value > $addr_q) bounce('You have max '||$addr_q);}" |
| 79 | }, |
| 80 | { |
| 81 | "messages": [ |
| 82 | { |
| 83 | "app": "state", |
| 84 | "state": "{var[$ADDR|| $to] += $value;var[$from_key] -= $value;if(var[$from_key] == 0) var[$from_key] = false;var[$perm_key] -= $value;if(var[$perm_key] == 0) var[$perm_key] = false;var[$byte_key] += $base_inp;var[$TOTAL] += $base_inp;response['message'] = 'Transferred '||$value||' to '||$to;}" |
| 85 | } |
| 86 | ], |
| 87 | "if": "{trigger.data.transfer_from AND $base == $BYTE_INP}", |
| 88 | "init": "{$from = trigger.data.transfer_from;$to = trigger.data.to;$from_key = $ADDR|| $from;$perm_key = $PERM || $from || $addr;if(!is_valid_address($from)) bounce('transfer_from param invalid, specify from address instead of any other value');if(!$to) bounce('To param missing');if(!is_valid_address($to)) bounce('To param invalid');if(!var[$from_key]) bounce('Account have no funds');if(!$value) bounce('Value param missing');if(!var[$perm_key]) bounce('Not allowed to spend');if(var[$perm_key] < $value) bounce('You can spend max '||var[$perm_key]);if(var[$from_key] < $value) bounce('Account have '||var[$from_key]);}" |
| 89 | }, |
| 90 | { |
| 91 | "messages": [ |
| 92 | { |
| 93 | "app": "state", |
| 94 | "state": "{if(trigger.output[[asset!=base]].asset != 'none') bounce('Allowed asset: '||$ASSET);response['asset'] = 'Allowed asset: '||$ASSET;response['accepted_params'] = 'withdraw, transfer, transfer_from, approve, withdraw_bytes';response['usage'] = 'Send '||$BYTE_INP||' bytes and param = 1 for continue.';response['message'] = 'Received donation for funding AA operation, thaanks!';}" |
| 95 | } |
| 96 | ] |
| 97 | } |
| 98 | ] |
| 99 | }, |
| 100 | "init": "{$ASSET = 'hd936lRtPN11pkgNv8qVnqN2OHMyAp8P/NsLp6KsuqA=';$BYTE_INP = 10000;$FREE_LIMIT = 3000;$ADDR = 'a';$PERM = 'p';$BYTE = 'b';$TOTAL = 'total';$base = trigger.output[[asset=base]];$trigger_cost = unit[trigger.unit].headers_commission + unit[trigger.unit].payload_commission;$addr = trigger.address;$balance = balance[base] - $base - storage_size;$free_mode = ($balance - var[$TOTAL]) > $FREE_LIMIT ;$addr_key = $ADDR || $addr;$addr_q = var[$addr_key];$byte_key = $BYTE || $addr;$base_inp = $base + ($free_mode?$trigger_cost:0);$value = trigger.data.value;if(!trigger.data.approve AND $value AND (typeof($value) != 'number' OR $value <= 0)) bounce('Value param invalid');if(trigger.output[[asset!=base]].asset != 'none')$asset = trigger.output[[asset!=base]].asset;}" |
| 101 | } |
| 102 | ] |