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