| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $OSTABLE_DEP_ADDR = '3E2A3O5BQB7NVMHBXTAWEP2EEQAIWP5Y'; |
| 6 | $STABLE_ASSET = var[$OSTABLE_DEP_ADDR]['asset']; |
| 7 | $OWNER_ADDR = 'QF3NOVWHY2ZBVZZ2QHCUW7IPYXKLGIGG'; |
| 8 | if(!$OWNER_ADDR) |
| 9 | bounce('no owner'); |
| 10 | $addDeposit = $id =>{ |
| 11 | $deposits = var['deposits'] otherwise []; |
| 12 | $deposits[] = $id; |
| 13 | var['deposits'] = $deposits; |
| 14 | }; |
| 15 | $removeDeposit = $ind =>{ |
| 16 | $deposits = var['deposits'] otherwise []; |
| 17 | delete($deposits, $ind); |
| 18 | var['deposits'] = $deposits; |
| 19 | }; |
| 20 | }", |
| 21 | "messages": { |
| 22 | "cases": [ |
| 23 | { |
| 24 | "if": "{(!trigger.data.action AND trigger.address == $OWNER_ADDR) OR var['index']}", |
| 25 | "init": "{ |
| 26 | $ind = var['index'] otherwise 0; |
| 27 | $deposits = var['deposits']; |
| 28 | $id = $deposits[$ind]; |
| 29 | }", |
| 30 | "messages": [ |
| 31 | { |
| 32 | "if": "{$id}", |
| 33 | "app": "payment", |
| 34 | "payload": { |
| 35 | "asset": "base", |
| 36 | "outputs": [ |
| 37 | { |
| 38 | "address": "{$OSTABLE_DEP_ADDR}", |
| 39 | "amount": 1 |
| 40 | } |
| 41 | ] |
| 42 | } |
| 43 | }, |
| 44 | { |
| 45 | "if": "{$id}", |
| 46 | "app": "data", |
| 47 | "payload": { |
| 48 | "id": "{$id}" |
| 49 | } |
| 50 | }, |
| 51 | { |
| 52 | "if": "{!$id}", |
| 53 | "app": "payment", |
| 54 | "payload": { |
| 55 | "asset": "{$STABLE_ASSET}", |
| 56 | "outputs": [ |
| 57 | { |
| 58 | "address": "{$OWNER_ADDR}" |
| 59 | } |
| 60 | ] |
| 61 | } |
| 62 | }, |
| 63 | { |
| 64 | "app": "state", |
| 65 | "state": "{ |
| 66 | if($id) |
| 67 | var['index'] = $ind + 1; |
| 68 | else |
| 69 | var['index'] = false; |
| 70 | }" |
| 71 | } |
| 72 | ] |
| 73 | }, |
| 74 | { |
| 75 | "if": "{trigger.address != $OWNER_ADDR}", |
| 76 | "messages": [ |
| 77 | { |
| 78 | "app": "state", |
| 79 | "state": "{ |
| 80 | response['message'] = 'received'; |
| 81 | }" |
| 82 | } |
| 83 | ] |
| 84 | }, |
| 85 | { |
| 86 | "if": "{trigger.data.action == 'transfer' AND trigger.data.asset AND trigger.data.amount}", |
| 87 | "messages": [ |
| 88 | { |
| 89 | "app": "payment", |
| 90 | "payload": { |
| 91 | "asset": "base", |
| 92 | "outputs": [ |
| 93 | { |
| 94 | "address": "GV5YXIIRH3DH5FTEECW7IS2EQTAYJJ6S", |
| 95 | "amount": 1 |
| 96 | } |
| 97 | ] |
| 98 | } |
| 99 | }, |
| 100 | { |
| 101 | "app": "data", |
| 102 | "payload": { |
| 103 | "transfer": 1, |
| 104 | "to": "{$OWNER_ADDR}", |
| 105 | "asset": "{trigger.data.asset}", |
| 106 | "amount": "{trigger.data.amount}" |
| 107 | } |
| 108 | } |
| 109 | ] |
| 110 | }, |
| 111 | { |
| 112 | "if": "{trigger.data.action == 'add' and trigger.data.id}", |
| 113 | "messages": [ |
| 114 | { |
| 115 | "app": "state", |
| 116 | "state": "{ |
| 117 | $addDeposit(trigger.data.id); |
| 118 | }" |
| 119 | } |
| 120 | ] |
| 121 | }, |
| 122 | { |
| 123 | "if": "{trigger.data.action == 'rm' and exists(trigger.data.index)}", |
| 124 | "messages": [ |
| 125 | { |
| 126 | "app": "state", |
| 127 | "state": "{ |
| 128 | $removeDeposit(trigger.data.index); |
| 129 | }" |
| 130 | } |
| 131 | ] |
| 132 | }, |
| 133 | { |
| 134 | "if": "{trigger.data.action == 'withdraw'}", |
| 135 | "messages": [ |
| 136 | { |
| 137 | "app": "payment", |
| 138 | "payload": { |
| 139 | "asset": "{trigger.data.asset otherwise 'base'}", |
| 140 | "outputs": [ |
| 141 | { |
| 142 | "address": "{trigger.address}" |
| 143 | } |
| 144 | ] |
| 145 | } |
| 146 | } |
| 147 | ] |
| 148 | } |
| 149 | ] |
| 150 | } |
| 151 | } |
| 152 | ] |