Definition: [
"autonomous agent",
{
"bounce_fees": {
"base": 10000
},
"init": "{
// admin stuff
$this = {
name: "THAANKS",
owner:"O7NYCFUL5XIJTYE3O4MKGMGMTN6ATQAJ",
use_cases: "Be first to use 'token = <received token>' after the request time and before the acceptable delay to receive the associated reward. To subscribe as an helper and have a chance to be picked up later use: 'subscribe = true'. To unsubscribe use: 'unsubscribe = true'. If your are an AA use at minimum 'ask_help = <true>'.",
how_to: "Use 'ask_help = <true>' with optionaly 'helper = <address>' if you want to propose an helper. Use 'private_mode = true' to force the triggering to be done by the specific helper. If you need to be trigger after a given time, use 'request_time = <timestamp>' and if you want to give a dead line use 'acceptable_delay = <delay in seconds>'. "
}; // to collect the dust
}",
"messages": {
"cases": [
{
"if": "{ !!trigger.data.request_tag }",
"init": "{
$request = json_parse(var[trigger.data.request_tag] otherwise bounce ("Too late or wrong tag"));
if ($request.time > timestamp) bounce ("Too early, try at "||timestamp_to_string($request.time));
if (!!$request.private and $request.private != trigger.address) bounce ("Private reward!");
$is_late = timestamp > $request.deadline;
$reward_destination = $is_late ? $request.aa : trigger.address;
}",
"messages": [
{
"app": "data",
"payload": {
"tag": "{trigger.data.request_tag}"
}
},
{
"if": "{ !!$request.asset != "base" }",
"app": "payment",
"payload": {
"asset": "{$request.asset}",
"outputs": [
{
"address": "{ $reward_destination }",
"amount": "{ $request.amount }"
}
]
}
},
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{ $reward_destination }",
"amount": "{ $request.amount }"
},
{
"if": "{ !$is_late }",
"address": "{ $request.aa }",
"amount": "{ 1 }"
}
]
}
},
{
"app": "state",
"state": "{
var[trigger.data.request_hash] = false;
response['message'] = $is_late ? "Too late, sorry !" : trigger.address||" has been rewarded ^^";
}"
}
]
},
{
"messages": [
{
"app": "state",
"state": "{
$new_request = {
address: trigger.data.address otherwise trigger.address,
time: trigger.data.requested_time otherwise timestamp,
deadline: trigger.data.requested_time + trigger.data.acceptable_delay otherwise 10*24*60*60,
private: trigger.data.trigger_address,
amount: trigger.output[[asset!=base]].amount otherwise trigger.output[[asset=base]].amount-2000,
asset: trigger.output[[asset!=base]].asset != "none"? trigger.output[[asset!=base]].asset: "base",
};
$tag = trigger.data.tag otherwise sha256($new_request.address||$new_request.time);
var[$tag] = json_stringify($new_request);
response['message'] = "Trigger-Request "||$tag||" created";
}"
}
]
}
]
}
}
]