Definition: [
"autonomous agent",
{
"init": "{
// JAA, Joint Account Agent
$owner = "O7NYCFUL5XIJTYE3O4MKGMGMTN6ATQAJ"; //office_testnet_wallet
$account = trigger.data.account otherwise trigger.data.ac otherwise ""; // sha256()?
$trigger = trigger.address;
$pay_amount = trigger.data.amount otherwise trigger.data.am otherwise 0;
$pay_address = trigger.data.address otherwise trigger.data.ad otherwise "";
$pay_id_received = trigger.data.pay_id otherwise trigger.data.pi otherwise "";
// use cases
$setup = (trigger.data.a1) AND (trigger.data.a2); // minimum 2.
$init_pay = ($pay_amount>0) AND ($pay_address !="");
$validate_pay = $pay_id_received != "";
}",
"messages": {
"cases": [
{
"if": "{$setup}",
"init": "{
if ($account=="") bounce ("need account name");
if (var[$account]) bounce ("Account "||$account||" already exist!");
}",
"messages": [
{
"app": "state",
"state": "{
var[$account] = trigger.output[[asset=base]];
var[$account||"_1"] = trigger.data.a1;
var[$account||"_2"] = trigger.data.a2;
response['message'] = 'Multi-sig account set for '||$account||'. ';
}"
}
]
},
{
"if": "{$init_pay}",
"init": "{
if ($account=="") bounce ("need account name");
if (!var[$account]) bounce ("Account "||$account||" do not exist!");
$pay_id_created = sha256($account||'>'||$pay_address||': '||$pay_amount);
$validator_num = ($trigger == var[$account||"_1"]) ? "2": "1";
$validator = $account||"_"||$validator_num;
}",
"messages": [
{
"app": "data",
"payload": {
"message": "{"Your approval is required for a payment from "||$account||" to pay "||$pay_amount||" to pay "||$pay_address||", please send me (AA) back the pay_id linked to validate the transaction. "}",
"pay_id": "{$pay_id_created}"
}
},
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{var[$validator]}",
"amount": 1000
}
]
}
},
{
"app": "state",
"state": "{
var[$pay_id_created||"_amount"] = $pay_amount;
var[$pay_id_created||"_address"] = $pay_address;
var[$pay_id_created||"_v"||$validator_num||"_required"] = true;
response['message'] = "Payment "||$pay_id_created||" created and approvals requested";
}"
}
]
},
{
"if": "{$validate_pay}",
"init": "{
if (var[$account]) bounce ("Account "||$account||" do not exist!");
$amount = var[$pay_id_received||"_amount"] otherwise 0;
if ($amount == 0) bounce ("Payment ID "||$pay_id_received||" do not exist!");
$address = var[$pay_id_received||"_address"] otherwise "";
$validator_num = ($trigger == var[$account||"_1"]) ? "1": "2";
$require = $pay_id_received||"_v"||$validator_num||"_required";
if (var[$require] != true)
bounce ("Your validation is not required!");
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$address}",
"amount": "{$amount}"
}
]
}
},
{
"app": "state",
"state": "{
var[$address] = false;
var[$amount] = false;
var[$require] = false;
response['message'] = "Payment of "||$amount||" done to "||$address;
}"
}
]
},
{
"messages": [
{
"app": "state",
"state": "{
var[$account] += trigger.output[[asset=base]];
}"
}
]
}
]
}
}
]