Definition: [
"autonomous agent",
{
"bounce_fees": {
"base": 10000
},
"init": "{
$developper = "B2UMBICLZSBVDHRC7BYM6BBU4AQEXL2F"; //errors are donations^^
$howto = "Give me a 'destination' address, a 'duration' in hours and the 'hash' of the secret allowing to release the funds and I will keep the funds safe during that time.";
}",
"messages": {
"cases": [
{
"if": "{ !!params.destination and !!params.duration_in_hours and !!params.hash_secret}",
"messages": [
{
"app": "state",
"state": "{
var["origin"] = trigger.address;
var["destination"] = params.destination;
$amount = trigger.output[[asset=base]].amount; var["amount"] = $amount;
$deadline = timestamp + json_parse(params.duration_in_hours); var["deadline"] = $deadline;
var["hash_of_secret"] = params.hash_of_secret;
response['message'] = 'Lock, holding '||$amount||' bytes until '||timestamp_to_string($deadline, 'datetime')||' hours, created by '||trigger.address||' for '||params.destination||'.';
}"
}
]
},
{
"if": "{ !!var["deadline"] and timestamp>var["deadline"] }",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{var["sender"]}",
"amount": "{balance[base]}"
}
]
}
},
{
"app": "state",
"state": "{
var["deadline"] = false;
response['message'] = 'Cancelled, bytes sent back to origin address';
}"
}
]
},
{
"if": "{!!var["deadline"] and var["gb_receiver"] == trigger.address }",
"init": "{
$message = "You have been recognized but ";
if (!params.secret)
bounce ($message||"you have to provide the 'secret' revealed on the other chain");
if (sha256(params.secret) != var["hash_of_secret"])
bounce ($message||"the secret is not good one.");
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{var["destination"]}",
"amount": "{var["amount"]}"
}
]
}
},
{
"app": "state",
"state": "{
var["deadline"] = false;
response['message'] = 'Transfer successfull!';
}"
}
]
},
{
"if": "{!var["deadline"] and !!var["hash_of_secret"] }",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{$developper}",
"amount": "{balance[base]}"
}
]
}
},
{
"app": "state",
"state": "{
response['message'] = 'Thank you for this donation!';
}"
}
]
},
{
"messages": [
{
"app": "state",
"state": "{
bounce($howto) ;
}"
}
]
}
]
}
}
]