Unit ID
rGzDmw6IyC4aFOReUzaCV0IMFbOYGhSXIevUKOqhDpw=
Received
21.10.2019 19:09:17
Confirmation delay (full node)
3 minutes 20 seconds
Confirmation delay (light node)
5 minutes 32 seconds
Messages
Definition
Definition: [ "autonomous agent", { "init": "{ // How is works, instruction to be bounce if not used case selected $INSTRUCTIONS = "Create a locked guarantee with 'create = true', 'account_name = <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 'account_name = <unique account name>' and'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."; // Owner of the AA can withdraw the dust $AA_OWNER = "MYESSCFGDERS3YIEGNZDOG2BI5HKQHLU"; $AA_NAME = "ARGAA"; // A Renting Guarantee Autonomous Agent // the AA is keeping in mind the total amount of guarantee to have a way to now the dust available in its balance: $total = var["total"] otherwise 0; }", "messages": { "cases": [ { "if": "{ !!trigger.data.create}", "init": "{ // account name defined? if (!trigger.data.account_name) bounce ("Add 'account_name' !"); // account exist already? if (var[trigger.data.account_name||"_guarantee"]) bounce ("Already a guarantee with this name !"); // owner defined? if (!trigger.data.owner) bounce ("Add 'owner'= <owner address> !"); // the object of the account is the guarantee if (trigger.output[[asset=base]] <= 10000) bounce ("You must add the guarantee value to the 10 000 bytes fee !" ); // isolate guarantee $guarantee = trigger.output[[asset=base]]-1000; }", "messages": [ { "app": "data", "payload": { "account_name": "{ trigger.data.account_name }", "guarantee": "{ $guarantee }", "aa": "{ this_address }" } }, { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{ trigger.data.owner }", "amount": "{ 1 }" }, { "address": "{ trigger.data.owner }", "amount": "{ 1 }" } ] } }, { "app": "state", "state": "{ var[trigger.data.account_name||"_owner"] = trigger.data.owner; var[trigger.data.account_name||"_guarantee"] = $guarantee; var[trigger.data.account_name||"_renter"] = trigger.address; var["total"] += $guarantee; response['message'] = $guarantee||" bytes locked as guarantee for "||trigger.data.account_name; }" } ] }, { "if": "{ !!trigger.data.proposition}", "init": "{ // account exist already? if (!var[trigger.data.account_name||"_guarantee"]) bounce ("Account/guarantee do not exist with this name !"); // check if user is part of the contract if (trigger.address != var[trigger.data.account_name||"_owner"] and trigger.address != var[trigger.data.account_name||"_renter"]) bounce ("You are not part of the agreement!"); // get guarantee amount from var state $guarantee = var[trigger.data.account_name||"_guarantee"]; // check if propostiion is a value if (!is_integer(trigger.data.proposition)) bounce ("The proposition should be between 0 and "||$guarantee); // realist propostion of release? if (trigger.data.proposition > $guarantee) bounce ("The proposition is larger than the full guarantee! "||$guarantee|| "bytes"); // Lets find which party is giving a new proposition $owner_proposition = trigger.address == var[trigger.data.account_name||"_owner"] ? trigger.data.proposition : var[trigger.data.account_name||"_owner_proposition"]; $renter_proposition = trigger.address == var[trigger.data.account_name||"_renter"] ? trigger.data.proposition : var[trigger.data.account_name||"_renter_proposition"]; // Agreement is found if both propositions have been received and their sum is equal to the guarantee $agreement_found = (( $owner_proposition + $renter_proposition ) == $guarantee); // Distribute the guarantee? send a symbolic byte to make a party aware of the new proposition? $amount_to_send_to_renter = $agreement_found ? $owner_proposition : (trigger.address == var[trigger.data.account_name||"_owner"]) ? 1:0; $amount_to_send_to_owner = $agreement_found ? $renter_proposition : (trigger.address == var[trigger.data.account_name||"_renter"]) ? 1:0; }", "messages": [ { "app": "data", "payload": { "account_name": "{ trigger.data.account_name }", "guarantee": "{ $guarantee }", "agreement": "{ $agreement_found }", "renter_proposition": "{ $renter_proposition }", "owner_proposition": "{ $owner_proposition }", "aa": "{ this_address }" } }, { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{ var[trigger.data.account_name||"_renter"] }", "amount": "{ $amount_to_send_to_renter }" }, { "address": "{ var[trigger.data.account_name||"_owner"] }", "amount": "{ $amount_to_send_to_owner }" }, { "address": "{ trigger.address }", "amount": "{ trigger.output[[asset=base]]-2000 }" } ] } }, { "app": "state", "state": "{ if ($agreement_found) { // clear the full state var[trigger.data.account_name||"_renter"] = false; var[trigger.data.account_name||"_owner"] = false; var[trigger.data.account_name||"_renter_proposition"] = false; var[trigger.data.account_name||"_owner_proposition"] = false; var[trigger.data.account_name||"_guarantee"] = false; var["total"] = $total - $guarantee; response['message'] = "Agreement found and funds have been sent back to parties ^^"; } else { // safe the proposition var[trigger.data.account_name||"_renter_proposition"] = $renter_proposition; var[trigger.data.account_name||"_owner_proposition"] = $owner_proposition; response['message'] = "Proposition recorded ("||$trigger_proposition||" bytes), the other party should set 'amount' to "|| ($guarantee - $trigger_proposition)||" bytes to find agreement ^^"; } }" } ] }, { "init": "{ if (trigger.address != $AA_OWNER) bounce ($INSTRUCTIONS); }", "messages": [ { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{ $AA_OWNER }", "amount": "{ balance[base] - $total - 1000 }" } ] } }, { "app": "state", "state": "{ response['message'] = "Dust sent to AA owner"; }" } ] } ] } } ]
Technical information
Fees:
7,098 bytes
(353 headers, 6745 payload)
Level:1113642
Witnessed level:1113635
Main chain index:1112401
Latest included mc index:1112400
Status:stable/confirmed/final