| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | if (!$FOREVER_CONSTANT){ |
| 9 | $AA_in_debug_mode = false; |
| 10 | $is_test_mode = false; |
| 11 | $owner = 'SX66Y36BOU77S7MWML6JQQA3CJLX4COR'; |
| 12 | $domain_creation_fee = 500000; |
| 13 | $requesting_reputation_fee = 0; |
| 14 | $reward_pourcentage = 1; |
| 15 | $symbolic_reward= 10; |
| 16 | $evaluation_delay = 2*24*60*60*30; |
| 17 | $default_domain = 'base'; |
| 18 | $default_attestor = '35IT3ZYKEPQSCXG2F7A7KWNRAD3SZXN4'; |
| 19 | $mode_uwa = 'uwa'; $mode_twa = 'twa'; $mode_cbwa = 'cbwa'; $mode_crwa = 'crwa'; |
| 20 | $default_mode_of_average = $mode_uwa; |
| 21 | |
| 22 | $message_creation_howto ='set \'creation\' to ['||$mode_uwa||', '||$mode_twa||', '||$mode_cbwa||', '||$mode_crwa||']'; |
| 23 | } |
| 24 | |
| 25 | if (!$TRIGGER_INFO){ |
| 26 | |
| 27 | $user_address = trigger.address; |
| 28 | $requested_address = trigger.data.request otherwise trigger.data.re otherwise 'none'; |
| 29 | $evaluation_address = trigger.data.adress otherwise trigger.data.ad otherwise 'none'; |
| 30 | $domain = trigger.data.domain otherwise trigger.data.do otherwise $default_domain; |
| 31 | $attestor_address = trigger.data.attestor otherwise trigger.data.at otherwise $default_attestor; |
| 32 | $evaluation = trigger.data.evaluation otherwise trigger.data.ev otherwise -1; |
| 33 | $mode_of_average_for_creation = trigger.data.creation otherwise trigger.data.cr otherwise 'unknown'; |
| 34 | |
| 35 | if (($requested_address !='none') and ($evaluation_address!='none')) |
| 36 | bounce ("trigger.data.request and trigger.data.adress cannot be both set"); |
| 37 | |
| 38 | |
| 39 | $is_creating= ($mode_of_average_for_creation!='unknown')? true:false; |
| 40 | |
| 41 | if ($requested_address !='none'){ |
| 42 | $is_requesting=true; |
| 43 | $evaluated_address = $requested_address; |
| 44 | } |
| 45 | if ($evaluation_address !='none'){ |
| 46 | $is_contributing=true; |
| 47 | $evaluated_address = $evaluation_address; |
| 48 | } |
| 49 | |
| 50 | if ($AA_in_debug_mode){ |
| 51 | $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 ||'). '; |
| 52 | |
| 53 | response['TRIGGER_INFO'] = $TRIGGER_INFO; |
| 54 | } |
| 55 | } |
| 56 | if (!$HASHES){ |
| 57 | $user_address_hash = sha256($user_address); |
| 58 | $evaluated_address_hash = sha256($evaluated_address); |
| 59 | $domain_hash = sha256($domain); |
| 60 | $attestor_hash = sha256($attestor); |
| 61 | $attested_domain = sha256($domain_hash and $attestor_hash); |
| 62 | $evaluation_hash = sha256($attested_domain and $evaluated_address_hash and $user_address_hash); |
| 63 | $reputation_hash = sha256(($attested_domain and $evaluated_address_hash) || 'reputation'); |
| 64 | $evaluation_count_hash = sha256(($attested_domain and $evaluated_address_hash) || 'count'); |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | if ($AA_in_debug_mode){ |
| 70 | $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 ||'). '; |
| 71 | |
| 72 | response['HASHES'] = $HASHES; |
| 73 | } |
| 74 | } |
| 75 | if (!$INITIAL_DAG_STATE){ |
| 76 | $attested_domain_exist_in_dag = var['coad('||$attested_domain]; |
| 77 | $attested_domain_exist = ($attested_domain_exist_in_dag) ? true:false; |
| 78 | $balance_in_attestor_scope = var['bo('||$attestor_hash] otherwise 0; |
| 79 | $reputation = var['ro('||$reputation_hash] otherwise -1; |
| 80 | $eval_count = var['eco('||$evaluation_count_hash] otherwise 0; |
| 81 | $previous_evaluation = var['leo('||$evaluation_hash] otherwise -1; |
| 82 | $is_re_evaluation = ($previous_evaluation != -1); |
| 83 | $mode_of_average= var['moa('||$attested_domain] otherwise $default_mode_of_average; |
| 84 | |
| 85 | if ($AA_in_debug_mode){ |
| 86 | $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. '; |
| 87 | |
| 88 | response['INITIAL_DAG_STATE'] = $INITIAL_DAG_STATE; |
| 89 | } |
| 90 | |
| 91 | } |
| 92 | if (!$PRELIMINARY_CHECKS){ |
| 93 | |
| 94 | |
| 95 | $attested_default_domain = ($domain == $default_domain) and ($attestor_address == $default_attestor); |
| 96 | |
| 97 | |
| 98 | $fee_received = trigger.output[[asset=base]].amount; |
| 99 | $is_creation_fee_received = $fee_received > $domain_creation_fee; |
| 100 | $is_requesting_fee_received = $fee_received > $requesting_reputation_fee; |
| 101 | |
| 102 | if ($AA_in_debug_mode){ |
| 103 | $PRELIMINARY_CHECKS= 'Requesting mode is ('|| $is_requesting ||') contributing mode is('|| $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 ||'). '; |
| 104 | |
| 105 | response['PRELIMINARY_CHECKS'] = $PRELIMINARY_CHECKS; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | }", |
| 110 | "messages": { |
| 111 | "cases": [ |
| 112 | { |
| 113 | "if": "{$is_requesting}", |
| 114 | "init": "{ |
| 115 | |
| 116 | if (!$REQUESTING_CHECKS){ |
| 117 | if (!$attested_domain_exist and !$attested_default_domain) |
| 118 | bounce('Sorry, You have requested reputation for a domain-attestor pair that do not exist.'); |
| 119 | $reputationExists = ($reputation != -1); |
| 120 | if (!$reputationExists) |
| 121 | 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.'); |
| 122 | if (!$is_requesting_fee_received) |
| 123 | bounce('Sorry, The fee to request a reputation is '|| $requesting_reputation_fee || 'bytes'); |
| 124 | |
| 125 | if(!$evaluated_address) |
| 126 | bounce('Sorry, You have to specify which address you want to find reputation for. Please add an \'address\' field in the data section.'); |
| 127 | |
| 128 | |
| 129 | $evaluated_is_attested = attestation[[attestors=$attestor_address, address=$evaluated_address, ifnone=0]]; |
| 130 | |
| 131 | if ($AA_in_debug_mode){ |
| 132 | $REQUESTING_CHECKS = 'Seller attestation is ('|| $evaluated_is_attested ||'). '; |
| 133 | |
| 134 | response['REQUESTING_CHECKS'] = $REQUESTING_CHECKS; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | if (!$RETURNING_REPUTATION){ |
| 139 | |
| 140 | $reputation_to_show = round($reputation,1); |
| 141 | $message_about_reputation ='Reputation for domain \''|| $domain ||'\' is '||$reputation_to_show||'/5 from ' || $eval_count || ' votes. '; |
| 142 | if ($evaluated_is_attested) |
| 143 | $message_about_attestation = 'and the address is attested by \''||$attestor_address||'\'). '; |
| 144 | else |
| 145 | $message_about_attestation = 'BUT the address is NOT attested by \''||$attestor_address||'\')! '; |
| 146 | |
| 147 | response['message'] = $message_about_reputation || $message_about_attestation; |
| 148 | response['domain'] = $domain; |
| 149 | response['attestor'] = $attestor_address; |
| 150 | response['reputation'] = $reputation_to_show; |
| 151 | response['evaluation_count'] = $eval_count; |
| 152 | response['attested'] = $evaluated_is_attested; |
| 153 | |
| 154 | if ($AA_in_debug_mode){ |
| 155 | $RETURNING_REPUTATION = $message_about_reputation || $message_about_attestation; |
| 156 | |
| 157 | response['RETURNING_REPUTATION'] = $RETURNING_REPUTATION; |
| 158 | } |
| 159 | } |
| 160 | }", |
| 161 | "messages": [ |
| 162 | { |
| 163 | "app": "data", |
| 164 | "payload": { |
| 165 | "message": "{$message}", |
| 166 | "domain": "{$domain}", |
| 167 | "attestor": "{$attestor_address}", |
| 168 | "reputation": "{$reputation}", |
| 169 | "evaluation_count": "{$evaluation_count}", |
| 170 | "attested": "{$attested}" |
| 171 | } |
| 172 | }, |
| 173 | { |
| 174 | "app": "state", |
| 175 | "state": "{ |
| 176 | |
| 177 | if (!$FINAL_DAG_STATE){ |
| 178 | $saved_fee = trigger.output[[asset=base]].amount - 1000; |
| 179 | var['bo('||$attestor_hash] += $saved_fee; |
| 180 | |
| 181 | if ($AA_in_debug_mode){ |
| 182 | $FINAL_DAG_STATE = 'After the requesting, the new balance for this attestor scope is('|| var['bo('||$attestor_hash] ||') bytes, it added ('|| $saved_fee ||') bytes. '; |
| 183 | |
| 184 | response['FINAL_DAG_STATE'] = $FINAL_DAG_STATE; |
| 185 | } |
| 186 | } |
| 187 | }" |
| 188 | } |
| 189 | ] |
| 190 | }, |
| 191 | { |
| 192 | "if": "{$is_creating}", |
| 193 | "init": "{ |
| 194 | |
| 195 | if (!$DOMAIN_CREATION){ |
| 196 | |
| 197 | |
| 198 | if ($attested_domain_exist) |
| 199 | bounce('Sorry, The domain \''||$domain||'\' in the scope of the attestor \''||$attestor_address||'\' already exist. '); |
| 200 | |
| 201 | |
| 202 | $message_about_creation_requirements = 'In creation mode you should have '||$message_creation_howto||' and you should not specify any \'evaluation\'. '; |
| 203 | |
| 204 | |
| 205 | if($is_requesting or $is_contributing) |
| 206 | bounce('Sorry, '|| $message_about_creation_requirements); |
| 207 | |
| 208 | |
| 209 | $moa = $mode_of_average_for_creation; |
| 210 | if(($moa != $mode_uwa) and ($moa != $mode_twa) and ($moa != $mode_cbwa) and ($moa != $mode_crwa)) |
| 211 | bounce('Sorry, '|| $message_about_creation_requirements); |
| 212 | |
| 213 | $ok_to_create_domain=true; |
| 214 | $message_about_creation = 'The domain \''||$domain||'\' has been created in the scope of the attestor \''||$attestor_address||'\' with the average mode \''||$mode_of_average_for_creation||'\'. '; |
| 215 | |
| 216 | response['message'] = $message_about_creation; |
| 217 | |
| 218 | if ($AA_in_debug_mode){ |
| 219 | $DOMAIN_CREATION = $message_about_creation; |
| 220 | |
| 221 | response['DOMAIN_CREATION'] = $DOMAIN_CREATION; |
| 222 | } |
| 223 | } |
| 224 | }", |
| 225 | "messages": [ |
| 226 | { |
| 227 | "app": "data", |
| 228 | "payload": { |
| 229 | "domain": "{$domain}", |
| 230 | "attestor": "{$attestor_address}" |
| 231 | } |
| 232 | }, |
| 233 | { |
| 234 | "app": "state", |
| 235 | "state": "{ |
| 236 | |
| 237 | if (!$FINAL_DAG_STATE){ |
| 238 | |
| 239 | $saved_fee = trigger.output[[asset=base]].amount - 1000; |
| 240 | |
| 241 | var['coad('||$attested_domain]=$user_address_hash; |
| 242 | var['moa('||$attested_domain]=$mode_of_average_for_creation; |
| 243 | |
| 244 | var['bo('||$attestor_hash] += $saved_fee; |
| 245 | |
| 246 | if ($AA_in_debug_mode){ |
| 247 | $FINAL_DAG_STATE = 'After creation of the new, domain the new balance for this attestor scope is('|| var['bo('||$attestor_hash] ||') bytes, it added ('|| $saved_fee ||') bytes. '; |
| 248 | |
| 249 | response['FINAL_DAG_STATE'] = $FINAL_DAG_STATE; |
| 250 | } |
| 251 | } |
| 252 | }" |
| 253 | } |
| 254 | ] |
| 255 | }, |
| 256 | { |
| 257 | "if": "{$is_contributing}", |
| 258 | "init": "{ |
| 259 | |
| 260 | if (!$CONTRIBUTION_CHECKING){ |
| 261 | |
| 262 | if ($evaluation < 0 or $evaluation > 5) |
| 263 | bounce('Sorry, data.evaluation should be set between 0 and 5 if you want to vote'); |
| 264 | |
| 265 | if(!$evaluated_address) |
| 266 | bounce('Sorry, You have to specify which address you want to find reputation for. Please add an \'address\' field in the data section.'); |
| 267 | |
| 268 | if($evaluated_address==$user_address) |
| 269 | bounce('Sorry, You cannot vote for yourself'); |
| 270 | |
| 271 | if (!$attested_domain_exist and !$attested_default_domain) |
| 272 | bounce('Sorry, the domain-attestor pair do not exists. It can be created if you ' || $message_creation_howto || ' but the fee is \''||$domain_creation_fee || '\' bytes, this money will be used to reward the evaluators. '|| $PRELIMINARY_CHECKS); |
| 273 | |
| 274 | $user_is_attested = attestation[[attestors=$attestor_address, address=$user_address, ifnone=0]]; |
| 275 | |
| 276 | if (!$user_is_attested) |
| 277 | { |
| 278 | if(!$is_test_mode) |
| 279 | 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.'); |
| 280 | if($is_test_mode) |
| 281 | $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. '; |
| 282 | else |
| 283 | $message_about_testing =''; |
| 284 | } |
| 285 | else |
| 286 | $message_about_testing =''; |
| 287 | |
| 288 | if ($AA_in_debug_mode){ |
| 289 | $CONTRIBUTION_CHECKING = $message_about_testing; |
| 290 | |
| 291 | response['CONTRIBUTION_CHECKING'] = $CONTRIBUTION_CHECKING; |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | if (!$REWARD_COMPUTATION){ |
| 296 | if ($user_is_attested){ |
| 297 | $reward = round($balance_in_attestor_scope* $reward_pourcentage /100); |
| 298 | $message_about_the_reward = 'The reward is '||$reward_pourcentage||'% of the attested scope which is '|| $balance_in_attestor_scope ||" bytes. "; |
| 299 | } |
| 300 | else{ |
| 301 | $reward = $symbolic_reward; |
| 302 | $message_about_the_reward = 'The reward is symbolic because you are not attested by '|| $attestor_address||'. '; |
| 303 | } |
| 304 | |
| 305 | if ($AA_in_debug_mode){ |
| 306 | $REWARD_COMPUTATION = 'The reward will be ('|| $reward ||'). '|| $message_about_the_reward ||'. '; |
| 307 | |
| 308 | response['REWARD_COMPUTATION'] = $REWARD_COMPUTATION; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | if (!$REPUTATION_COMPUTATION){ |
| 313 | $reputation_corrected = ($reputation == -1)? 0: $reputation; |
| 314 | |
| 315 | if ($mode_of_average) { |
| 316 | $total_score=($reputation * $eval_count); |
| 317 | |
| 318 | if ($is_re_evaluation){ |
| 319 | $new_reputation = ($total_score + ($evaluation-$previous_evaluation) / ($eval_count)); |
| 320 | $message_about_re_evaluation = 'Your evaluation was changed from '||$previous_evaluation||' to '||$evaluation||'. '; |
| 321 | $new_eval_count = $eval_count; |
| 322 | $message_about_number_of_eval = 'The number of votes for this address is still '||$new_eval_count||'. '; |
| 323 | } |
| 324 | else{ |
| 325 | $new_reputation = ($total_score + $evaluation) / ($eval_count+1); |
| 326 | $message_about_re_evaluation = ''; |
| 327 | $new_eval_count = $eval_count+1; |
| 328 | $message_about_number_of_eval = '('||$new_eval_count||' votes attested for this address. '; |
| 329 | } |
| 330 | } |
| 331 | $reputation_to_show = round($new_reputation,1); |
| 332 | |
| 333 | if ($AA_in_debug_mode){ |
| 334 | $REPUTATION_COMPUTATION = 'the new reputation is ('|| $new_reputation ||'('|| $reputation_to_show ||')). '; |
| 335 | |
| 336 | response['REPUTATION_COMPUTATION'] = $REPUTATION_COMPUTATION; |
| 337 | } |
| 338 | |
| 339 | } |
| 340 | |
| 341 | if (!$RESPONSE_CREATION){ |
| 342 | |
| 343 | |
| 344 | $message = $message_about_testing ||'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; |
| 345 | |
| 346 | response['message'] = $message; |
| 347 | response['domain'] = $domain; |
| 348 | response['attestor'] = $attestor_address; |
| 349 | response['vote_from'] = $user_address; |
| 350 | if ($is_re_evaluation) |
| 351 | { |
| 352 | response['old_evaluation'] = $previous_evaluation; |
| 353 | response['new_evaluation'] = $evaluation; |
| 354 | } |
| 355 | else |
| 356 | response['evaluation'] = $evaluation; |
| 357 | response['old_reputation'] = $reputation; |
| 358 | response['new_reputation'] = $new_reputation; |
| 359 | response['attested'] = $evaluated_is_attested; |
| 360 | |
| 361 | if ($AA_in_debug_mode){ |
| 362 | $RESPONSE_CREATION = 'The message to the user will be ('|| $message ||'). '; |
| 363 | |
| 364 | response['RESPONSE_CREATION'] = $RESPONSE_CREATION; |
| 365 | } |
| 366 | } |
| 367 | }", |
| 368 | "messages": [ |
| 369 | { |
| 370 | "app": "payment", |
| 371 | "payload": { |
| 372 | "asset": "{'base'}", |
| 373 | "outputs": [ |
| 374 | { |
| 375 | "address": "{trigger.address}", |
| 376 | "amount": "{$reward}" |
| 377 | } |
| 378 | ] |
| 379 | } |
| 380 | }, |
| 381 | { |
| 382 | "app": "state", |
| 383 | "state": "{ |
| 384 | |
| 385 | if (!$FINAL_DAG_STATE){ |
| 386 | |
| 387 | var['ro('||$reputation_hash] = $new_reputation; |
| 388 | var['eco('||$evaluation_count_hash] = $new_eval_count; |
| 389 | var['leo('||$evaluation_hash] = $evaluation; |
| 390 | var['bo('||$attestor_hash] = $balance_in_attestor_scope - $reward; |
| 391 | |
| 392 | if ($AA_in_debug_mode){ |
| 393 | $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] ||'). '; |
| 394 | |
| 395 | response['FINAL_DAG_STATE'] = $FINAL_DAG_STATE; |
| 396 | } |
| 397 | |
| 398 | } |
| 399 | }" |
| 400 | } |
| 401 | ] |
| 402 | } |
| 403 | ] |
| 404 | } |
| 405 | } |
| 406 | ] |