[
"autonomous agent",
{
"init": "{
$puk = trigger.data.puk1||trigger.data.puk2;
$asset = trigger.output[[asset=base]].asset;
$key = $puk||'_'||$asset;
}",
"messages": {
"cases": [
{
"if": "{(trigger.data.puk1) AND (trigger.data.puk2) AND (!trigger.data.s) AND (!trigger.data.ad)}",
"messages": [
{
"app": "state",
"state": "{
var[$key] += trigger.output[[asset=base]];
response['message'] = var[$key]||' '||$asset||' are safe under the puk '||$puk;
}"
}
]
},
{
"if": "{(trigger.data.puk1) AND (trigger.data.puk2) AND (trigger.data.s1) AND (trigger.data.s2) AND (trigger.data.ad)}",
"init": "{
$asset_withdrawn = trigger.data.asset otherwise $asset;
if (!var[$key]) bounce ("puk doesn\'t exists with asset "||$asset);
if (!is_valid_sig(trigger.data.ad, "-----BEGIN PUBLIC KEY-----"||$puk||"-----END PUBLIC KEY-----", trigger.data.s1||trigger.data.s2)) bounce ("Wrong signature!");
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "{$asset}",
"outputs": [
{
"address": "{trigger.data.ad}",
"amount": "{var[$key]}"
}
]
}
},
{
"app": "state",
"state": "{
response['message'] = var[$key]||' '||$asset||' withdrawn from '||$puk||' to '|| trigger.data.ad;
var[$key] = false;
}"
}
]
},
{
"messages": [
{
"app": "state",
"state": "{
bounce ("Set a 'puk1' and 'puk2' field to <the 2 half of the public key, for which you have the related private key> to safely store funds. To withdraw later, set the same 'puk', as well as a 'ad' field to <the Obyte adresse where you want to receive the funds> and a 's1' and 's2' field to <the 2 half signature of a message containing the address 'a'>.");
}"
}
]
}
]
}
}
]
Response: {
"responseVars": {
"message": "333333 base withdrawn from MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE90U9sMxra8wxIaIBy87p09aM8n4rKe1eZOtL0Im19ItIIzT3AiKE0dRsHemcn5bUcSqnC/jC+3H8vaCtjn9ylg== to O7NYCFUL5XIJTYE3O4MKGMGMTN6ATQAJ"
}
}
Response: {
"responseVars": {
"message": "333333 base are safe under the puk MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE90U9sMxra8wxIaIBy87p09aM8n4rKe1eZOtL0Im19ItIIzT3AiKE0dRsHemcn5bUcSqnC/jC+3H8vaCtjn9ylg=="
},
"error": "no messages after filtering"
}