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