| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | $this = { |
| 9 | dust_collector : "B2UMBICLZSBVDHRC7BYM6BBU4AQEXL2F", |
| 10 | htlc_base_aa : "GXH5UX3ILVMM66HGDXD4RZCAX6YK4R4I" |
| 11 | }; |
| 12 | |
| 13 | |
| 14 | }", |
| 15 | "messages": { |
| 16 | "cases": [ |
| 17 | { |
| 18 | "if": "{ !!trigger.data.destination_address and !!trigger.data.hash_of_secret}", |
| 19 | "init": "{ |
| 20 | $deadline = timestamp+(json_parse(trigger.data.duration_in_hours otherwise 12)*60*60); |
| 21 | $aa_definition = ['autonomous agent', { |
| 22 | base_aa: $this.htlc_base_aa , |
| 23 | params: { |
| 24 | funder_address: trigger.initial_address, |
| 25 | destination_address: trigger.data.destination_address, |
| 26 | hash_of_secret: trigger.data.hash_of_secret, |
| 27 | amount: trigger.data.amount otherwise 0, |
| 28 | asset_id: trigger.data.asset_id otherwise "base", |
| 29 | deadline: $deadline, |
| 30 | } |
| 31 | } |
| 32 | ]; |
| 33 | }", |
| 34 | "messages": [ |
| 35 | { |
| 36 | "app": "definition", |
| 37 | "payload": { |
| 38 | "definition": "{$aa_definition}" |
| 39 | } |
| 40 | }, |
| 41 | { |
| 42 | "app": "payment", |
| 43 | "payload": { |
| 44 | "asset": "base", |
| 45 | "outputs": [ |
| 46 | { |
| 47 | "address": "{trigger.initial_address}", |
| 48 | "amount": "{balance[base]-2000}" |
| 49 | } |
| 50 | ] |
| 51 | } |
| 52 | }, |
| 53 | { |
| 54 | "app": "state", |
| 55 | "state": "{ |
| 56 | response['message'] = "HTLC has been created"; |
| 57 | response['HTLC address'] = chash160($aa_definition); |
| 58 | response['HTLC time out'] = timestamp_to_string($deadline); |
| 59 | response['HTLC destination'] = trigger.data.destination_address; |
| 60 | }" |
| 61 | } |
| 62 | ] |
| 63 | }, |
| 64 | { |
| 65 | "messages": [ |
| 66 | { |
| 67 | "app": "state", |
| 68 | "state": "{ |
| 69 | bounce("I need:'destination_address' and 'hash_of_secret' and optional 'amount', 'asset_id' and 'duration_in_hours'."); |
| 70 | }" |
| 71 | } |
| 72 | ] |
| 73 | } |
| 74 | ] |
| 75 | } |
| 76 | } |
| 77 | ] |