[
"autonomous agent",
{
"bounce_fees": {
"base": 10000
},
"init": "{
// Store an easy accessible proof that You Were Holding Asset In The Past that can be used by an AA.
$name = "DAG Snapshot for AA";
// made to be used by an other AA via var[this_aa_address][sha256($address||$asset||$timestamp)]
// The user trigger the this AA with information and the AA store a state var linking address and timestamp to amount.
// will probably work only for funds on single address wallet :(
}",
"messages": {
"cases": [
{
"if": "{ !!trigger.data.first_unit_id and !!trigger.data.second_unit_id and !!trigger.data.timestamp }",
"init": "{
$address = trigger.data.address otherwise trigger.address;
if(!is_valid_address($address)) bounce ("invalid address");
$asset = trigger.data.asset otherwise "base";
$date_and_time = timestamp_to_string(trigger.data.timestamp);
if(!is_integer(trigger.data.timestamp )) bounce("invalid timestamp");
$first_timestamp = unit[trigger.data.first_unit_id].timestamp;
response['nts'] = 'kGQZkIj3gRclCp2vw9LMg0jVnPKYCebXHxm8XYPxbQ4=';
response['ts'] = unit['kGQZkIj3gRclCp2vw9LMg0jVnPKYCebXHxm8XYPxbQ4='].timestamp;
response['mts'] = trigger.data.first_unit_id;
response['mts'] = unit[trigger.data.first_unit_id].timestamp;
if(!$first_timestamp) bounce ('first unit not existing');
if($first_timestamp>trigger.data.timestamp) bounce("first unit should be earlier than "||$date_and_time||"("||$first_timestamp||")");
$second_timestamp = unit[trigger.data.second_unit_id].timestamp;
if(!$second_timestamp) bounce ('second unit not existing');
if(trigger.data.timestamp>$second_timestamp) bounce("second unit should be older than "||$date_and_time||"("||$second_timestamp||")");
$amount_from_first = unit[trigger.data.first_unit_id].messages[[.app='payment']].payload.outputs[[.address=$address, .asset=$asset]].amount;
if(!$amount_from_first)bounce("asset not existing in first unit");
$amount_from_second= unit[trigger.data.second_unit_id].messages[[.app='payment']].payload.outputs[[.address=$address, .asset=$asset] ].amount;
if(!$amount_from_second)bounce("asset not existing in second unit");
$prooven_amount = ($amount_from_first<$amount_from_second) ? $amount_from_first : $amount_from_second;
$id = sha256($address||$asset||trigger.data.timestamp); // to be able to use different assets and timestamps for a given address.g
if (!!var[$id]) bounce ("proof already existing for "||var[$id]||' '||$asset);
}",
"messages": [
{
"app": "state",
"state": "{
var[$id] = $prooven_amount;
response["message"] = $prooven_amount||' '||$asset||" proof stored";
}"
}
]
},
{
"messages": [
{
"app": "state",
"state": "{
bounce ("I want to create for you a proof that your actual address was hodling some bytes at a given time. For that, I need a 'first_unit_id', 'second_unit_id' showing your actual address with bytes and the 'timestamp', to store the 'hodling amount proof', the timestamp must be included betwwen the timestamp of the first and the second unit.");
}"
}
]
}
]
}
}
]
Response: {
"error": "I want to create for you a proof that your actual address was hodling some bytes at a given time. For that, I need a 'first_unit_id', 'second_unit_id' showing your actual address with bytes and the 'timestamp', to store the 'hodling amount proof', the timestamp must be included betwwen the timestamp of the first and the second unit."
}