| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | |
| 6 | $OWNER = "MYESSCFGDERS3YIEGNZDOG2BI5HKQHLU"; |
| 7 | |
| 8 | |
| 9 | $UT_ACCOUNT_NAME = "toietmoi"; |
| 10 | $UT_OTHER_PARTY_ADDRESS = "35IT3ZYKEPQSCXG2F7A7KWNRAD3SZXN4"; |
| 11 | |
| 12 | }", |
| 13 | "messages": { |
| 14 | "cases": [ |
| 15 | { |
| 16 | "if": "{ trigger.data.create }", |
| 17 | "init": "{ |
| 18 | $name = trigger.data.create; |
| 19 | $other_party = trigger.data.other_party otherwise bounce ("need 'other_party' address!"); |
| 20 | }", |
| 21 | "messages": [ |
| 22 | { |
| 23 | "app": "state", |
| 24 | "state": "{ |
| 25 | var[$name||"_party1"] = trigger.address; |
| 26 | var[$name||"_party2"] = $other_party; |
| 27 | var[$name||"_balance"] = trigger.output[[asset=base]]; |
| 28 | |
| 29 | if (var["blocked_balance"]) |
| 30 | var["blocked_balance"] += trigger.output[[asset=base]]; |
| 31 | else |
| 32 | var["blocked_balance"] = trigger.output[[asset=base]]; |
| 33 | |
| 34 | response['message'] = "Done! Later, the parties will have to agree on how to spread the balance ("||trigger.output[[asset=base]]||") by sending the 'amount' they allow the other party to receive, if the sum of the 2 amounts is equal to the balance then the payment will be executed."; |
| 35 | }" |
| 36 | } |
| 37 | ] |
| 38 | }, |
| 39 | { |
| 40 | "if": "{ trigger.data.name }", |
| 41 | "init": "{ |
| 42 | $name = trigger.data.name; |
| 43 | $balance = var[$name||"_balance"] otherwise bounce ("Guarantee name do not exist!"); |
| 44 | $amount = trigger.data.amount otherwise bounce ("Need the 'amount' you allow the other party to receive!"); |
| 45 | if ($amount > $balance) bounce ("The amount is bigger than the full balance!"); |
| 46 | |
| 47 | if (var[$name||"_party1"] == trigger.address) |
| 48 | { |
| 49 | $proposition1 = $amount; |
| 50 | $proposition2 = var[$name||"_proposition2"] otherwise $balance; |
| 51 | } |
| 52 | if (var[$name||"_party2"] == trigger.address) |
| 53 | { |
| 54 | $proposition1 = var[$name||"_proposition1"] otherwise $balance; |
| 55 | $proposition2 = $amount; |
| 56 | } |
| 57 | |
| 58 | if (!($proposition1)) bounce ("You are not part of the agreement!"); |
| 59 | |
| 60 | $agreement_found = ( $proposition1 + $proposition2 ) == $balance; |
| 61 | }", |
| 62 | "messages": [ |
| 63 | { |
| 64 | "if": "{ $agreement_found }", |
| 65 | "app": "payment", |
| 66 | "payload": { |
| 67 | "asset": "base", |
| 68 | "outputs": [ |
| 69 | { |
| 70 | "address": "{var[$name||"_party1"]}", |
| 71 | "amount": "{ $proposition2 - 500 }" |
| 72 | }, |
| 73 | { |
| 74 | "address": "{var[$name||"_party2"]}", |
| 75 | "amount": "{ $proposition1 - 500 }" |
| 76 | }, |
| 77 | { |
| 78 | "address": "{trigger.address}", |
| 79 | "amount": "{ trigger.output[[asset=base]]-2000 }" |
| 80 | } |
| 81 | ] |
| 82 | } |
| 83 | }, |
| 84 | { |
| 85 | "app": "state", |
| 86 | "state": "{ |
| 87 | if ($agreement_found) |
| 88 | { |
| 89 | var[$name||"_party1"] = false; |
| 90 | var[$name||"_party2"] = false; |
| 91 | var[$name||"_balance"] = false; |
| 92 | var[$name||"_proposition1"] = false; |
| 93 | var[$name||"_proposition2"] = false; |
| 94 | |
| 95 | var["blocked_balance"] -= ($proposition1 + $proposition2 - 1000); |
| 96 | |
| 97 | response['message'] = "Agreement found and funds sent back to parties ^^"; |
| 98 | } |
| 99 | else |
| 100 | { |
| 101 | if (var[$name||"_party1"] == trigger.address) |
| 102 | var[$name||"_proposition1"] = $amount; |
| 103 | else |
| 104 | var[$name||"_proposition2"] = $amount; |
| 105 | |
| 106 | response['message'] = "Proposition recorded ("||$amount||" bytes), the other party should set 'amount' to "|| ($balance - $amount)||" bytes to find agreement ^^"; |
| 107 | } |
| 108 | }" |
| 109 | } |
| 110 | ] |
| 111 | }, |
| 112 | { |
| 113 | "init": "{ |
| 114 | if (trigger.address != $owner) |
| 115 | bounce ("you need to read the doc!"); |
| 116 | }", |
| 117 | "messages": [ |
| 118 | { |
| 119 | "app": "payment", |
| 120 | "payload": { |
| 121 | "asset": "base", |
| 122 | "outputs": [ |
| 123 | { |
| 124 | "address": "{$owner}", |
| 125 | "amount": "{ balance[base] - var["blocked_balance"] - 1000 }" |
| 126 | } |
| 127 | ] |
| 128 | } |
| 129 | }, |
| 130 | { |
| 131 | "app": "state", |
| 132 | "state": "{ |
| 133 | response['message'] = "Dust sent to owner"; |
| 134 | }" |
| 135 | } |
| 136 | ] |
| 137 | } |
| 138 | ] |
| 139 | } |
| 140 | } |
| 141 | ] |