Definition: [
"autonomous agent",
{
"bounce_fees": {
"base": 10000
},
"init": "{
// constantes
$name = "WEAALTH";
$how_to_claim = "To claim you heritage, enter you signature";
$how_to_setup = "To setup your testament, use, start+testament name then add + beneficiary + percentage, then finish then fill and later cancel_request";
$how_to = $how_to_claim||$how_to_setup;
$request_heritage_fee = 50000;
$HOLLAA = "C6M6BLAM2QTK727RTWA3YHZ4VW5ZIGBF";
$Shafe = '2W6XFKSHXI5OJRZR7T4LQBFZ2GZ3BZBN'; // AA from sharjar, easy version of safe storage
$DEFAULT_DELAY_TO_CANCEL = 4 * 7 * 24 * 60 * 60; // 4 weeks
}",
"messages": {
"cases": [
{
"if": "{ !!trigger.data.start and !!trigger.data.testament_name }",
"messages": [
{
"app": "state",
"state": "{
// existing?
if (!!var[trigger.data.testament_name]) bounce ("This name exist already!");
// for the moment store the user for faster next steps
var[trigger.address] = trigger.data.testament_name;
// store the testament writter to be able to change his mind
var[trigger.data.testament_name||"_writter"] = trigger.address;
// create the testament balance:
var[trigger.data.testament_name||"_balance"] = trigger.output[[asset=base]].amount - 2000;
response['message'] = 'Testament setup started';
}"
}
]
},
{
"if": "{ !!trigger.data.add and !!trigger.data.beneficiary and !!trigger.data.percentage}",
"init": "{
$testament_name = var[trigger.address] otherwise trigger.data.testament_name otherwise bounce ($how_to);
if (!trigger.data.hash_of_secret)
bounce ("need 'hash_of_secret'");
if (!!var[$testament_name||"_writter"])
if (trigger.address != var[$testament_name||"_writter"])
bounce ("Account "||$testament_name||" already exist!");
// inputs tests
if (!is_integer(trigger.data.percentage)) bounce ("Invalid percentage'!");
if (trigger.data.percentage>100) bounce ("Invalid percentage'!");
}",
"messages": [
{
"app": "data",
"payload": {
"list_name": "{ $testament_name||"_beneficiaries" }",
"add": "{ trigger.data.beneficiary }",
"value": "{ "hash="||trigger.data.hash_of_secret||" %="||trigger.data.percentage }"
}
},
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{ $HOLLAA }",
"amount": 1000
}
]
}
},
{
"app": "state",
"state": "{
var[$testament_name||"_balance"] = trigger.output[[asset=base]].amount - 1000;
response['message'] = 'Beneficiariey added';
}"
}
]
},
{
"if": "{ !!trigger.data.finish_testament }",
"init": "{
$testament_name = var[trigger.address] otherwise trigger.data.testament_name otherwise bounce ($how_to);
if (!!var[$testament_name||"_writter"])
if (trigger.address != var[$testament_name||"_writter"])
bounce ("Account "||$testament_name||" already exist!");
}",
"messages": [
{
"app": "state",
"state": "{
var[trigger.address] = false;
var[$testament_name||"_balance"] = trigger.output[[asset=base]].amount - 1000;
response['message'] = $testament_name||" activated ^^";
}"
}
]
},
{
"if": "{ !!trigger.data.fill }",
"init": "{
$testament_name = trigger.data.testament_name otherwise bounce ($how_to);
}",
"messages": [
{
"app": "state",
"state": "{
var[$testament_name ||"_balance"] += trigger.output[[asset=base]].amount;
response['message'] = "Testament balance updates ^^";
}"
}
]
},
{
"if": "{ !!trigger.data.request_heritage and !!trigger.data.beneficiary }",
"init": "{
$testament_name = trigger.data.testament_name otherwise bounce ($how_to);
// Check big fee to limit spam
if (trigger.output[[asset=base]].amount < $request_heritage_fee)
bounce ("Minimum fee for this is "||$request_heritage_fee);
// Inputs tests
if (!var[$testament_name||"_writter"])
bounce ("Account "||$testament_name||" do NOT exist!");
// Test if the user is really a beneficiary
if (!var[$HOLLAA][$testament_name||"_beneficiaries_"||trigger.data.beneficiary])
bounce ("Beneficiary do not exist");
// Check the phase of the withdraw
if (!!var[$testament_name||"_requester_address"])
bounce ("Heritage validation already requested, wait for the waiting delay to expire and use 'ask_to_proof_ownership'");
// Check if the testament is not already validated so taht the user can directly proof ownership
if (!!var[$testament_name||"_validated"])
bounce ("the testament execution is already validated, you can directly use 'proove_ownership'");
}",
"messages": [
{
"app": "data",
"payload": {
"message": "{ trigger.data.beneficiary||" have requested his heritage" }"
}
},
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{ var[$testament_name||"_writter"] }",
"amount": 1000
}
]
}
},
{
"app": "state",
"state": "{
var[$testament_name||"_requester_address"] = trigger.address;
var[trigger.address||"_requested_time"] = timestamp;
var[trigger.address||"_beneficiary"] = trigger.data.beneficiary;
var[trigger.address||"_testament_name"] = $testament_name;
var[$testament_name||"_balance"] -= 1000;
response['message'] = "Request validated";
}"
}
]
},
{
"if": "{ !!trigger.data.ask_to_proof_ownership }",
"init": "{
// check if this address has requested heritage
if (!var[trigger.address])
bounce ("You cannot proof ownership before you have requested your heritage and waited for the delay");
if (!var[$testament_name||"_validated"])
{
// check if delay expired
$delay_to_cancel = var[var[trigger.address||"_testament_name"]||"_waiting_period"]
otherwise $DEFAULT_DELAY_TO_CANCEL;
$earlier_time = var[trigger.address||"_requested_time"] + $delay_to_cancel;
if (timestamp < $earlier_time)
bounce ("Too early to proof onwership wait for "||timestamp_to_string($earlier_time, 'datetime'));
// validate heritage
$validated=true;
}
// calculate part
$beneficiary = var[trigger.address||"_beneficiary"];
$hash_and_percentage = var[$HOLLAA][$testament_name||"_beneficiaries_"||$beneficiary];
$separator_pos=index_of($hash_and_percentage, " %=");
$hash = substring($hash_and_percentage, 0, $separator_pos);
// convert percentage as string to number
$percentage = json_parse(substring($hash_and_percentage, $separator_pos + 3));
// the final balance to share is the actual for the first proof or the stored one for the next ones
$final_balance = var[$testament_name||"_final_heritage_balance"] otherwise var[$testament_name||"_balance"];
// compute heritage part
$heritage_value = round(var[$testament_name||"_balance"] * $percentage / 100) + $request_heritage_fee ;
}",
"messages": [
{
"app": "data",
"payload": {
"list_name": "{ $testament_name||"_beneficiaries" }",
"remove": "{ var[trigger.address||"_beneficiary"] }",
"store": "{ $percentage||" % of the "||$testament_name||" heritage" }",
"hash_of_secret": "{ $hash }",
"message": "{ "Heritage available by providing your secret to AA: "||$Shafe }"
}
},
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{ $HOLLAA }",
"amount": 500
},
{
"address": "{ $Shafe }",
"amount": "{ $heritage_value }"
},
{
"address": "{ trigger.data.withdraw_address }",
"amount": "{ 66 }"
}
]
}
},
{
"app": "state",
"state": "{
if(!!$validated)
{
var[$testament_name||"_validated"] =true;
var[$testament_name||"_final_heritage_balance"] = var[$testament_name||"_balance"];
}
var[$testament_name||"_balance"] -= $heritage_value;
response['message'] = 'Heritage withdrawn';
}"
}
]
},
{
"if": "{ !!trigger.data.cancel_request }",
"init": "{
$testament_name = trigger.data.testament_name otherwise
bounce ("Add 'testament_name'");
// inputs tests
if (!var[$testament_name||"_writter"])
bounce ("Account "||$testament_name||" do NOT exist!");
// check that it is the writter
if (trigger.address != var[$testament_name||"_writter"])
bounce ("you must be the writter of the will to cancel a request");
// check if heritage already validated
if (!!var[$testament_name||"_validated"])
bounce ("Sorry, too late the heritage has been validated");
}",
"messages": [
{
"app": "state",
"state": "{
var[$testament_name||"_requester_address"] = false;
var[$requester_address||"_requested_time"] = false;
var[$requester_address||"_beneficiary"] = false;
var[$requester_address||"_testament_name"] = false;
response['message'] = 'Heritage request cancelled';
}"
}
]
},
{
"messages": [
{
"app": "state",
"state": "{
bounce ($how_to);
}"
}
]
}
]
}
}
]