| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "doc_url": "https://oswap-frontend.herokuapp.com/oscript/factory.json", |
| 5 | "init": "{ |
| 6 | $exchange_template = 'QOCT4JF4C3L725QJE56QFQEYSUTUUE2T'; |
| 7 | }", |
| 8 | "messages": { |
| 9 | "cases": [ |
| 10 | { |
| 11 | "if": "{trigger.data.createExchange AND trigger.data.asset}", |
| 12 | "init": "{ |
| 13 | $asset = trigger.data.asset; |
| 14 | if ( |
| 15 | !asset[$asset].exists |
| 16 | OR asset[$asset].is_private |
| 17 | OR !asset[$asset].is_transferrable |
| 18 | OR asset[$asset].fixed_denominations |
| 19 | ) |
| 20 | bounce("INVALID_ASSET"); |
| 21 | if (var['asset_to_exchange.' || $asset]) |
| 22 | bounce("DUPLICATE_EXCHANGE"); |
| 23 | }", |
| 24 | "messages": [ |
| 25 | { |
| 26 | "app": "definition", |
| 27 | "payload": { |
| 28 | "definition": [ |
| 29 | "autonomous agent", |
| 30 | { |
| 31 | "base_aa": "{$exchange_template}", |
| 32 | "params": { |
| 33 | "asset": "{$asset}" |
| 34 | } |
| 35 | } |
| 36 | ] |
| 37 | } |
| 38 | }, |
| 39 | { |
| 40 | "app": "state", |
| 41 | "state": "{ |
| 42 | $exchange = unit[response_unit].messages[[.app='definition']].payload.address; |
| 43 | $asset_id = var['asset_count'] + 1; |
| 44 | var['asset_to_exchange.' || $asset] = $exchange; |
| 45 | var['exchange_to_asset.' || $exchange] = $asset; |
| 46 | var['asset_count'] = $asset_id; |
| 47 | var['id_to_asset.' || $asset_id] = $asset; |
| 48 | response['asset'] = $asset; |
| 49 | response['exchange'] = $exchange; |
| 50 | }" |
| 51 | } |
| 52 | ] |
| 53 | } |
| 54 | ] |
| 55 | } |
| 56 | } |
| 57 | ] |