[
"autonomous agent",
{
"bounce_fees": {
"base": 10000
},
"init": "{
// constants
$domain_creation_fee = 500000; // 500,000.0 bytes
$requesting_reputation_fee = 10000; // 10,000.0 bytes
$reward_pourcentage = 1; // 1% of the balance for an evalution of an attested address
$symbolic_reward= 10; // for evaluation of not attested address
$evaluation_delay = 2*24*60*60; // 1 days
$default_domain = 'base';
$default_attestor = '35IT3ZYKEPQSCXG2F7A7KWNRAD3SZXN4'; //'UOYYSPEE7UUW3KJAB5F4Y4AWMYMDDB4Y'; // official attestor
// variables directly from triggering transaction default
$user_address = trigger.address; // Attested user (if evaluator)
response['trigger.address'] = $user_address;
$evaluated_address = trigger.data.adress otherwise trigger.data.ad;
$domain = trigger.data.domain otherwise trigger.data.do otherwise $default_domain; // Evaluation domain
$evaluation = trigger.data.evaluation otherwise trigger.data.ev; // Evaluation: 0-5 or ?
$attestor = trigger.data.attestor otherwise trigger.data.at otherwise $default_attestor;
// deductions
$is_requesting = $evaluation == '?';
$is_contributing = (!$is_requesting)? $evaluation >= 0 and $evaluation <= 5 : false;
$attested_default_domain = $domain == $default_domain and $attestor == $default_attestor;
// Preliminary checks
if(!$is_requesting and !$is_contributing)
bounce('Sorry, You have to specify a \'evaluation\' field in the data section. Use \'0\' to \'5\' to evaluate an address or use \'?\' to request the reputation of an address.'); // (money - bounce fee) is return automatically
if(!$evaluated_address)
bounce('Sorry, You have to specify which address you want to find reputation for. Please add an \'address\' field in the data section.');
// hashing to avoid to store the reputation openely in the dag (euh why?)
$user_address_hash = sha256($user_address);
$evaluated_address_hash = sha256($evaluated_address);
$domain_hash = sha256($domain);
$attestor_hash = sha256($attestor);
$attested_domain = sha256($domain_hash and $attestor_hash);
$evaluation_hash = sha256($attested_domain and $evaluated_address_hash and $user_address_hash);
$reputation_hash = sha256(($attested_domain and $evaluated_address_hash) || 'reputation');
$evaluation_count_hash = sha256(($attested_domain and $evaluated_address_hash) || 'count');
// confuse attested address in the dag to avoid to gather information for free
// is it even possible ? $evaluated_address_confused = $evaluated_address(2);
// Attestation checks
$evaluated_is_attested = attestation[[attestors=$attestor, address=$evaluated_address, ifnone=0]];
$user_is_attested = attestation[[attestors=$attestor, address=$user_address, ifnone=0]];
// state variable checks
$attested_domain_exist = var[$attested_domain]otherwise false;
$balance_in_attestor_scope = var[$attestor_hash] otherwise 0;
$reputation = var[$reputation_hash] otherwise 0;
$eval_count = var[$evaluation_count_hash] otherwise 0;
response['new_evaluation_hash'] = $evaluation_hash;
response['old_evaluation_hash'] = var[$evaluation_hash];
$is_re_evaluation = var[$evaluation_hash] otherwise false; // this return false if the var doesn't exist
$previous_evaluation = var[$evaluation_hash] otherwise 0;
// Fee checks
$fee_received = trigger.output[[asset=base]].amount;
$creation_fee_received = $fee_received > $domain_creation_fee;
$requesting_fee_received = $fee_received > $requesting_reputation_fee;
}",
"messages": {
"cases": [
{
"if": "{$is_requesting}",
"init": "{
if (!$attested_domain_exist and !$attested_default_domain)
bounce('Sorry, You have requested reputation for a domain-attestor pair that do not exist.');
$reputationExists = $reputation;
if (!$reputationExists)
bounce('Sorry, the address (user) do not have reputation in this domain-attestor pair yet. Please consider to rate this user once you interacted with him/her.');
if (!$requesting_fee_received)
bounce('Sorry, The fee to request a reputation is '|| $requesting_reputation_fee || 'bytes');
// Respond
$reputation_to_show = round($reputation,1);
if ($evaluated_is_attested){
$message = 'Reputation for domain \''|| $domain ||'\' is '||$reputation_to_show||'/5 from '||$eval_count||' votes (and the address is attested by \''||$attestor_address||'\').';
}else{
$message = 'Reputation for domain \''|| $domain ||'\' is '||$reputation_to_show||'/5 from '||$eval_count||' votes BUT the address is NOT attested by \''||$attestor_address||'\')!';
}
response['message'] = $message;
response['domain'] = $domain;
response['attestor'] = $attestor;
response['reputation'] = $reputation_to_show;
response['attested'] = $evaluated_is_attested;
}",
"messages": [
{
"app": "data",
"payload": {
"message": "{$message}",
"reputation": "{$reputation}",
"is_attested": "{$evaluated_is_attested}"
}
},
{
"app": "state",
"state": "{
var[$attestor_hash] += trigger.output[[asset=base]].amount - 1000; // 1000 is the data transfert fee approximation?
}"
}
]
},
{
"if": "{$is_contributing}",
"init": "{
if (!$attested_domain_exist and !$creation_fee_received and !$attested_default_domain){
bounce('Sorry, the domain-attestor pair do not exists. It can be created but the fee is \''||$domain_creation_fee || '\' bytes, this money will be used to reward the evaluators');}
if (!$user_is_attested)
bounce('Sorry, to be able give an evaluation you need to be attested by the following attestor: \''|| $attestor || '\' or it will be too easy to pump a reputation.');
// calculating reward
$reward = $evaluated_is_attested?
round($balance_in_attestor_scope* $reward_pourcentage /100) :
$symbolic_reward;
// compute new reputation
$total_score=($reputation * $eval_count);
if ($is_re_evaluation){
$new_reputation = ($total_score + ($evaluation-$previous_evaluation) / ($eval_count));
$message_about_re_evaluation = 'Your evaluation was changed from '||$previous_evaluation||' to '||$evaluation||'. ';
$new_eval_count = $eval_count;
$message_about_number_of_eval = 'The number of votes is still '||$new_eval_count||'. ';
}
else{
$new_reputation = ($total_score + $evaluation) / ($eval_count+1);
$message_about_re_evaluation = '';
$new_eval_count = $eval_count+1;
$message_about_number_of_eval = 'There is now '||$new_eval_count||' votes. ';
}
// create message
$reputation_to_show = round($new_reputation,1);
if (!$attested_domain_exist)
$message_about_domain = 'The domain \''||$domain||'\' has been created in the scope of the attestor \''||$attestor||'\'. ';
else
$message_about_domain = '';
$message = $message_about_domain||'Thank you for your contribution, a reward of '||$reward||' byte have been sent to you ('||$user_address||'). The new reputation of '||$evaluated_address||' is '||$reputation_to_show||'/5. '|| $message_about_re_evaluation || $message_about_number_of_eval;
response['message'] = $message;
response['domain'] = $domain;
response['attestor'] = $attestor;
response['vote_from'] = $user_address;
if ($is_re_evaluation){
response['old_evaluation'] = $previous_evaluation;
response['new_evaluation'] = $evaluation;}
else
response['evaluation'] = $evaluation;
response['old_reputation'] = $reputation;
response['new_reputation'] = $new_reputation;
response['attested'] = $evaluated_is_attested;
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "{'base'}",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{$reward}"
}
]
}
},
{
"app": "state",
"state": "{
if (!$attested_domain_exist) var[$attested_domain]=$user_address_hash; // creating the var.
var[$evaluation_count_hash] = $new_eval_count;
var[$reputation_hash] = $new_reputation;
var[$evaluation_hash] = $evaluation; // last evaluation for later revote
var[$attestor_hash] = $evaluated_is_attested - $reward; // attestor balance
}"
}
]
}
]
}
}
]