Unit ID
RDdpwsME/ku0PdyVUO/7S8J71gH+UZ246XvXGgBV0m8=
Received
24.08.2019 15:02:18
Confirmation delay (full node)
2 minutes 9 seconds
Confirmation delay (light node)
5 minutes 40 seconds
Messages
Definition
Definition: [ "autonomous agent", { "init": "{ // JAAAWS, Joint Account Agent $aa_name = "JAAAWS"; $owner = "O7NYCFUL5XIJTYE3O4MKGMGMTN6ATQAJ"; //office_testnet_wallet $holaa = "5BRALFFKNML53X4MJVTWBSBYSDSNRIHQ"; $parties = $holaa; $pay_id_received = trigger.data.pay_id otherwise trigger.data.pi otherwise ""; // use cases $validate_pay = $pay_id_received != ""; $cancel = ($pay_id_received != "") AND (trigger.data.cancel==true); }", "messages": { "cases": [ { "if": "{trigger.data.create}", "init": "{ }", "messages": [ { "app": "data", "payload": { "create": "{trigger.data.create}" } }, { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{$holaa}", "amount": 1 } ] } }, { "app": "state", "state": "{ var[trigger.data.create] = trigger.output[[asset=base]]; var[trigger.data.create||"_in_creation"] = trigger.address; // to avoid abuse; response['message'] = trigger.data.create||" create, please add parties."; }" } ] }, { "if": "{trigger.data.add_party}", "init": "{ if (!trigger.data.account) bounce ("Need 'account'!"); if (!(var[$parties][trigger.data.account])) bounce (trigger.data.account||" do not exist"); if (!(var[trigger.data.account||"_in_creation"])) bounce ("The account is final"); if (var[trigger.data.account||"_in_creation"] != trigger.address) bounce ("You are not the account creator!"); }", "messages": [ { "app": "data", "payload": { "list_name": "{trigger.data.account}", "add": "{trigger.data.add_party}" } }, { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{$parties}", "amount": 1 } ] } }, { "app": "state", "state": "{ response['message'] = trigger.data.add_party||" added ^^"; }" } ] }, { "if": "{trigger.data.finalize}", "init": "{ $account= trigger.data.finalize; if (!(var[$parties][$account])) bounce ($account||" do not exist"); if (!(var[$account||"_in_creation"])) bounce ("The account is already final"); if (var[$account||"_in_creation"] != trigger.address) bounce ("You are not the account creator!"); if (var[$holaa][$account||"_count"] < 2) bounce ("the minimum is 2 parties, use 'add_party'"); }", "messages": [ { "app": "state", "state": "{ var[trigger.data.account||"_in_creation"] = false; response['message'] = trigger.data.account||" finalized ^^"; }" } ] }, { "if": "{ trigger.data.pay_to }", "init": "{ $account = trigger.data.account; if (!($account)) bounce ("Need 'account'!"); if (!(trigger.data.amount)) bounce ("Need 'amount'!"); if (!(var[$parties][$account])) bounce ($account||" do not exist"); if (var[$account||"_in_creation"] != trigger.address) bounce ("Account not finalized!"); $pay_id_created = sha256($account||'>'||trigger.data.pay_to||':'||trigger.data.amount); //var[$parties][$account||] if (trigger.address == $party1) { $need_party1_validation = false; $initiator = 1; } else { if (trigger.address == $party2) { $need_party2_validation = false; $initiator = 2; } else { if (trigger.address == $party3) { $need_party3_validation = false; $initiator = 3; } else bounce ("You are not a party of "||$account); } } if ($initiator==1) $next_validator_num = 2; else $next_validator_num = 1; }", "messages": [ { "app": "data", "payload": { "message": "{"JAAAWS: Your approval is required for a payment from the account '"||$account||" to pay "||trigger.data.amount||" to "||trigger.data.pay_to||", please send me back the pay_id linked to validate the transaction. And add a cancel = true field to refuse it."}", "pay_id": "{$pay_id_created}" } }, { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{var[$account||"_"||$next_validator_num]}", "amount": 1000 } ] } }, { "app": "state", "state": "{ var[$pay_id_created||"_account"] = $account; var[$pay_id_created||"_amount"] = $pay_amount; var[$pay_id_created||"_address"] = $pay_address; var[$pay_id_created||"_initiator"] = trigger.address; if ( $need_party1_validation) var[$pay_id_created||"_required_v1"] = true; if ( $need_party2_validation) var[$pay_id_created||"_required_v2"] = true; if ( $need_party3_validation) var[$pay_id_created||"_required_v3"] = true; response['message'] = "Payment "||$pay_id_created||" created and approvals requested"; }" } ] }, { "if": "{$validate_pay}", "init": "{ $account_received = var[$pay_id_received||"_account"] otherwise ""; $pay_amount_to_valid = var[$pay_id_received||"_amount"] otherwise 0; $pay_address_to_valid = var[$pay_id_received||"_address"] otherwise ""; if ($account_received == "") bounce ("Payment ID "||$pay_id_received||" do not exist!"); // check if validation was needed if ($trigger == var[$account_received||"_1"]) $validator_num = 1; if ($trigger == var[$account_received||"_2"]) $validator_num = 2; if ($trigger == var[$account_received||"_3"]) $validator_num = 3; $is_this_validation_needed = var[$pay_id_created||"_required_v"||$validator_num] otherwise false; if ($is_this_validation_needed ==false) bounce ("Your validation by validator "||$validator_num||"is not required!"); $is_next_needed = var[$pay_id_created||"_required_v"||($validator_num+1)] otherwise false; if ($is_next_needed == true) { $next_address = var[$account_received||"_"||($validator_num+1)]; $next_amount = 1000; $next_message = "JAAAWS: Your approval is required for a payment from the account '"||$account_received||" to pay "||$pay_amount_to_valid||" to "||$pay_address_to_valid||", please send me back the pay_id linked to validate the transaction. And add a cancel = true field to refuse it."; } else { // lets do the payment $next_address = $pay_address_to_valid; $next_amount = $pay_amount_to_valid; $next_message = "Payment of "||$next_amount||" done to "||$next_address||" from account "||$account_received; } }", "messages": [ { "app": "data", "payload": { "message": "{$next_message}", "pay_id": "{$pay_id_received}" } }, { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{$next_address}", "amount": "{$next_amount}" } ] } }, { "app": "state", "state": "{ var[$pay_id_created||"_required_v"||$validator_num] = false; if ($is_next_needed != true) { var[$account_received] = false; var[$pay_address_to_valid] = false; var[$pay_amount_to_valid] = false; } }" } ] }, { "if": "{$cancel}", "init": "{ $account_received = var[$pay_id_received||"_account"] otherwise ""; $amount = var[$pay_id_received||"_amount"] otherwise 0; $address = var[$pay_id_received||"_address"] otherwise ""; if (trigger.address == var[$account_received||"_1"]) $cancel_valid = true; if (trigger.address == var[$account_received||"_2"]) $cancel_valid = true; if (trigger.address == var[$account_received||"_2"]) $cancel_valid = true; if (trigger.address == $address) $cancel_valid = true; if ($cancel_valid==false) bounce ("You must be a party to cancel!"); }", "messages": [ { "app": "state", "state": "{ var[$account_received] = false; var[$address] = false; var[$amount] = false; var[$pay_id_created||"_required_v1"] = false; var[$pay_id_created||"_required_v2"] = false; var[$pay_id_created||"_required_v3"] = false; response['message'] = "Payment of "||$amount||" to "||$address||" is cancelled by "||trigger.address; }" } ] }, { "messages": [ { "init": "{ if ($account=="") bounce ("need account name"); $input = trigger.output[[asset=base]]; }", "app": "state", "state": "{ var[$account] += $input; response['message'] = $input||" added to the account "||$account; }" } ] } ] } } ]
Technical information
Fees:
7,950 bytes
(353 headers, 7597 payload)
Level:1023059
Witnessed level:1023051
Main chain index:1021872
Latest included mc index:1021871
Status:stable/confirmed/final