[
"autonomous agent",
{
"init": "{
$aa_name = "AAAA"; // Dynamic Asset Names Autonomous Agent;
$owner = "
O7NYCFUL5XIJTYE3O4MKGMGMTN6ATQAJ"; // could withdraw the dust is calculable.
$i = trigger.data;
}",
"messages": {
"cases": [
{
"if": "{ $i.create }",
"init": "{
$list_name = $i.create;
if (var[$list_name])
bounce ("'"||$list_name||"' already exist!");
}",
"messages": [
{
"app": "state",
"state": "{
var[$list_name] = trigger.address; //owner of the list;
var[$list_name||"_count"] = 0 ;
var[$list_name||"_is_public"] = $i.public;
response['message'] = $list_name||" created ^^.";
}"
}
]
},
{
"if": "{ $i.add }",
"init": "{
$list_name = $i.list_name;
if (!$list_name)
bounce ("Need 'list_name'!");
if (!(var[$list_name]))
bounce ("'"||$list_name||"' do not exist !");
if (!(var[$list_name||"_is_public"]))
if (trigger.address != var[$list_name])
bounce ("You don't own this private list");
$new_entry = $i.add;
}",
"messages": [
{
"app": "state",
"state": "{
var[$list_name||"_count"] +=1;
var[$list_name||"_"||$new_entry] = var[$list_name||"_count"];
var[$list_name||"_"||var[$list_name||"_count"]] = $new_entry;
response['message']= $new_entry||" added ^^.";
}"
}
]
},
{
"if": "{ $i.delete }",
"init": "{
$list_name = $i.delete;
if (!(var[$list_name]))
bounce ("'"||$i.list_name||"' did not exist at the first place!");
if (trigger.address != var[$list_name])
bounce ("Must be owner to delete the list");
if (var[$list_name||"_count"] > 0)
bounce ("List must be empty to be deleted, use 'remove_last' as much as needed");
}",
"messages": [
{
"app": "state",
"state": "{
var[$list_name] = false;
var[$list_name||"_count"] = false;
response['message']= $list_name||" delete ^^.";
}"
}
]
},
{
"if": "{ $i.remove_last }",
"init": "{
$list_name = $i.remove_last;
if (!(var[$list_name]))
bounce ("'"||$i.list_name||"' did not exist !");
if (trigger.address != var[$list_name])
bounce ("Must be owner to remove last entry of the list");
if (var[$list_name||"_count"] == 0)
bounce ("List is empty!");
}",
"messages": [
{
"app": "state",
"state": "{
// get last entry
$last_entry = var[$list_name||"_"||var[$list_name||"_count"]];
// remove it
var[$list_name||"_"||$last_entry] = false;
var[$list_name||"_"||var[$list_name||"_count"]] = false;
var[$list_name||"_count"] -= 1;
response['message']= $last_entry||" removed ^^.";
}"
}
]
},
{
"messages": [
{
"app": "state",
"state": "{
bounce ("default case");
}"
}
]
}
]
}
}
]