Unit ID
r0M1uHNoqawX02SwmId+N7XbjT76pRJYgmq3zhNtm5o=
Received
03.09.2019 20:59:20
Confirmation delay (full node)
3 minutes 4 seconds
Confirmation delay (light node)
9 minutes 49 seconds
Messages
Definition
Definition: [ "autonomous agent", { "init": "{ $i = trigger.data; // How is works $INSTRUCTIONS = "To unlock, both parties should agree on how to spread the guarantee, buy sending 'amount' = <number of bytes I release for the other party>. When the sum of the 2 amounts is equal to the guarantee then the payment is executed."; // Owner of the AA can withdraw the dust if calculable $AA_OWNER = "MYESSCFGDERS3YIEGNZDOG2BI5HKQHLU"; $AA_NAME = "ARGAA"; // A Renting Guarantee Autonomous Agent // Account name is used to store de related information $account_name = $i.account_name otherwise $i.create; $key = $name||"_"; // There is 2 parties, owner and renter, known from the AA state or from the input during creation of the account $owner = var[$key||"owner"] otherwise $i.owner otherwise bounce ("need 'owner' address!"); $renter = var[$key||"renter"] otherwise trigger.address; // the object of the account is the guarantee, known a existing account or equal to the funds sent during the creation $guarantee = var[$key||"guarantee"] otherwise trigger.output[[asset=base]]-1000; // For the gurantee to be release, both parties should send proposition of release for the other party: $owner_proposition = var[$key||"owner_proposition"] otherwise 0; $renter_proposition = var[$key||"renter_proposition"] otherwise 0; // 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": "{ !!$i.create }", "init": "{ if (var[$key||"guarantee"]) bounce ("Already a guarantee with this name"); }", "messages": [ { "app": "data", "payload": { "account_name": "{ $account_name }", "guarantee": "{ $guarantee }" } }, { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{ $owner }", "amount": "{ 1 }" } ] } }, { "app": "state", "state": "{ var[$key||"owner"] = $owner; var[$key||"guarantee"] = $guarantee; var[$key||"renter"] = $renter; var["total"] = $total + $guarantee; response['message'] = $guarantee||" bytes locked as guarantee."; }" } ] }, { "if": "{ !!$i.account_name and !!$i.proposition }", "init": "{ // Exceptions if ($i.proposition > $guarantee) bounce ("The released prroposition is bigger than the full guarantee!"); if (trigger.address != $renter and trigger.address != $owner) bounce ("You are not part of the agreement!"); // Lets find which party is giving a new proposition $new_owner_proposition = trigger.address == $owner ? $i.proposition : $owner_proposition; $new_renter_proposition = trigger.address == $renter ? $i.proposition : $renter_proposition; // Agreement is found if booth propoition have been received adn their sum is equal to the guarantee $agreement_found = ( $new_owner_proposition + $new_renter_proposition ) == $guarantee; // Distribute the guarantee? send a symbolic bytes to make a party aware of the new proposition? $amount_to_send_to_renter = $agreement_found ? $new_owner_proposition : trigger.address == $owner ? 1:0; $amount_to_send_to_owner = $agreement_found ? $new_renter_proposition : trigger.address == $renter ? 1:0; }", "messages": [ { "app": "data", "payload": { "account_name": "{ $account_name }", "guarantee": "{ $guarantee }", "agreement": "{ $agreement_found }", "renter_proposition": "{ $new_renter_proposition }", "owner_proposition": "{ $new_owner_proposition }" } }, { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{ $renter }", "amount": "{ $amount_to_send_to_renter }" }, { "address": "{ $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[$key||"renter"] = false; var[$key||"renter_proposition"] = false; var[$key||"owner"] = false; var[$key||"owner_proposition"] = false; var[$key||"guarantee"] = false; var["total"] = $total - $guarantee; response['message'] = "Agreement found and funds have been sent back to parties ^^"; } else { // safe the proposition var[$key||"renter_proposition"] = $new_renter_proposition; var[$key||"owner_proposition"] = $new_owner_proposition; response['message'] = "Proposition recorded ("||$i.proposition||" bytes), the other party should set 'amount' to "|| ($guarantee - $i.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 owner"; }" } ] } ] } } ]
Technical information
Fees:
4,851 bytes
(353 headers, 4498 payload)
Level:1043680
Witnessed level:1043673
Main chain index:1042453
Latest included mc index:1042452
Status:stable/confirmed/final