| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | |
| 6 | $INSTRUCTIONS = "Create a locked guarantee with 'create' = <unique account name> and 'owner' = <address of the owner for who you should lock a guarantee for>. Once locked, it will require consensus between the 2 parties on how to distribute it to unlock it. Both parties should use 'proposition' = <part of the guarantee you are agree to release for the other party>. When the sum of the 2 propositions is equal to the guarantee amount, the guarantee is unlock and distribute accordingly to the 2 parties."; |
| 7 | |
| 8 | |
| 9 | $AA_OWNER = "MYESSCFGDERS3YIEGNZDOG2BI5HKQHLU"; |
| 10 | $AA_NAME = "ARGAA"; |
| 11 | |
| 12 | |
| 13 | |
| 14 | $total = var["total"] otherwise 0; |
| 15 | }", |
| 16 | "messages": { |
| 17 | "cases": [ |
| 18 | { |
| 19 | "if": "{ !!trigger.data.create}", |
| 20 | "init": "{ |
| 21 | |
| 22 | if (!trigger.data.account_name) |
| 23 | bounce ("Add 'account_name' !"); |
| 24 | |
| 25 | if (var[trigger.data.account_name||"guarantee"]) |
| 26 | bounce ("Already a guarantee with this name !"); |
| 27 | |
| 28 | if (!trigger.data.owner) |
| 29 | bounce ("Add 'owner'= <owner address> !"); |
| 30 | |
| 31 | if (trigger.output[[asset=base]] <= 10000) |
| 32 | bounce ("You must add the guarentee value to the 10 000 bytes fee !" ); |
| 33 | |
| 34 | $guarantee = trigger.output[[asset=base]]-1000; |
| 35 | }", |
| 36 | "messages": [ |
| 37 | { |
| 38 | "app": "data", |
| 39 | "payload": { |
| 40 | "account_name": "{ trigger.data.account_name }", |
| 41 | "guarantee": "{ $guarantee }", |
| 42 | "aa": "{ this_address }" |
| 43 | } |
| 44 | }, |
| 45 | { |
| 46 | "app": "payment", |
| 47 | "payload": { |
| 48 | "asset": "base", |
| 49 | "outputs": [ |
| 50 | { |
| 51 | "address": "{ trigger.data.owner }", |
| 52 | "amount": "{ 1 }" |
| 53 | } |
| 54 | ] |
| 55 | } |
| 56 | }, |
| 57 | { |
| 58 | "app": "state", |
| 59 | "state": "{ |
| 60 | var[trigger.data.account_name||"_owner"] = trigger.data.owner; |
| 61 | var[trigger.data.account_name||"_guarantee"] = $guarantee; |
| 62 | var[trigger.data.account_name||"_renter"] = trigger.address; |
| 63 | var["total"] += $guarantee; |
| 64 | |
| 65 | response['message'] = $guarantee||" bytes locked as guarantee for "||trigger.data.account_name; |
| 66 | }" |
| 67 | } |
| 68 | ] |
| 69 | }, |
| 70 | { |
| 71 | "if": "{ !!trigger.data.proposition}", |
| 72 | "init": "{ |
| 73 | |
| 74 | if (!var[trigger.data.account_name||"guarantee"]) |
| 75 | bounce ("Account/Guarentee do not exist with this name !"); |
| 76 | |
| 77 | if (trigger.address != var[trigger.data.account_name||"_owner"] and |
| 78 | trigger.address != var[trigger.data.account_name||"_renter"]) |
| 79 | bounce ("You are not part of the agreement!"); |
| 80 | |
| 81 | $guarantee = var[trigger.data.account_name||"guarantee"]; |
| 82 | |
| 83 | if (!is_integer(trigger.data.proposition)) |
| 84 | bounce ("The proposition should be between 0 and "||$guarantee); |
| 85 | |
| 86 | if (trigger.data.proposition > $guarantee) |
| 87 | bounce ("The proposition is larger than the full guarantee! "||$guarantee|| "bytes"); |
| 88 | |
| 89 | |
| 90 | $owner_proposition = trigger.address == var[trigger.data.account_name||"_owner"] ? |
| 91 | trigger.data.proposition : var[trigger.data.account_name||"_owner_proposition"]; |
| 92 | $renter_proposition = trigger.address == var[trigger.data.account_name||"_renter"] ? |
| 93 | trigger.data.proposition : var[trigger.data.account_name||"_renter_proposition"]; |
| 94 | |
| 95 | |
| 96 | $agreement_found = (( $owner_proposition + $renter_proposition ) == $guarantee); |
| 97 | |
| 98 | |
| 99 | $amount_to_send_to_renter = $agreement_found ? |
| 100 | $owner_proposition : (trigger.address == var[trigger.data.account_name||"_owner"]) ? 1:0; |
| 101 | $amount_to_send_to_owner = $agreement_found ? |
| 102 | $renter_proposition : (trigger.address == var[trigger.data.account_name||"_renter"]) ? 1:0; |
| 103 | }", |
| 104 | "messages": [ |
| 105 | { |
| 106 | "app": "data", |
| 107 | "payload": { |
| 108 | "account_name": "{ trigger.data.account_name }", |
| 109 | "guarantee": "{ $guarantee }", |
| 110 | "agreement": "{ $agreement_found }", |
| 111 | "renter_proposition": "{ $renter_proposition }", |
| 112 | "owner_proposition": "{ $owner_proposition }", |
| 113 | "aa": "{ this_address }" |
| 114 | } |
| 115 | }, |
| 116 | { |
| 117 | "app": "payment", |
| 118 | "payload": { |
| 119 | "asset": "base", |
| 120 | "outputs": [ |
| 121 | { |
| 122 | "address": "{ var[trigger.data.account_name||"_renter"] }", |
| 123 | "amount": "{ $amount_to_send_to_renter }" |
| 124 | }, |
| 125 | { |
| 126 | "address": "{ var[trigger.data.account_name||"_owner"] }", |
| 127 | "amount": "{ $amount_to_send_to_owner }" |
| 128 | }, |
| 129 | { |
| 130 | "address": "{ trigger.address }", |
| 131 | "amount": "{ trigger.output[[asset=base]]-2000 }" |
| 132 | } |
| 133 | ] |
| 134 | } |
| 135 | }, |
| 136 | { |
| 137 | "app": "state", |
| 138 | "state": "{ |
| 139 | if ($agreement_found) |
| 140 | { |
| 141 | var[trigger.data.account_name||"_renter"] = false; |
| 142 | var[trigger.data.account_name||"_owner"] = false; |
| 143 | var[trigger.data.account_name||"_renter_proposition"] = false; |
| 144 | var[trigger.data.account_name||"_owner_proposition"] = false; |
| 145 | var[trigger.data.account_name||"_guarantee"] = false; |
| 146 | var["total"] = $total - $guarantee; |
| 147 | response['message'] = "Agreement found and funds have been sent back to parties ^^"; |
| 148 | } |
| 149 | else |
| 150 | { |
| 151 | var[trigger.data.account_name||"_renter_proposition"] = $renter_proposition; |
| 152 | var[trigger.data.account_name||"_owner_proposition"] = $owner_proposition; |
| 153 | |
| 154 | response['message'] = "Proposition recorded ("||$trigger_proposition||" bytes), the other party should set 'amount' to "|| ($guarantee - $trigger_proposition)||" bytes to find agreement ^^"; |
| 155 | } |
| 156 | }" |
| 157 | } |
| 158 | ] |
| 159 | }, |
| 160 | { |
| 161 | "init": "{ if (trigger.address != $AA_OWNER) bounce ($INSTRUCTIONS); }", |
| 162 | "messages": [ |
| 163 | { |
| 164 | "app": "payment", |
| 165 | "payload": { |
| 166 | "asset": "base", |
| 167 | "outputs": [ |
| 168 | { |
| 169 | "address": "{ $AA_OWNER }", |
| 170 | "amount": "{ balance[base] - $total - 1000 }" |
| 171 | } |
| 172 | ] |
| 173 | } |
| 174 | }, |
| 175 | { |
| 176 | "app": "state", |
| 177 | "state": "{ response['message'] = "Dust sent to AA owner"; }" |
| 178 | } |
| 179 | ] |
| 180 | } |
| 181 | ] |
| 182 | } |
| 183 | } |
| 184 | ] |