| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $f = 1000; |
| 6 | if(!trigger.data.scope) bounce ('please specifcy a scope'); |
| 7 | |
| 8 | $balance = 'balance_' || trigger.data.scope; |
| 9 | $secret_hashed = 'secret_' || trigger.data.scope; |
| 10 | $input = trigger.output[[asset=base]]; |
| 11 | }", |
| 12 | "messages": { |
| 13 | "cases": [ |
| 14 | { |
| 15 | "if": "{trigger.data.set_proof}", |
| 16 | "init": "{ if (var[$secret_hashed]) bounce ("Safe already exists"); }", |
| 17 | "messages": [ |
| 18 | { |
| 19 | "app": "state", |
| 20 | "state": "{ |
| 21 | var[$secret_hashed] = trigger.data.set_proof; |
| 22 | response['sec'] = 'Secret set for account' || trigger.data.scope; |
| 23 | |
| 24 | var[$balance] = var[$balance] + $input; |
| 25 | response['message'] = 'accepted on account ' || trigger.data.scope || ': ' || $input || ' bytes'; |
| 26 | }" |
| 27 | } |
| 28 | ] |
| 29 | }, |
| 30 | { |
| 31 | "if": "{trigger.data.secret}", |
| 32 | "init": "{ |
| 33 | if (!var[$secret_hashed]) bounce ("scope doesn't exists"); |
| 34 | if (sha256(trigger.data.secret) != var[$secret_hashed]) bounce ("Wrong secret!"); |
| 35 | }", |
| 36 | "messages": [ |
| 37 | { |
| 38 | "init": "{ |
| 39 | $total = var[$balance] + $input - $f; |
| 40 | }", |
| 41 | "app": "payment", |
| 42 | "payload": { |
| 43 | "asset": "base", |
| 44 | "outputs": [ |
| 45 | { |
| 46 | "address": "{trigger.address}", |
| 47 | "amount": "{$total}" |
| 48 | } |
| 49 | ] |
| 50 | } |
| 51 | }, |
| 52 | { |
| 53 | "app": "state", |
| 54 | "state": "{ |
| 55 | var[$balance] = 0; |
| 56 | var[$secret_hashed] = false; |
| 57 | response['message'] = 'withdrawn from account ' || trigger.data.scope || '. '; |
| 58 | }" |
| 59 | } |
| 60 | ] |
| 61 | } |
| 62 | ] |
| 63 | } |
| 64 | } |
| 65 | ] |