| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | $vrf = 'IFCSZYF6SLPC7IYNEIDEHMI6SEVDJOFM'; |
| 9 | $pubkey = var['pubkey']; |
| 10 | }", |
| 11 | "messages": { |
| 12 | "cases": [ |
| 13 | { |
| 14 | "if": "{trigger.data.type == 'set_pubkey' AND trigger.data.pubkey}", |
| 15 | "messages": [ |
| 16 | { |
| 17 | "app": "state", |
| 18 | "state": "{ |
| 19 | if (exists($pubkey)) { |
| 20 | bounce('already init'); |
| 21 | } |
| 22 | var['pubkey'] = trigger.data.pubkey; |
| 23 | }" |
| 24 | } |
| 25 | ] |
| 26 | }, |
| 27 | { |
| 28 | "if": "{ |
| 29 | trigger.data.type == 'walk' |
| 30 | }", |
| 31 | "messages": [ |
| 32 | { |
| 33 | "app": "payment", |
| 34 | "payload": { |
| 35 | "asset": "base", |
| 36 | "outputs": [ |
| 37 | { |
| 38 | "address": "{$vrf}", |
| 39 | "amount": "{1000000}" |
| 40 | } |
| 41 | ] |
| 42 | } |
| 43 | }, |
| 44 | { |
| 45 | "app": "state", |
| 46 | "state": "{ |
| 47 | if (trigger.output[[asset=base]] < 1010000) { |
| 48 | bounce('Min amount: ' || 1010000 || 'bytes'); |
| 49 | } |
| 50 | var['rid_' || response_unit] = trigger.address; |
| 51 | }" |
| 52 | } |
| 53 | ] |
| 54 | }, |
| 55 | { |
| 56 | "if": "{trigger.data.id AND trigger.data.proof}", |
| 57 | "messages": [ |
| 58 | { |
| 59 | "app": "state", |
| 60 | "state": "{ |
| 61 | $id = trigger.data.id; |
| 62 | $proof = trigger.data.proof; |
| 63 | $address = var['rid_' || $id]; |
| 64 | |
| 65 | if (!exists($address)) { |
| 66 | bounce('Random request not found'); |
| 67 | } |
| 68 | |
| 69 | if (!vrf_verify($id, $proof, $pubkey)) { |
| 70 | bounce('Not valid vrf'); |
| 71 | } |
| 72 | |
| 73 | $steps = number_from_seed($proof, 0, 20); |
| 74 | var['user_' || $address] += $steps; |
| 75 | response['result'] = 'User ' || $address || ' walked ' || $steps || ' steps'; |
| 76 | }" |
| 77 | } |
| 78 | ] |
| 79 | } |
| 80 | ] |
| 81 | } |
| 82 | } |
| 83 | ] |