Unit ID
pY0OKOFQuLl5jrbVeKFmaWD8tPft5zjwdoIpELYbMKw=
Received
25.09.2019 18:19:29
Confirmation delay (full node)
2 minutes 39 seconds
Confirmation delay (light node)
3 minutes 55 seconds
Messages
Definition
Definition: [ "autonomous agent", { "init": "{ // FOREVER CONSTANTE $AA_NAME = "JAAA"; $LIST_HOLDER_AA = "5OHSAYPGDL7IPPRCZCFR7ZNJDS45VXBB"; $INSTRUCTIONS = "Every operation need 'account_name= <account name>', if you received a token just use it, 'token = <received token> optionaly with 'cancel = true' to deny the payment, to initiate a payment, define 'pay_to' and 'amount'. To create a new account, add users with 'add_user = <address>' mutiple times then 'activate_account = true' and chose 'hierarchical/flat = true'."; }", "messages": { "cases": [ { "if": "{ !!trigger.data.pay_id }", "init": "{ $payment_id = trigger.data.pay_id; $account_name = var[$payment_id||"_account"]; // bouncings if (!var[$payment_id]) bounce ("Token "||$payment_id||" do not exist!"); if (!var[$LIST_HOLDER_AA][$account_name||"_users_"||trigger.address]) bounce ("This address is not listed as actor of this account"); if (!var[$payment_id||"_needs_"||trigger.address]) bounce ("Your validation is not needed!"); $number_of_validations_needed = var[$payment_id||"_validation_needed"]-1; $is_validated = ($number_of_validations_needed == 0); $forwarding_needed = !$is_validated and var[$account_name] == "hierarchical"; }", "messages": [ { "if": "{ $is_validated }", "app": "data", "payload": { "message": "{ var[$payment_id||"_communication"] }" } }, { "if": "{ $is_validated }", "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{ var[$payment_id||"_destination"] }", "amount": "{ var[$payment_id||"_amount"] }" } ] } }, { "if": "{ $forwarding_needed }", "app": "data", "payload": { "list_name": "{ $account_name||"_users" }", "token": "{ $payment_id }", "get_previous": "{ $party }" } }, { "if": "{ $forwarding_needed }", "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{ $LIST_HOLDER_AA }", "amount": "{ 1000 }" } ] } }, { "app": "state", "state": "{ var[$payment_id||"_needs_"||trigger.address] = false; var[$payment_id||"_validation_needed"] = $validation_needed; if ($is_validated) // clean the payment state { var[$payment_id] = false; var[$payment_id||"_initiator"] = false; var[$payment_id||"_communication"] = false; var[$payment_id||"_destination"] = false; var[$payment_id||"_amount"] = false; var[$payment_id||"_account"] = false; } }" } ] }, { "if": "{ !!trigger.data.pay_to}", "init": "{ // bouncing $account_name = trigger.data.account_name otherwise bounce ($INSTRUCTIONS); if (!var[$account_name]) bounce ("Account "||$account_name||" do not exist!"); if (!var[$LIST_HOLDER_AA][$account_name||"_users_"||trigger.address]) bounce ("This address is not listed as actor of this account"); if (!is_valid_address(trigger.data.pay_to)) bounce ("Invalid address in 'pay_to'!"); if (!is_valid_amount(trigger.data.amount)) bounce ("amount must be positive !"); // initiate payment request $payment_id = sha256($account_name||'>'||$pay_address||': '||$pay_amount); }", "messages": [ { "app": "data", "payload": { "list_name": "{ $account_name||"_users" }", "get_previous": "{ true }", "token": "{ $payment_id }" } }, { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{ $LIST_HOLDER_AA }", "amount": 1000 } ] } }, { "app": "state", "state": "{ $nickname = var[$LIST_HOLDER_AA][$account_name||"_users_"||trigger.address]; var[$payment_id] = "Payment of "||trigger.data.amount||" bytes from "||$account_name||" to "||trigger.data.pay_to||" initiated by "||trigger.address||"("||$nickname||")"; var[$payment_id||"_initiator"] = trigger.address; var[$payment_id||"_destination"] = trigger.data.pay_to; var[$payment_id||"_amount"] = trigger.data.amount; var[$payment_id||"_account"] = $account_name; var[$payment_id||"_communication"] = trigger.data.communication otherwise "none"; var[$payment_id||"_validation_needed"] = var[$LIST_HOLDER_AA][$account_name||"_users_items_count"]-1; response['message'] = "Payment "||$payment_id||" created and approvals requested"; }" } ] }, { "if": "{ !!trigger.data.cancel}", "init": "{ $account_name = trigger.data.account_name otherwise bounce ($INSTRUCTIONS); if (!var[$LIST_HOLDER_AA][$account_name||"_users_"||trigger.address]) bounce ("This address is not listed as actor of this account"); $payment_id = trigger.data.token otherwise bounce ("'Token' needed !"); $message = "Payment cancelled by "||trigger.address||", "||var[$payment_id]; }", "messages": [ { "app": "data", "payload": { "message": "{ $message }" } }, { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{ var[$payment_id||"_initiator"] }", "amount": 6 } ] } }, { "app": "state", "state": "{ var[$payment_id] = false; var[$payment_id||"_initiator"] = false; var[$payment_id||"_validation_needed"] = false; var[$payment_id||"_communication"] = false; var[$payment_id||"_destination"] = false; var[$payment_id||"_amount"] = false; var[$payment_id||"_account"] = false; var[$payment_id||"_needs_"||trigger.address] = false; var[$payment_id||"_destination"] = false; var[$payment_id||"_amount"] = false; response['message'] = $message; }" } ] }, { "if": "{ !!trigger.data.add_user }", "init": "{ $account_name = var[trigger.address] otherwise trigger.data.account_name otherwise bounce ($INSTRUCTIONS); if (!!var[$account_name||"_owner"]) if (trigger.address != var[$account_name||"_owner"]) bounce ("Account "||$account_name||" already exist!"); if (!is_valid_address(trigger.data.add_user)) bounce ("Invalid address in 'add_user'!"); }", "messages": [ { "app": "data", "payload": { "list_name": "{ $account_name||"_users" }", "add": "{ trigger.data.add_user }", "value": "{ trigger.data.nick_name }" } }, { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{ $LIST_HOLDER_AA }", "amount": 250 } ] } }, { "app": "state", "state": "{ // temporary store creator to avoid to enter account name for each new user added var[trigger.address] = $account_name; // temporary store owner to avoid abuse during creation of the account var[$account_name||"_owner"] = trigger.address; var[$account_name||"_balance"] += trigger.output[[asset=base]].amount - 1000; response['message'] = 'One user added ^^'; }" } ] }, { "if": "{ !!trigger.data.activate_account }", "init": "{ $account_name = trigger.data.account_name otherwise bounce ($INSTRUCTIONS); if (!!var[$account_name||"_owner"]) if (trigger.address != var[$account_name||"_owner"]) bounce ($account_name||" already active!"); if (!trigger.data.hierachical and !trigger.data.flat) bounce ("you must specify 'hierarchical = true' or 'flat = true'"); }", "messages": [ { "app": "state", "state": "{ var[$account_name] = !!trigger.data.hierachical ? "hierarchical": "flat"; var[$account_name||"_owner"] = false; var[$account_name||"_balance"] += trigger.output[[asset=base]].amount; response['message'] = $account_name||" activated ^^"; }" } ] }, { "if": "{ trigger.address == $LIST_HOLDER_AA }", "init": "{ // initiate payment request $payment_id = trigger.data.token; // get it back from HOLLAA $account_name = var[$payment_id||"_account"]; $party = trigger.data.item_name; // validation from party needed? $actual_user_validation_needed = $party != var[$payment_id||"_initiator"]; $amount_for_next_party = $actual_user_validation_needed? 1000 : 0; // $another_party_is_needed = $party != var[$LIST_HOLDER_AA][$account_name||"_users_first_item"]; $forwarding_needed = $another_party_is_needed and (var[$account_name] == "flat" or !$actual_user_validation_needed); // trick to be able to put condition on the payment and avoid 'already have base payment' $amount_for_AA = $forwarding_needed? 1000 : 0; }", "messages": [ { "if": "{ $actual_user_validation_needed }", "app": "data", "payload": { "message": "{"JAAA: Your approval is required: "||var[$payment_id]||", please send me back the pay_id linked to validate the transaction. And add a 'cancel = true' field to refuse it."}", "me": "{ this_address }", "pay_id": "{ $payment_id }" } }, { "if": "{ $forwarding_needed }", "app": "data", "payload": { "list_name": "{ $account_name||"_users" }", "get_previous": "{ $party }", "token": "{ $payment_id }" } }, { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{ $LIST_HOLDER_AA }", "amount": "{ $amount_for_AA }" }, { "address": "{ $party }", "amount": "{ $amount_for_next_party }" } ] } }, { "app": "state", "state": "{ var[$payment_id||"_needs_"||$party] = $actual_user_validation_needed; if ( $actual_user_validation_needed ) response["message"] = $party||"has been requested for validation"; if ( $forwarding_needed ) response["message"] = "Forwarding info to other parties"; }" } ] }, { "messages": [ { "app": "state", "state": "{ bounce ($INSTRUCTIONS); }" } ] } ] } } ]
Technical information
Fees:
10,452 bytes
(353 headers, 10099 payload)
Level:1078159
Witnessed level:1078151
Main chain index:1076921
Latest included mc index:1076920
Status:stable/confirmed/final