| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | if (!$FOREVER_CONSTANT){ |
| 9 | $AA_in_debug_mode = true; |
| 10 | $owner = 'MYESSCFGDERS3YIEGNZDOG2BI5HKQHLU'; |
| 11 | $domain_creation_fee = 500000; |
| 12 | $requesting_reputation_fee = 0; |
| 13 | $reward_pourcentage = 1; |
| 14 | $symbolic_reward= 10; |
| 15 | $evaluation_delay = 2*24*60*60; |
| 16 | |
| 17 | $default_domain = 'base'; |
| 18 | $default_attestor = '35IT3ZYKEPQSCXG2F7A7KWNRAD3SZXN4'; |
| 19 | } |
| 20 | if (!$TRIGGER_INFO){ |
| 21 | $user_address = trigger.address; |
| 22 | $evaluated_address = trigger.data.adress otherwise trigger.data.ad; |
| 23 | $domain = trigger.data.domain otherwise trigger.data.do otherwise $default_domain; |
| 24 | $attestor_address = trigger.data.attestor otherwise trigger.data.at otherwise $default_attestor; |
| 25 | $evaluation = trigger.data.evaluation otherwise trigger.data.ev; |
| 26 | $input_is_test_mode = trigger.data.testmode otherwise trigger.data.tm otherwise false; |
| 27 | |
| 28 | if ($AA_in_debug_mode){ |
| 29 | $TRIGGER_INFO = 'At the begining there was a user ('||$user_address||') interested in a seller('|| $evaluated_address ||') in a given domain ('|| $domain ||') in the scope of an attestor ('|| $attestor_address ||'), the evaluation is set to ('|| $evaluation ||'), the user could try to initial the test mode ('|| $input_is_test_mode ||'). '; |
| 30 | |
| 31 | response['TRIGGER_INFO'] = $TRIGGER_INFO; |
| 32 | } |
| 33 | } |
| 34 | if (!$HASHES){ |
| 35 | $user_address_hash = sha256($user_address); |
| 36 | $evaluated_address_hash = sha256($evaluated_address); |
| 37 | $domain_hash = sha256($domain); |
| 38 | $attestor_hash = sha256($attestor); |
| 39 | $attested_domain = sha256($domain_hash and $attestor_hash); |
| 40 | $evaluation_hash = sha256($attested_domain and $evaluated_address_hash and $user_address_hash); |
| 41 | $reputation_hash = sha256(($attested_domain and $evaluated_address_hash) || 'reputation'); |
| 42 | $evaluation_count_hash = sha256(($attested_domain and $evaluated_address_hash) || 'count'); |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | if ($AA_in_debug_mode){ |
| 48 | $HASHES= 'user hash is ('|| $user_address_hash ||') seller ('|| $evaluated_address_hash ||') domain ('|| $domain_hash ||') attestor ('|| $attestor_hash ||') attested_domain ('|| $attested_domain ||'). The evaluation hash for the AD and this pair of user is ('|| $evaluation_hash ||') seller reputation hash is ('|| $reputation_hash ||') number of evaluation for this seller hash is ('|| $evaluation_count_hash ||'). '; |
| 49 | |
| 50 | response['HASHES'] = $HASHES; |
| 51 | } |
| 52 | } |
| 53 | if (!$INITIAL_DAG_STATE){ |
| 54 | $state_var_is_test_mode = var['is_test_mode']; |
| 55 | $attested_domain_exist_in_dag = var['coad('||$attested_domain]; |
| 56 | $attested_domain_exist = ($attested_domain_exist_in_dag) ? true:false; |
| 57 | $balance_in_attestor_scope = var['bo('||$attestor_hash] otherwise 0; |
| 58 | $reputation = var['ro('||$reputation_hash] otherwise -1; |
| 59 | $eval_count = var['eco('||$evaluation_count_hash] otherwise 0; |
| 60 | $previous_evaluation = var['leo('||$evaluation_hash] otherwise -1; |
| 61 | $is_re_evaluation = ($previous_evaluation != -1); |
| 62 | |
| 63 | if ($AA_in_debug_mode){ |
| 64 | $INITIAL_DAG_STATE = 'Is test mode activated to allow unattested user to vote? ('|| $state_var_is_test_mode || '). It is ('|| $attested_domain_exist || '(' || var['coad('||$attested_domain] ||')) that the attested domain exist. The balance for this attestor scope is ('|| $balance_in_attestor_scope || '(' || var['bo('||$attestor_hash] || ')). The reputation of the seller is ('|| $reputation || '(' || var['ro('||$reputation_hash] || ')) with ('|| $eval_count|| '(' || var['eco('||$evaluation_count_hash] ||')) votes. The previous evaluation of the seller from this user is ('|| $previous_evaluation|| '(' || var['le(=)'||$evaluation_hash] ||')) so it is ('|| $is_re_evaluation || ') to says that it is a re-evaluation. '; |
| 65 | |
| 66 | response['INITIAL_DAG_STATE'] = $INITIAL_DAG_STATE; |
| 67 | } |
| 68 | |
| 69 | } |
| 70 | if (!$PRELIMINARY_CHECKS){ |
| 71 | |
| 72 | |
| 73 | if ($user_address==$owner) |
| 74 | $is_test_mode = $input_is_test_mode otherwise $state_var_is_test_mode otherwise false; |
| 75 | else |
| 76 | $is_test_mode = var['is_test_mode'] otherwise false; |
| 77 | |
| 78 | |
| 79 | $is_requesting = $evaluation == '?'; |
| 80 | $is_contributing = (!$is_requesting)? $evaluation >= 0 and $evaluation <= 5 : false; |
| 81 | |
| 82 | |
| 83 | $attested_default_domain = ($domain == $default_domain) and ($attestor_address == $default_attestor); |
| 84 | |
| 85 | |
| 86 | if(!$is_requesting and !$is_contributing) |
| 87 | 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.'); |
| 88 | if(!$evaluated_address) |
| 89 | bounce('Sorry, You have to specify which address you want to find reputation for. Please add an \'address\' field in the data section.'); |
| 90 | |
| 91 | |
| 92 | $fee_received = trigger.output[[asset=base]].amount; |
| 93 | $is_creation_fee_received = $fee_received > $domain_creation_fee; |
| 94 | $is_requesting_fee_received = $fee_received > $requesting_reputation_fee; |
| 95 | |
| 96 | if ($AA_in_debug_mode){ |
| 97 | $PRELIMINARY_CHECKS= 'The test mode is set to ('|| $is_test_mode ||') requesting mode to ('|| $is_requesting ||') contributing mode to ('|| $is_contributing ||') this is ('|| $attested_default_domain ||') to say that we will work with the default attested domain. The fee received is ('|| $fee_received ||') ok for creation? ('|| $is_creation_fee_received ||') ok for requesting a reputation? ('|| $is_requesting_fee_received ||'). '; |
| 98 | |
| 99 | response['PRELIMINARY_CHECKS'] = $PRELIMINARY_CHECKS; |
| 100 | } |
| 101 | } |
| 102 | if (!$ATTESTATIONS){ |
| 103 | $evaluated_is_attested = attestation[[attestors=$attestor_address, address=$evaluated_address, ifnone=0]]; |
| 104 | $user_is_attested = attestation[[attestors=$attestor_address, address=$user_address, ifnone=0]]; |
| 105 | |
| 106 | if ($AA_in_debug_mode){ |
| 107 | $ATTESTATIONS = 'User attestation is ('|| $user_is_attested ||') and seller attestation is ('|| $evaluated_is_attested ||'). '; |
| 108 | |
| 109 | response['ATTESTATIONS'] = $ATTESTATIONS; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | }", |
| 114 | "messages": { |
| 115 | "cases": [ |
| 116 | { |
| 117 | "if": "{$is_requesting}", |
| 118 | "init": "{ |
| 119 | |
| 120 | if (!$REQUESTING_CHECKS){ |
| 121 | if (!$attested_domain_exist and !$attested_default_domain) |
| 122 | bounce('Sorry, You have requested reputation for a domain-attestor pair that do not exist.'); |
| 123 | $reputationExists = ($reputation != -1); |
| 124 | if (!$reputationExists) |
| 125 | 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.'); |
| 126 | if (!$is_requesting_fee_received) |
| 127 | bounce('Sorry, The fee to request a reputation is '|| $requesting_reputation_fee || 'bytes'); |
| 128 | |
| 129 | if ($AA_in_debug_mode){ |
| 130 | $REQUESTING_CHECKS = 'User attestation is ('|| $user_is_attested ||') and seller attestation is ('|| $evaluated_is_attested ||'). '; |
| 131 | |
| 132 | response['REQUESTING_CHECKS'] = $REQUESTING_CHECKS; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | if (!$RETURNING_REPUTATION){ |
| 137 | |
| 138 | $reputation_to_show = round($reputation,1); |
| 139 | $message_about_reputation ='Reputation for domain \''|| $domain ||'\' is '||$reputation_to_show||'/5 from ' || $eval_count || 'votes. '; |
| 140 | if ($evaluated_is_attested) |
| 141 | $message_about_attestation = 'and the address is attested by \''||$attestor_address||'\'). '; |
| 142 | else |
| 143 | $message_about_attestation = 'BUT the address is NOT attested by \''||$attestor_address||'\')! '; |
| 144 | |
| 145 | response['message'] = $message_about_reputation || $message_about_attestation; |
| 146 | response['domain'] = $domain; |
| 147 | response['attestor'] = $attestor_address; |
| 148 | response['reputation'] = $reputation_to_show; |
| 149 | response['evaluation_count'] = $eval_count; |
| 150 | response['attested'] = $evaluated_is_attested; |
| 151 | |
| 152 | if ($AA_in_debug_mode){ |
| 153 | $RETURNING_REPUTATION = $message_about_reputation || $message_about_attestation; |
| 154 | |
| 155 | response['RETURNING_REPUTATION'] = $RETURNING_REPUTATION; |
| 156 | } |
| 157 | } |
| 158 | }", |
| 159 | "messages": [ |
| 160 | { |
| 161 | "app": "data", |
| 162 | "payload": { |
| 163 | "message": "{$message}", |
| 164 | "domain": "{$domain}", |
| 165 | "attestor": "{$attestor_address}", |
| 166 | "reputation": "{$reputation}", |
| 167 | "evaluation_count": "{$evaluation_count}", |
| 168 | "attested": "{$attested}" |
| 169 | } |
| 170 | }, |
| 171 | { |
| 172 | "app": "state", |
| 173 | "state": "{ |
| 174 | |
| 175 | if (!$FINAL_DAG_STATE){ |
| 176 | $saved_fee = trigger.output[[asset=base]].amount - 1000; |
| 177 | var['bo('||$attestor_hash] += $saved_fee; |
| 178 | var['is_test_mode'] = $is_test_mode; |
| 179 | |
| 180 | if ($AA_in_debug_mode){ |
| 181 | $FINAL_DAG_STATE = 'After the requesting, the new balance for this attestor scope is('|| var['bo('||$attestor_hash] ||') bytes, it added ('|| $saved_fee ||') bytes. The test mode will be activated? ('|| $is_test_mode ||'). '; |
| 182 | |
| 183 | response['FINAL_DAG_STATE'] = $FINAL_DAG_STATE; |
| 184 | } |
| 185 | } |
| 186 | }" |
| 187 | } |
| 188 | ] |
| 189 | }, |
| 190 | { |
| 191 | "if": "{$is_contributing}", |
| 192 | "init": "{ |
| 193 | |
| 194 | if (!$CONTRIBUTION_CHECKING){ |
| 195 | |
| 196 | if (!$attested_domain_exist and !$is_creation_fee_received and !$attested_default_domain){ |
| 197 | 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');} |
| 198 | |
| 199 | if (!$user_is_attested) |
| 200 | { |
| 201 | if(!$is_test_mode) |
| 202 | bounce('Sorry, to be able to give an evaluation you need to be attested by the following attestor: \''|| $attestor_address || '\' or it will be too easy to pump a reputation.'); |
| 203 | if($is_test_mode) |
| 204 | $message_about_testing ='Normally, a user not attested by the attestor linked to a domain should not be able to vote, but as you are in test mode you will be able to vote. '; |
| 205 | else |
| 206 | $message_about_testing =''; |
| 207 | } |
| 208 | |
| 209 | if ($AA_in_debug_mode){ |
| 210 | $CONTRIBUTION_CHECKING = $message_about_testing; |
| 211 | |
| 212 | response['CONTRIBUTION_CHECKING'] = $CONTRIBUTION_CHECKING; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | if (!$REWARD_COMPUTATION){ |
| 217 | if ($evaluated_is_attested){ |
| 218 | $reward = round($balance_in_attestor_scope* $reward_pourcentage /100); |
| 219 | $message_about_the_reward = 'The reward is '||$reward_pourcentage||'% of the attested scope which is '|| $balance_in_attestor_scope ||" bytes. "; |
| 220 | } |
| 221 | else{ |
| 222 | $reward = $symbolic_reward; |
| 223 | $message_about_the_reward = 'The reward is symbolic because you are not attested by '|| $attestor_address||'. '; |
| 224 | } |
| 225 | |
| 226 | if ($AA_in_debug_mode){ |
| 227 | $REWARD_COMPUTATION = 'The reward will be ('|| $reward ||'). '|| $message_about_the_reward ||'. '; |
| 228 | |
| 229 | response['REWARD_COMPUTATION'] = $REWARD_COMPUTATION; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | if (!$REPUTATION_COMPUTATION){ |
| 234 | $reputation_corrected = ($reputation == -1)? 0: $reputation; |
| 235 | |
| 236 | $total_score=($reputation * $eval_count); |
| 237 | |
| 238 | if ($is_re_evaluation){ |
| 239 | $new_reputation = ($total_score + ($evaluation-$previous_evaluation) / ($eval_count)); |
| 240 | $message_about_re_evaluation = 'Your evaluation was changed from '||$previous_evaluation||' to '||$evaluation||'. '; |
| 241 | $new_eval_count = $eval_count; |
| 242 | $message_about_number_of_eval = 'The number of votes for this address is still '||$new_eval_count||'. '; |
| 243 | } |
| 244 | else{ |
| 245 | $new_reputation = ($total_score + $evaluation) / ($eval_count+1); |
| 246 | $message_about_re_evaluation = ''; |
| 247 | $new_eval_count = $eval_count+1; |
| 248 | $message_about_number_of_eval = '('||$new_eval_count||' votes attested for this address. '; |
| 249 | } |
| 250 | $reputation_to_show = round($new_reputation,1); |
| 251 | |
| 252 | if ($AA_in_debug_mode){ |
| 253 | $REPUTATION_COMPUTATION = 'the new reputation is ('|| $new_reputation ||'('|| $reputation_to_show ||')). '; |
| 254 | |
| 255 | response['REPUTATION_COMPUTATION'] = $REPUTATION_COMPUTATION; |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | if (!$RESPONSE_CREATION){ |
| 260 | |
| 261 | if (!$attested_domain_exist) |
| 262 | $message_about_domain = 'The domain \''||$domain||'\' has been created in the scope of the attestor \''||$attestor_address||'\'. '; |
| 263 | else |
| 264 | $message_about_domain = ''; |
| 265 | |
| 266 | $message = $message_about_testing||$message_about_domain||'Thank you for your contribution, a reward of '||$reward||' byte have been sent to you ('||$user_address||'). '|| $message_about_the_reward || 'The new reputation of '||$evaluated_address||' is now ('||$reputation_to_show||'/5). '|| $message_about_re_evaluation || $message_about_number_of_eval; |
| 267 | |
| 268 | response['message'] = $message; |
| 269 | response['domain'] = $domain; |
| 270 | response['attestor'] = $attestor_address; |
| 271 | response['vote_from'] = $user_address; |
| 272 | if ($is_re_evaluation) |
| 273 | { |
| 274 | response['old_evaluation'] = $previous_evaluation; |
| 275 | response['new_evaluation'] = $evaluation; |
| 276 | } |
| 277 | else |
| 278 | response['evaluation'] = $evaluation; |
| 279 | response['old_reputation'] = $reputation; |
| 280 | response['new_reputation'] = $new_reputation; |
| 281 | response['attested'] = $evaluated_is_attested; |
| 282 | |
| 283 | if ($AA_in_debug_mode){ |
| 284 | $RESPONSE_CREATION = 'The message to the user will be ('|| $message ||'). '; |
| 285 | |
| 286 | response['RESPONSE_CREATION'] = $RESPONSE_CREATION; |
| 287 | } |
| 288 | } |
| 289 | }", |
| 290 | "messages": [ |
| 291 | { |
| 292 | "app": "payment", |
| 293 | "payload": { |
| 294 | "asset": "{'base'}", |
| 295 | "outputs": [ |
| 296 | { |
| 297 | "address": "{trigger.address}", |
| 298 | "amount": "{$reward}" |
| 299 | } |
| 300 | ] |
| 301 | } |
| 302 | }, |
| 303 | { |
| 304 | "app": "state", |
| 305 | "state": "{ |
| 306 | |
| 307 | if (!$FINAL_DAG_STATE){ |
| 308 | |
| 309 | if (!$attested_domain_exist) |
| 310 | var['coad('||$attested_domain]=$user_address_hash; |
| 311 | |
| 312 | var['ro('||$reputation_hash] = $new_reputation; |
| 313 | var['eco('||$evaluation_count_hash] = $new_eval_count; |
| 314 | var['leo('||$evaluation_hash] = $evaluation; |
| 315 | var['bo('||$attestor_hash] = $balance_in_attestor_scope - $reward; |
| 316 | var['is_test_mode'] = $is_test_mode; |
| 317 | |
| 318 | if ($AA_in_debug_mode){ |
| 319 | $FINAL_DAG_STATE = 'Finally the state of the DAG is: the new reputation of the seller is ('|| $new_reputation ||') with a number of vote of ('|| $new_eval_count ||'), the last evaluation saved from this user will be ('|| $evaluation ||'). The new balance available in the scope is ('|| var['bo('||$attestor_hash] ||'). The test mode will be activated? ('|| $is_test_mode ||'). '; |
| 320 | |
| 321 | response['FINAL_DAG_STATE'] = $FINAL_DAG_STATE; |
| 322 | } |
| 323 | |
| 324 | } |
| 325 | }" |
| 326 | } |
| 327 | ] |
| 328 | } |
| 329 | ] |
| 330 | } |
| 331 | } |
| 332 | ] |