| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | |
| 6 | $return_fee = 1000; |
| 7 | $attestor = 'BK54UAWZ6KTI3K7PWH7PRPHVYWTIZZXH'; |
| 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 ' || $attestor); |
| 10 | $balance = 'user_id_'||$attested_user_id||'_balance'; |
| 11 | }", |
| 12 | "messages": { |
| 13 | "cases": [ |
| 14 | { |
| 15 | "if": "{!trigger.data.withdraw}", |
| 16 | "init": "{ |
| 17 | if (!attestation[[attestors=$attestor, address=trigger.address]].profile_hash AND trigger.data.public!='allow') bounce("This address attestation is not private. Anybody can see account associated with your balance. If you still want to continue please add 'public' data field with value 'allow'"); |
| 18 | }", |
| 19 | "messages": [ |
| 20 | { |
| 21 | "app": "state", |
| 22 | "state": "{ |
| 23 | var[$balance] = var[$balance] + trigger.output[[asset=base]]; |
| 24 | response['message'] = "Total balance for your account will be " || var[$balance] || " bytes."; |
| 25 | }" |
| 26 | } |
| 27 | ] |
| 28 | }, |
| 29 | { |
| 30 | "init": "{ |
| 31 | if (!var[$balance]) bounce("Your address is attested but the balance for your account is not found"); |
| 32 | if (typeof(trigger.data.withdraw)!='number') bounce("Please enter numbers of bytes you want to withdraw from your account"); |
| 33 | if (var[$balance] + trigger.output[[asset=base]] < trigger.data.withdraw + $return_fee) bounce('Not enough funds. The maximum amount you can withdraw for this user_id is ' || var[$balance] - $return_fee || 'bytes'); |
| 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 will be released - '|| $return_fee || ' bytes transaction fee + ' || trigger.output[[asset=base]] || ' bytes bounced back)'; |
| 52 | var[$balance] = var[$balance] - trigger.data.withdraw - $return_fee; |
| 53 | }" |
| 54 | } |
| 55 | ] |
| 56 | } |
| 57 | ] |
| 58 | } |
| 59 | } |
| 60 | ] |