| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $return_fee = 1000; |
| 6 | $attestor = 'BK54UAWZ6KTI3K7PWH7PRPHVYWTIZZXH'; |
| 7 | $attestor_name = 'email'; |
| 8 | $attested_user_id = attestation[[attestors=$attestor, address=trigger.address]].user_id; |
| 9 | if (!$attested_user_id) bounce("Your address is not attested by "||$attestor_name||" attestor "|| $attestor); |
| 10 | $balance_key = "user_id_"||$attested_user_id||"_balance"; |
| 11 | }", |
| 12 | "messages": { |
| 13 | "cases": [ |
| 14 | { |
| 15 | "if": "{!trigger.data.withdraw}", |
| 16 | "messages": [ |
| 17 | { |
| 18 | "app": "state", |
| 19 | "state": "{ |
| 20 | var[$balance_key] = var[$balance_key] + trigger.output[[asset=base]]; |
| 21 | response['message'] = "Total balance for your "||$attestor_name||" account will be " || var[$balance_key] || " bytes."; |
| 22 | }" |
| 23 | } |
| 24 | ] |
| 25 | }, |
| 26 | { |
| 27 | "init": "{ |
| 28 | if (!var[$balance_key]) bounce("Your address is attested but the balance for your account is not found"); |
| 29 | if (typeof(trigger.data.withdraw)!='number') bounce("Please enter number of bytes in the 'withdraw' data field. Your balance is " || var[$balance_key] || " bytes."); |
| 30 | if (var[$balance_key] < trigger.data.withdraw) bounce('Not enough funds. The maximum amount you can withdraw is ' || var[$balance_key] || ' bytes.'); |
| 31 | if (trigger.output[[asset=base]] < $return_fee) bounce('The sending amount is less than the transaction fee '|| $return_fee ||' bytes. Please increase it.'); |
| 32 | }", |
| 33 | "messages": [ |
| 34 | { |
| 35 | "app": "payment", |
| 36 | "payload": { |
| 37 | "asset": "base", |
| 38 | "outputs": [ |
| 39 | { |
| 40 | "address": "{trigger.address}", |
| 41 | "amount": "{trigger.data.withdraw + trigger.output[[asset=base]] - $return_fee}" |
| 42 | } |
| 43 | ] |
| 44 | } |
| 45 | }, |
| 46 | { |
| 47 | "app": "state", |
| 48 | "state": "{ |
| 49 | response['message'] = 'You will receive ' || (trigger.data.withdraw + trigger.output[[asset=base]]) - $return_fee || ' bytes to your account (' || trigger.data.withdraw || ' bytes from your account + '|| trigger.output[[asset=base]] || ' bytes bounced back - '|| $return_fee || ' bytes transaction fee)'; |
| 50 | var[$balance_key] = var[$balance_key] - trigger.data.withdraw; |
| 51 | }" |
| 52 | } |
| 53 | ] |
| 54 | } |
| 55 | ] |
| 56 | } |
| 57 | } |
| 58 | ] |