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