Unit ID
nlT50LKTrkrXcAGyYCsfbxrPY3glHxdDc436lN7Z2So=
Received
10.10.2019 17:52:49
Confirmation delay (full node)
5 minutes 56 seconds
Confirmation delay (light node)
9 minutes 45 seconds
Messages
Definition
Definition: [ "autonomous agent", { "bounce_fees": { "base": 10000 }, "init": "{ // general instruction to bounce when no inputs are set yet $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).!"; // we need an attestor to avoid that scammers vote multiple times by changing addresses $ATTESTATOR = '35IT3ZYKEPQSCXG2F7A7KWNRAD3SZXN4'; // address of secondary AA to store the addresses of voters to avoid multiple votes $HOLLAA = "YNB262XRUZYZTG5YSTS4QCWE4C6ZEEP2"; // define var that are use in each use cases $name = trigger.data.register otherwise trigger.data.like otherwise trigger.data.dislike otherwise bounce ($INSTRUCTIONS); $popular_version_number = var[$name||"_"||"popular_version_number"]; }", "messages": { "cases": [ { "if": "{ !!trigger.data.register }", "init": "{ // if the name is already existing, you must be owner to update it with a new version if (!!var[$name||"_owner"]) if (var[$name||"_owner"] != trigger.address) bounce ("You are not the owner !"); // aa address must be provided if (!trigger.data.address) bounce ("Please specify 'address' !"); // check that the address is really an AA address if (!is_aa(trigger.data.address)) bounce ("The address must the address of confirmed AA !"); // in case of update, we increase the version number, otherwise we start with version 1 $version_number = var[$name||"_last_version_number"] + 1 otherwise 1; // get AA version full name $version_name = $name||"_"||$version_number; }", "messages": [ { "app": "data", "payload": { "list_name": "{ $voted_version_name||"_voters" }", "add": "{ trigger.address }", "value": "{ "+1" }" } }, { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{trigger.address}", "amount": "{ trigger.output[[asset=base]]-2000 }" }, { "address": "{$HOLLAA}", "amount": "{ 100 }" } ] } }, { "app": "state", "state": "{ // for each AA we want to keep: var[$name||"_owner"] = trigger.address; // only user allow to update the AA var[$name||"_last_version_number"] = $version_number; var[$name||"_popular_version_number"] = $popular_version_number otherwise $version_number; // for each version we want to keep var[$version_name||"_address"] = trigger.data.address; var[$version_name||"_likes"] = 1; var[$version_name||"_dislikes"] = 0; var[$version_name||"_date"] = timestamp_to_string(timestamp); // response to show some information in the unit that triggered the AA response['message'] = "New version of your AA has been registered ^^"; }" } ] }, { "if": "{ !!trigger.data.like or !!trigger.data.dislike}", "init": "{ // check that the voter is attested if (attestation[[attestors=$ATTESTATOR, address=trigger.address, ifnone=false]] == false) bounce ("To like or dislike you must be attested by "||$ATTESTATOR); // check that the version is provided $version_number = trigger.data.version otherwise bounce ("Please specify 'version'"); // get voted version full name $voted_version_name = $name||"_"||$version_number; // check that the version provided exists if (!var[$voted_version_name||"_address"]) bounce ($voted_version_name||" do not exist !"); // check if the voter never votes for this version if (!!var[$HOLLAA][$voted_version_name||"_voters_"||trigger.address]) bounce ("Cannot vote twice!"); }", "messages": [ { "app": "data", "payload": { "list_name": "{ $voted_version_name||"_voters" }", "add": "{ trigger.address }", "value": "{ !!trigger.data.like ? "+1" : "-1" }" } }, { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{trigger.address}", "amount": "{ trigger.output[[asset=base]]-1000 }" } ] } }, { "app": "state", "state": "{ // proceed voting if (trigger.data.like) var[$voted_version_name||"_likes"] += 1; if (trigger.data.dislike) var[$voted_version_name||"_dislikes"] += 1; // check if it became the most popular version $voted_version_score = var[$voted_version_name||"_likes"] - var[$voted_version_name||"_dislikes"]; $popular_version_score = var[$name||"_"||$popular_version_number||"_likes"] - var[$name||"_"||$popular_version_number||"_dislikes"]; if ($voted_version_score > $popular_version_score) var[$name||"_popular_version_number"] = $version_number; // add info in the unit as feedback response['message'] = "Your vote has been taken into account ^^ "; }" } ] }, { "messages": [ { "app": "state", "state": "{ bounce ($INSTRUCTIONS); }" } ] } ] } } ]
Technical information
Fees:
4,997 bytes
(353 headers, 4644 payload)
Level:1101470
Witnessed level:1101463
Main chain index:1100230
Latest included mc index:1100229
Status:stable/confirmed/final