[
"autonomous agent",
{
"bounce_fees": {
"base": 10000
},
"init": "{
// forever constantes
$INSTRUCTIONS = "Please use 'register = <aa name>'' + 'address = <aa address>' to add your AA as a new entry or to update with a new version. Please use '(dis)like' = <aa name> + 'version' = <version> to give your opinion on a version of an AA (you need to be attested by the real name attestor).!";
$AA_OWNER = "
O7NYCFUL5XIJTYE3O4MKGMGMTN6ATQAJ";
$ATTESTATOR = '35IT3ZYKEPQSCXG2F7A7KWNRAD3SZXN4';
// see all possible inputs here:
$register = trigger.data.register;
$aa_address = trigger.data.address;
$like = trigger.data.like;
$dislike = trigger.data.dislike;
$aa_version = trigger.data.version;
$need_help = trigger.data.help otherwise trigger.data.h;
// define var that are use in each use cases
$name = trigger.data.register otherwise trigger.data.like otherwise trigger.data.dislike otherwise
bounce ($INSTRUCTIONS);
$key = $name||"_";
$popular_version = var[$key||"popular_version"];
$popular_version_number = var[$key||"popular_version_number"];
}",
"messages": {
"cases": [
{
"if": "{ !!$register }",
"init": "{
if (!!var[$key||"owner"])
if (var[$key||"owner"] != trigger.address)
bounce ("You are not the owner !");
if (!$aa_address)
bounce ("Please specify 'address' !");
$version = var[$key||"last_version_number"] + 1 otherwise 1;
}",
"messages": [
{
"app": "state",
"state": "{
// for each AA we want to keep:
var[$key||"owner"] = trigger.address; // only user allow to update the AA
var[$key||"last_version_number"] = $version;
var[$key||"last_version"] = $aa_address;
var[$key||"popular_version"] = $popular_version otherwise $aa_address;
var[$key||"popular_version_number"] = $popular_version_number otherwise $version;
// for each version we want to keep
var[$key||$version||"_address"] = $aa_address;
var[$key||$version||"_likes"] = 0;
var[$key||$version||"_dislikes"] = 0;
var[$key||$version||"_date"] = timestamp_to_string(timestamp);
// response
response['message'] = "New version of your aa has been registered ^^";
}"
}
]
},
{
"if": "{ !!$like or !!$dislike}",
"init": "{
if (attestation[[attestors=$ATTESTATOR, address=trigger.address, ifnone=false]] == false)
bounce ("To like or dislike you must be attested by "||$ATTESTATOR);
$version = $aa_version otherwise bounce ("Please specify 'version'");
if (!var[$key||$version||"_address"])
bounce ($key||$version||" do not exist !");
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{ trigger.output[[asset=base]]-1000 }"
}
]
}
},
{
"app": "state",
"state": "{
// proceed voting
if ($b_want_to_like) var[$key||$version||"_likes"] +=1;
if ($b_want_to_dislike) var[$key||$version||"_dislikes"] -=1;
// check if it became the most popular version
if (var[$key||$version||"_likes"] > var[$key||$popular_version_number||"_likes"])
{
var[$key||"popular_version_number"] = var[$key||$version];
var[$key||"popular_version"] = var[$key||$version||"_address"];
}
response['message'] = "You vote has been taken into account ^^ ";
}"
}
]
},
{
"messages": [
{
"app": "state",
"state": "{
bounce ($INSTRUCTIONS);
}"
}
]
}
]
}
}
]