| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | |
| 6 | $aa_name = "JAAAWS"; |
| 7 | $owner = "O7NYCFUL5XIJTYE3O4MKGMGMTN6ATQAJ"; |
| 8 | $holaa = "5BRALFFKNML53X4MJVTWBSBYSDSNRIHQ"; |
| 9 | |
| 10 | $account = trigger.data.account otherwise trigger.data.ac otherwise ""; |
| 11 | |
| 12 | $party1 = trigger.data.address1 otherwise trigger.data.a1 otherwise ""; $p1_exist = ($party1 !=""); |
| 13 | $party2 = trigger.data.address2 otherwise trigger.data.a2 otherwise ""; $p2_exist = ($party2 !=""); |
| 14 | $party3 = trigger.data.address3 otherwise trigger.data.a3 otherwise ""; $p3_exist = ($party3 !=""); |
| 15 | |
| 16 | $trigger = trigger.address; |
| 17 | $pay_amount = trigger.data.amount otherwise trigger.data.am otherwise 0; |
| 18 | $pay_address = trigger.data.address otherwise trigger.data.ad otherwise ""; |
| 19 | $pay_id_received = trigger.data.pay_id otherwise trigger.data.pi otherwise ""; |
| 20 | |
| 21 | |
| 22 | $setup = ($p1_exist) AND ($p2_exist); |
| 23 | $init_pay = ($pay_amount>0) AND ($pay_address !=""); |
| 24 | $validate_pay = $pay_id_received != ""; |
| 25 | $cancel = ($pay_id_received != "") AND (trigger.data.cancel==true); |
| 26 | }", |
| 27 | "messages": { |
| 28 | "cases": [ |
| 29 | { |
| 30 | "if": "{trigger.data.create}", |
| 31 | "init": "{ |
| 32 | if ($account=="") bounce ("need account name"); |
| 33 | if (var[$account]) bounce ("Account "||$account||" already exist!"); |
| 34 | }", |
| 35 | "messages": [ |
| 36 | { |
| 37 | "app": "data", |
| 38 | "payload": { |
| 39 | "create": "{$account}" |
| 40 | } |
| 41 | }, |
| 42 | { |
| 43 | "app": "payment", |
| 44 | "payload": { |
| 45 | "asset": "base", |
| 46 | "outputs": [ |
| 47 | { |
| 48 | "address": "{$holaa}", |
| 49 | "amount": 1 |
| 50 | } |
| 51 | ] |
| 52 | } |
| 53 | }, |
| 54 | { |
| 55 | "app": "state", |
| 56 | "state": "{ |
| 57 | var[$account] = trigger.output[[asset=base]]; |
| 58 | if ($p1_exist )var[$account||"_1"] = $party1; |
| 59 | if ($p2_exist )var[$account||"_2"] = $party2; |
| 60 | if ($p3_exist )var[$account||"_3"] = $party3; |
| 61 | response['message'] = 'Multi-sig account set for '||$account||'. '; |
| 62 | }" |
| 63 | } |
| 64 | ] |
| 65 | }, |
| 66 | { |
| 67 | "if": "{trigger.data.add_party}", |
| 68 | "init": "{ |
| 69 | if ($account=="") bounce ("need account name"); |
| 70 | }", |
| 71 | "messages": [ |
| 72 | { |
| 73 | "app": "data", |
| 74 | "payload": { |
| 75 | "list_name": "{$account}", |
| 76 | "add": "{trigger.data.add_party}" |
| 77 | } |
| 78 | }, |
| 79 | { |
| 80 | "app": "payment", |
| 81 | "payload": { |
| 82 | "asset": "base", |
| 83 | "outputs": [ |
| 84 | { |
| 85 | "address": "{$holaa}", |
| 86 | "amount": 1 |
| 87 | } |
| 88 | ] |
| 89 | } |
| 90 | }, |
| 91 | { |
| 92 | "app": "state", |
| 93 | "state": "{ |
| 94 | response['message'] = trigger.data.add_party||" added ^^"; |
| 95 | }" |
| 96 | } |
| 97 | ] |
| 98 | }, |
| 99 | { |
| 100 | "if": "{$init_pay}", |
| 101 | "init": "{ |
| 102 | if ($account=="") bounce ("need account name"); |
| 103 | if (!var[$account]) bounce ("Account "||$account||" do not exist!"); |
| 104 | $pay_id_created = sha256($account||'>'||$pay_address||': '||$pay_amount); |
| 105 | |
| 106 | |
| 107 | if (trigger.address == $party1) |
| 108 | { |
| 109 | $need_party1_validation = false; |
| 110 | $initiator = 1; |
| 111 | } |
| 112 | else |
| 113 | { |
| 114 | if (trigger.address == $party2) |
| 115 | { |
| 116 | $need_party2_validation = false; |
| 117 | $initiator = 2; |
| 118 | } |
| 119 | else |
| 120 | { |
| 121 | if (trigger.address == $party3) |
| 122 | { |
| 123 | $need_party3_validation = false; |
| 124 | $initiator = 3; |
| 125 | } |
| 126 | else |
| 127 | bounce ("You are not a party of "||$account); |
| 128 | } |
| 129 | |
| 130 | } |
| 131 | if ($initiator==1) $next_validator_num = 2; else $next_validator_num = 1; |
| 132 | |
| 133 | }", |
| 134 | "messages": [ |
| 135 | { |
| 136 | "app": "data", |
| 137 | "payload": { |
| 138 | "message": "{"JAAAWS: Your approval is required for a payment from the account '"||$account||" to pay "||$pay_amount||" to "||$pay_address||", please send me back the pay_id linked to validate the transaction. And add a cancel = true field to refuse it."}", |
| 139 | "pay_id": "{$pay_id_created}" |
| 140 | } |
| 141 | }, |
| 142 | { |
| 143 | "app": "payment", |
| 144 | "payload": { |
| 145 | "asset": "base", |
| 146 | "outputs": [ |
| 147 | { |
| 148 | "address": "{var[$account||"_"||$next_validator_num]}", |
| 149 | "amount": 1000 |
| 150 | } |
| 151 | ] |
| 152 | } |
| 153 | }, |
| 154 | { |
| 155 | "app": "state", |
| 156 | "state": "{ |
| 157 | var[$pay_id_created||"_account"] = $account; |
| 158 | var[$pay_id_created||"_amount"] = $pay_amount; |
| 159 | var[$pay_id_created||"_address"] = $pay_address; |
| 160 | var[$pay_id_created||"_initiator"] = trigger.address; |
| 161 | |
| 162 | if ( $need_party1_validation) var[$pay_id_created||"_required_v1"] = true; |
| 163 | if ( $need_party2_validation) var[$pay_id_created||"_required_v2"] = true; |
| 164 | if ( $need_party3_validation) var[$pay_id_created||"_required_v3"] = true; |
| 165 | |
| 166 | response['message'] = "Payment "||$pay_id_created||" created and approvals requested"; |
| 167 | }" |
| 168 | } |
| 169 | ] |
| 170 | }, |
| 171 | { |
| 172 | "if": "{$validate_pay}", |
| 173 | "init": "{ |
| 174 | $account_received = var[$pay_id_received||"_account"] otherwise ""; |
| 175 | $pay_amount_to_valid = var[$pay_id_received||"_amount"] otherwise 0; |
| 176 | $pay_address_to_valid = var[$pay_id_received||"_address"] otherwise ""; |
| 177 | |
| 178 | if ($account_received == "") bounce ("Payment ID "||$pay_id_received||" do not exist!"); |
| 179 | |
| 180 | |
| 181 | if ($trigger == var[$account_received||"_1"]) $validator_num = 1; |
| 182 | if ($trigger == var[$account_received||"_2"]) $validator_num = 2; |
| 183 | if ($trigger == var[$account_received||"_3"]) $validator_num = 3; |
| 184 | |
| 185 | $is_this_validation_needed = var[$pay_id_created||"_required_v"||$validator_num] otherwise false; |
| 186 | if ($is_this_validation_needed ==false) |
| 187 | bounce ("Your validation by validator "||$validator_num||"is not required!"); |
| 188 | |
| 189 | $is_next_needed = var[$pay_id_created||"_required_v"||($validator_num+1)] otherwise false; |
| 190 | if ($is_next_needed == true) |
| 191 | { |
| 192 | $next_address = var[$account_received||"_"||($validator_num+1)]; |
| 193 | $next_amount = 1000; |
| 194 | $next_message = "JAAAWS: Your approval is required for a payment from the account '"||$account_received||" to pay "||$pay_amount_to_valid||" to "||$pay_address_to_valid||", please send me back the pay_id linked to validate the transaction. And add a cancel = true field to refuse it."; |
| 195 | } |
| 196 | else |
| 197 | { |
| 198 | $next_address = $pay_address_to_valid; |
| 199 | $next_amount = $pay_amount_to_valid; |
| 200 | $next_message = "Payment of "||$next_amount||" done to "||$next_address||" from account "||$account_received; |
| 201 | } |
| 202 | |
| 203 | |
| 204 | }", |
| 205 | "messages": [ |
| 206 | { |
| 207 | "app": "data", |
| 208 | "payload": { |
| 209 | "message": "{$next_message}", |
| 210 | "pay_id": "{$pay_id_received}" |
| 211 | } |
| 212 | }, |
| 213 | { |
| 214 | "app": "payment", |
| 215 | "payload": { |
| 216 | "asset": "base", |
| 217 | "outputs": [ |
| 218 | { |
| 219 | "address": "{$next_address}", |
| 220 | "amount": "{$next_amount}" |
| 221 | } |
| 222 | ] |
| 223 | } |
| 224 | }, |
| 225 | { |
| 226 | "app": "state", |
| 227 | "state": "{ |
| 228 | var[$pay_id_created||"_required_v"||$validator_num] = false; |
| 229 | if ($is_next_needed != true) |
| 230 | { |
| 231 | var[$account_received] = false; |
| 232 | var[$pay_address_to_valid] = false; |
| 233 | var[$pay_amount_to_valid] = false; |
| 234 | } |
| 235 | }" |
| 236 | } |
| 237 | ] |
| 238 | }, |
| 239 | { |
| 240 | "if": "{$cancel}", |
| 241 | "init": "{ |
| 242 | $account_received = var[$pay_id_received||"_account"] otherwise ""; |
| 243 | $amount = var[$pay_id_received||"_amount"] otherwise 0; |
| 244 | $address = var[$pay_id_received||"_address"] otherwise ""; |
| 245 | |
| 246 | if (trigger.address == var[$account_received||"_1"]) $cancel_valid = true; |
| 247 | if (trigger.address == var[$account_received||"_2"]) $cancel_valid = true; |
| 248 | if (trigger.address == var[$account_received||"_2"]) $cancel_valid = true; |
| 249 | |
| 250 | if (trigger.address == $address) $cancel_valid = true; |
| 251 | if ($cancel_valid==false) bounce ("You must be a party to cancel!"); |
| 252 | }", |
| 253 | "messages": [ |
| 254 | { |
| 255 | "app": "state", |
| 256 | "state": "{ |
| 257 | var[$account_received] = false; |
| 258 | var[$address] = false; |
| 259 | var[$amount] = false; |
| 260 | var[$pay_id_created||"_required_v1"] = false; |
| 261 | var[$pay_id_created||"_required_v2"] = false; |
| 262 | var[$pay_id_created||"_required_v3"] = false; |
| 263 | response['message'] = "Payment of "||$amount||" to "||$address||" is cancelled by "||trigger.address; |
| 264 | }" |
| 265 | } |
| 266 | ] |
| 267 | }, |
| 268 | { |
| 269 | "messages": [ |
| 270 | { |
| 271 | "init": "{ |
| 272 | if ($account=="") bounce ("need account name"); |
| 273 | $input = trigger.output[[asset=base]]; |
| 274 | }", |
| 275 | "app": "state", |
| 276 | "state": "{ |
| 277 | var[$account] += $input; |
| 278 | response['message'] = $input||" added to the account "||$account; |
| 279 | }" |
| 280 | } |
| 281 | ] |
| 282 | } |
| 283 | ] |
| 284 | } |
| 285 | } |
| 286 | ] |