| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | |
| 6 | $owner = "O7NYCFUL5XIJTYE3O4MKGMGMTN6ATQAJ"; |
| 7 | |
| 8 | $input_pid = trigger.data.pay_id otherwise trigger.data.pi otherwise ""; |
| 9 | |
| 10 | if ($input_pid != "") |
| 11 | { |
| 12 | $account = var[$input_pid||"_account"]; |
| 13 | $amount_to_pay = var[$input_pid||"_amount"]; |
| 14 | $address_to_pay = var[$input_pid||"_address"]; |
| 15 | $pay_id = $input_pid; |
| 16 | $pay_initiator = var[$input_pid||"_initiator"]; |
| 17 | } |
| 18 | else |
| 19 | { |
| 20 | $account = trigger.data.account otherwise trigger.data.ac otherwise ""; |
| 21 | $amount_to_pay = trigger.data.amount_to_pay otherwise trigger.data.am otherwise 0; |
| 22 | $address_to_pay = trigger.data.address_to_pay otherwise trigger.data.ad otherwise ""; |
| 23 | $pay_id = sha256($account||'>'||$pay_address||':'||$pay_amount); |
| 24 | $pay_initiator = trigger.address; |
| 25 | } |
| 26 | |
| 27 | if ($account=="") bounce ("need account name"); |
| 28 | |
| 29 | $party1 = trigger.data.address_to_pay1 otherwise trigger.data.a1 otherwise var[$account||"_1"] otherwise ""; |
| 30 | $party2 = trigger.data.address_to_pay2 otherwise trigger.data.a2 otherwise var[$account||"_2"] otherwise ""; |
| 31 | $party3 = trigger.data.address_to_pay3 otherwise trigger.data.a3 otherwise var[$account||"_3"] otherwise ""; |
| 32 | |
| 33 | $trg = trigger.address; |
| 34 | $b_is_a_party = ($trg == $party1) or ($trg == $party2) or ($trg == $party3) or ($trg == $address_to_pay); |
| 35 | if (trigger.address == $party1) $i_party_num = 1; |
| 36 | if (trigger.address == $party2) $i_party_num = 2; |
| 37 | if (trigger.address == $party3) $i_party_num = 3; |
| 38 | |
| 39 | if ($input_pid != "") |
| 40 | { |
| 41 | $b_pay_needed_v_from_1 = var[$input_pid||"_need_1"]; |
| 42 | $b_pay_needed_v_from_2 = var[$input_pid||"_need_2"]; |
| 43 | $b_pay_needed_v_from_3 = var[$input_pid||"_need_3"]; |
| 44 | } |
| 45 | else |
| 46 | { |
| 47 | $b_pay_needed_v_from_1 = (trigger.address == $party1); |
| 48 | $b_pay_needed_v_from_2 = (trigger.address == $party2); |
| 49 | $b_pay_needed_v_from_3 = (trigger.address == $party3); |
| 50 | } |
| 51 | |
| 52 | $b_initizalization = trigger.data.address_to_pay or trigger.data.ad or trigger.data.amount_to_pay or trigger.data.am; |
| 53 | }", |
| 54 | "messages": { |
| 55 | "cases": [ |
| 56 | { |
| 57 | "if": "{(trigger.data.address_to_pay1 or trigger.data.a1) and (trigger.data.address_to_pay2 or trigger.data.a2)}", |
| 58 | "init": "{ |
| 59 | if (var[$account]) bounce ("Account "||$account||" already exist!"); |
| 60 | }", |
| 61 | "messages": [ |
| 62 | { |
| 63 | "app": "state", |
| 64 | "state": "{ |
| 65 | var[$account] = trigger.output[[asset=base]]; |
| 66 | if ($party1 != "")var[$account||"_1"] = $party1; |
| 67 | if ($party2 != "")var[$account||"_2"] = $party2; |
| 68 | if ($party3 != "")var[$account||"_3"] = $party3; |
| 69 | response['message'] = "Joint Account set for "||$account||", balance = "||var[$account]; |
| 70 | }" |
| 71 | } |
| 72 | ] |
| 73 | }, |
| 74 | { |
| 75 | "if": "{($input_pid!= "") or $b_initizalization}", |
| 76 | "init": "{ |
| 77 | |
| 78 | if (!var[$account]) bounce ("Account "||$account||" do not exist!"); |
| 79 | if (!$is_a_party) bounce ("You are not a party of "||$account); |
| 80 | if (!$b_is_a_party) bounce ("You must be a party to interract!"); |
| 81 | |
| 82 | if (trigger.data.cancel==true) |
| 83 | { |
| 84 | $state_pay_need_v_from_1 = false; |
| 85 | $state_pay_need_v_from_2 = false; |
| 86 | $state_pay_need_v_from_3 = false; |
| 87 | |
| 88 | $address = var[$pay_id||"_initiator"]; |
| 89 | $amount = 1000; |
| 90 | $state_account = false; |
| 91 | $state_amount = false; |
| 92 | $state_address = false; |
| 93 | $state_initiator = false; |
| 94 | $message = "Payment of "||$amount||" to "||$address||" is cancelled by "||$trg; |
| 95 | } |
| 96 | else |
| 97 | { |
| 98 | if ($input_pid != "") |
| 99 | { |
| 100 | $state_pay_need_v_from_1 = $b_pay_needed_v_from_1 and ($trg != $party1); |
| 101 | $state_pay_need_v_from_2 = $b_pay_needed_v_from_2 and ($trg != $party2); |
| 102 | $state_pay_need_v_from_3 = $b_pay_needed_v_from_3 and ($trg != $party3); |
| 103 | } |
| 104 | else |
| 105 | { |
| 106 | $state_pay_need_v_from_1 = !(($party1 == "") or ($trg != $party1)) ; |
| 107 | $state_pay_need_v_from_2 = !(($party2 == "") or ($trg != $party2)) ; |
| 108 | $state_pay_need_v_from_3 = !(($party3 == "") or ($trg != $party3)) ; |
| 109 | } |
| 110 | $b_all_valid = ($state_pay_need_v_from_1 or $state_pay_need_v_from_2 or $state_pay_need_v_from_2); |
| 111 | |
| 112 | if ($b_all_valid) |
| 113 | { |
| 114 | $address = var[$pay_id||"_address"]; |
| 115 | $amount = var[$pay_id||"_amount"]; |
| 116 | $state_account = false; |
| 117 | $state_amount = false; |
| 118 | $state_address = false; |
| 119 | $state_initiator = false; |
| 120 | $message = "Payment of "||$amount||" to "||$address||" has been proceed"; |
| 121 | } |
| 122 | else |
| 123 | { |
| 124 | if ($dummy) $address = $dummy; |
| 125 | else if ($state_pay_need_v_from_1) $address = $party1; |
| 126 | else if ($state_pay_need_v_from_2) $address = $party2; |
| 127 | else if ($state_pay_need_v_from_3) $address = $party3; |
| 128 | |
| 129 | $amount = 1000; |
| 130 | $state_account = $account; |
| 131 | $state_amount = $amount_to_pay; |
| 132 | $state_address = $address_to_pay; |
| 133 | $state_initiator = $pay_initiator; |
| 134 | $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."; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | }", |
| 139 | "messages": [ |
| 140 | { |
| 141 | "app": "data", |
| 142 | "payload": { |
| 143 | "message": "{$message}", |
| 144 | "pay_id": "{$pay_id}" |
| 145 | } |
| 146 | }, |
| 147 | { |
| 148 | "app": "payment", |
| 149 | "payload": { |
| 150 | "asset": "base", |
| 151 | "outputs": [ |
| 152 | { |
| 153 | "address": "{$address}", |
| 154 | "amount": "{$amount}" |
| 155 | } |
| 156 | ] |
| 157 | } |
| 158 | }, |
| 159 | { |
| 160 | "app": "state", |
| 161 | "state": "{ |
| 162 | var[$pay_id||"_need_1"] = $state_pay_need_v_from_1; |
| 163 | var[$pay_id||"_need_2"] = $state_pay_need_v_from_2; |
| 164 | var[$pay_id||"_need_3"] = $state_pay_need_v_from_3; |
| 165 | |
| 166 | var[$pay_id||"_account"] = $state_account; |
| 167 | var[$pay_id||"_amount"] = $state_amount; |
| 168 | var[$pay_id||"_address"] = $state_address; |
| 169 | var[$pay_id||"_initiator"] = $state_initiator; |
| 170 | response['message'] = $message; |
| 171 | }" |
| 172 | } |
| 173 | ] |
| 174 | }, |
| 175 | { |
| 176 | "messages": [ |
| 177 | { |
| 178 | "init": "{ |
| 179 | if ($account=="") bounce ("need account name"); |
| 180 | $input = trigger.output[[asset=base]]; |
| 181 | }", |
| 182 | "app": "state", |
| 183 | "state": "{ |
| 184 | var[$account] += $input; |
| 185 | response['message'] = $input||" added to the account "||$account; |
| 186 | }" |
| 187 | } |
| 188 | ] |
| 189 | } |
| 190 | ] |
| 191 | } |
| 192 | } |
| 193 | ] |