| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | |
| 6 | $owner = "O7NYCFUL5XIJTYE3O4MKGMGMTN6ATQAJ"; |
| 7 | |
| 8 | $account = trigger.data.account otherwise trigger.data.ac otherwise ""; |
| 9 | |
| 10 | $trigger = trigger.address; |
| 11 | $pay_amount = trigger.data.amount otherwise trigger.data.am otherwise 0; |
| 12 | $pay_address = trigger.data.address otherwise trigger.data.ad otherwise ""; |
| 13 | $pay_id_received = trigger.data.pay_id otherwise trigger.data.pi otherwise ""; |
| 14 | |
| 15 | |
| 16 | $setup = (trigger.data.a1) AND (trigger.data.a2); |
| 17 | $init_pay = ($pay_amount>0) AND ($pay_address !=""); |
| 18 | $validate_pay = $pay_id_received != ""; |
| 19 | }", |
| 20 | "messages": { |
| 21 | "cases": [ |
| 22 | { |
| 23 | "if": "{$setup}", |
| 24 | "init": "{ |
| 25 | if ($account=="") bounce ("need account name"); |
| 26 | if (var[$account]) bounce ("Account "||$account||" already exist!"); |
| 27 | }", |
| 28 | "messages": [ |
| 29 | { |
| 30 | "app": "state", |
| 31 | "state": "{ |
| 32 | var[$account] = trigger.output[[asset=base]]; |
| 33 | var[$account||"_1"] = trigger.data.a1; |
| 34 | var[$account||"_2"] = trigger.data.a2; |
| 35 | response['message'] = 'Multi-sig account set for '||$account||'. '; |
| 36 | }" |
| 37 | } |
| 38 | ] |
| 39 | }, |
| 40 | { |
| 41 | "if": "{$init_pay}", |
| 42 | "init": "{ |
| 43 | if ($account=="") bounce ("need account name"); |
| 44 | if (!var[$account]) bounce ("Account "||$account||" do not exist!"); |
| 45 | $pay_id_created = sha256($account||'>'||$pay_address||': '||$pay_amount); |
| 46 | $validator_num = ($trigger == var[$account||"_1"]) ? "2": "1"; |
| 47 | $validator = $account||"_"||$validator_num; |
| 48 | }", |
| 49 | "messages": [ |
| 50 | { |
| 51 | "app": "data", |
| 52 | "payload": { |
| 53 | "message": "{"Your approval is required for a payment from "||$account||" to pay "||$pay_amount||" to pay "||$pay_address||", please send me (AA) back the pay_id linked to validate the transaction. "}", |
| 54 | "pay_id": "{$pay_id_created}" |
| 55 | } |
| 56 | }, |
| 57 | { |
| 58 | "app": "payment", |
| 59 | "payload": { |
| 60 | "asset": "base", |
| 61 | "outputs": [ |
| 62 | { |
| 63 | "address": "{var[$validator]}", |
| 64 | "amount": 1000 |
| 65 | } |
| 66 | ] |
| 67 | } |
| 68 | }, |
| 69 | { |
| 70 | "app": "state", |
| 71 | "state": "{ |
| 72 | var[$pay_id_created||"_amount"] = $pay_amount; |
| 73 | var[$pay_id_created||"_address"] = $pay_address; |
| 74 | var[$pay_id_created||"_v"||$validator_num||"_required"] = true; |
| 75 | response['message'] = "Payment "||$pay_id_created||" created and approvals requested"; |
| 76 | }" |
| 77 | } |
| 78 | ] |
| 79 | }, |
| 80 | { |
| 81 | "if": "{$validate_pay}", |
| 82 | "init": "{ |
| 83 | if (var[$account]) bounce ("Account "||$account||" do not exist!"); |
| 84 | |
| 85 | $amount = var[$pay_id_received||"_amount"] otherwise 0; |
| 86 | if ($amount == 0) bounce ("Payment ID "||$pay_id_received||" do not exist!"); |
| 87 | |
| 88 | $address = var[$pay_id_received||"_address"] otherwise ""; |
| 89 | |
| 90 | $validator_num = ($trigger == var[$account||"_1"]) ? "1": "2"; |
| 91 | $require = $pay_id_received||"_v"||$validator_num||"_required"; |
| 92 | if (var[$require] != true) |
| 93 | bounce ("Your validation is not required!"); |
| 94 | |
| 95 | }", |
| 96 | "messages": [ |
| 97 | { |
| 98 | "app": "payment", |
| 99 | "payload": { |
| 100 | "asset": "base", |
| 101 | "outputs": [ |
| 102 | { |
| 103 | "address": "{$address}", |
| 104 | "amount": "{$amount}" |
| 105 | } |
| 106 | ] |
| 107 | } |
| 108 | }, |
| 109 | { |
| 110 | "app": "state", |
| 111 | "state": "{ |
| 112 | var[$address] = false; |
| 113 | var[$amount] = false; |
| 114 | var[$require] = false; |
| 115 | response['message'] = "Payment of "||$amount||" done to "||$address; |
| 116 | }" |
| 117 | } |
| 118 | ] |
| 119 | }, |
| 120 | { |
| 121 | "messages": [ |
| 122 | { |
| 123 | "app": "state", |
| 124 | "state": "{ |
| 125 | var[$account] += trigger.output[[asset=base]]; |
| 126 | }" |
| 127 | } |
| 128 | ] |
| 129 | } |
| 130 | ] |
| 131 | } |
| 132 | } |
| 133 | ] |