| 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.1 }", |
| 17 | "messages": [ |
| 18 | { |
| 19 | "app": "data", |
| 20 | "payload": { |
| 21 | "create": "{ $UT_ACCOUNT_NAME }", |
| 22 | "other_party": "{ $UT_OTHER_PARTY_ADDRESS }" |
| 23 | } |
| 24 | }, |
| 25 | { |
| 26 | "app": "payment", |
| 27 | "payload": { |
| 28 | "asset": "base", |
| 29 | "outputs": [ |
| 30 | { |
| 31 | "address": "{this_address}", |
| 32 | "amount": "{trigger.output[[asset=base]] -1000}" |
| 33 | } |
| 34 | ] |
| 35 | } |
| 36 | } |
| 37 | ] |
| 38 | }, |
| 39 | { |
| 40 | "if": "{ trigger.data.2 }", |
| 41 | "messages": [ |
| 42 | { |
| 43 | "app": "data", |
| 44 | "payload": { |
| 45 | "name": "{$account_name }", |
| 46 | "amount": "{4000}" |
| 47 | } |
| 48 | }, |
| 49 | { |
| 50 | "app": "payment", |
| 51 | "payload": { |
| 52 | "asset": "base", |
| 53 | "outputs": [ |
| 54 | { |
| 55 | "address": "{this_address}", |
| 56 | "amount": "{1}" |
| 57 | } |
| 58 | ] |
| 59 | } |
| 60 | } |
| 61 | ] |
| 62 | }, |
| 63 | { |
| 64 | "if": "{ trigger.data.create }", |
| 65 | "init": "{ |
| 66 | $name = trigger.data.create; |
| 67 | $other_party = trigger.data.other_party otherwise bounce ("need 'other_party' address!"); |
| 68 | }", |
| 69 | "messages": [ |
| 70 | { |
| 71 | "app": "state", |
| 72 | "state": "{ |
| 73 | var[$name||"_party1"] = trigger.address; |
| 74 | var[$name||"_party2"] = $other_party; |
| 75 | var[$name||"_balance"] = trigger.output[[asset=base]]; |
| 76 | |
| 77 | if (var["blocked_balance"]) |
| 78 | var["blocked_balance"] += trigger.output[[asset=base]]; |
| 79 | else |
| 80 | var["blocked_balance"] = trigger.output[[asset=base]]; |
| 81 | |
| 82 | 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."; |
| 83 | }" |
| 84 | } |
| 85 | ] |
| 86 | }, |
| 87 | { |
| 88 | "if": "{ trigger.data.name }", |
| 89 | "init": "{ |
| 90 | $name = trigger.data.name; |
| 91 | $balance = var[$name||"_balance"] otherwise bounce ("Guarantee name do not exist!"); |
| 92 | $amount = trigger.data.amount otherwise bounce ("Need the 'amount' you allow the other party to receive!"); |
| 93 | if ($amount > $balance) bounce ("The amount is bigger than the full balance!"); |
| 94 | |
| 95 | if (var[$name||"_party1"] == trigger.address) |
| 96 | { |
| 97 | $proposition1 = $amount; |
| 98 | $proposition2 = var[$name||"_proposition2"] otherwise $balance; |
| 99 | } |
| 100 | if (var[$name||"_party2"] == trigger.address) |
| 101 | { |
| 102 | $proposition1 = var[$name||"_proposition1"] otherwise $balance; |
| 103 | $proposition2 = $amount; |
| 104 | } |
| 105 | |
| 106 | if (!($proposition1)) bounce ("You are not part of the agreement!"); |
| 107 | |
| 108 | $agreement_found = ( $proposition1 + $proposition2 ) == $balance; |
| 109 | }", |
| 110 | "messages": [ |
| 111 | { |
| 112 | "if": "{ $agreement_found }", |
| 113 | "app": "payment", |
| 114 | "payload": { |
| 115 | "asset": "base", |
| 116 | "outputs": [ |
| 117 | { |
| 118 | "address": "{var[$name||"_party1"]}", |
| 119 | "amount": "{ $proposition2 - 500 }" |
| 120 | }, |
| 121 | { |
| 122 | "address": "{var[$name||"_party2"]}", |
| 123 | "amount": "{ $proposition1 - 500 }" |
| 124 | }, |
| 125 | { |
| 126 | "address": "{trigger.address}", |
| 127 | "amount": "{ trigger.output[[asset=base]]-2000 }" |
| 128 | } |
| 129 | ] |
| 130 | } |
| 131 | }, |
| 132 | { |
| 133 | "app": "state", |
| 134 | "state": "{ |
| 135 | if ($agreement_found) |
| 136 | { |
| 137 | var[$name||"_party1"] = false; |
| 138 | var[$name||"_party2"] = false; |
| 139 | var[$name||"_balance"] = false; |
| 140 | var[$name||"_proposition1"] = false; |
| 141 | var[$name||"_proposition2"] = false; |
| 142 | |
| 143 | var["blocked_balance"] -= ($proposition1 + $proposition2 - 1000); |
| 144 | |
| 145 | response['message'] = "Agreement found and funds sent back to parties ^^"; |
| 146 | } |
| 147 | else |
| 148 | { |
| 149 | if (var[$name||"_party1"] == trigger.address) |
| 150 | var[$name||"_proposition1"] = $amount; |
| 151 | else |
| 152 | var[$name||"_proposition2"] = $amount; |
| 153 | |
| 154 | response['message'] = "Proposition recorded ("||$amount||" bytes), the other party should set 'amount' to "|| ($balance - $amount)||" bytes to find agreement ^^"; |
| 155 | } |
| 156 | }" |
| 157 | } |
| 158 | ] |
| 159 | }, |
| 160 | { |
| 161 | "init": "{ |
| 162 | if (trigger.address != $owner) |
| 163 | bounce ("you need to read the doc!"); |
| 164 | }", |
| 165 | "messages": [ |
| 166 | { |
| 167 | "app": "payment", |
| 168 | "payload": { |
| 169 | "asset": "base", |
| 170 | "outputs": [ |
| 171 | { |
| 172 | "address": "{$owner}", |
| 173 | "amount": "{ balance[base] - var["blocked_balance"] - 1000 }" |
| 174 | } |
| 175 | ] |
| 176 | } |
| 177 | }, |
| 178 | { |
| 179 | "app": "state", |
| 180 | "state": "{ |
| 181 | response['message'] = "Dust sent to owner"; |
| 182 | }" |
| 183 | } |
| 184 | ] |
| 185 | } |
| 186 | ] |
| 187 | } |
| 188 | } |
| 189 | ] |