| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | |
| 9 | $owner = 'MYESSCFGDERS3YIEGNZDOG2BI5HKQHLU'; |
| 10 | $domain_creation_fee = 500000; |
| 11 | $requesting_reputation_fee = 10000; |
| 12 | $reward_pourcentage = 1; |
| 13 | $symbolic_reward= 10; |
| 14 | $evaluation_delay = 2*24*60*60; |
| 15 | |
| 16 | $default_domain = 'base'; |
| 17 | $default_attestor = '35IT3ZYKEPQSCXG2F7A7KWNRAD3SZXN4'; |
| 18 | |
| 19 | |
| 20 | $user_address = trigger.address; |
| 21 | $evaluated_address = trigger.data.adress otherwise trigger.data.ad; |
| 22 | $domain = trigger.data.domain otherwise trigger.data.do otherwise $default_domain; |
| 23 | $evaluation = trigger.data.evaluation otherwise trigger.data.ev; |
| 24 | $attestor = trigger.data.attestor otherwise trigger.data.at otherwise $default_attestor; |
| 25 | $input_is_test_mode = trigger.data.testmode otherwise trigger.data.tm otherwise false; |
| 26 | |
| 27 | |
| 28 | if ($user_address==$owner) |
| 29 | $is_test_mode = $input_is_test_mode otherwise var['is_test_mode'] otherwise false; |
| 30 | else |
| 31 | $is_test_mode = var['is_test_mode'] otherwise false; |
| 32 | |
| 33 | |
| 34 | $is_requesting = $evaluation == '?'; |
| 35 | $is_contributing = (!$is_requesting)? $evaluation >= 0 and $evaluation <= 5 : false; |
| 36 | $attested_default_domain = $domain == $default_domain and $attestor == $default_attestor; |
| 37 | |
| 38 | |
| 39 | if(!$is_requesting and !$is_contributing) |
| 40 | 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.'); |
| 41 | if(!$evaluated_address) |
| 42 | bounce('Sorry, You have to specify which address you want to find reputation for. Please add an \'address\' field in the data section.'); |
| 43 | |
| 44 | |
| 45 | $user_address_hash = sha256($user_address); |
| 46 | $evaluated_address_hash = sha256($evaluated_address); |
| 47 | $domain_hash = sha256($domain); |
| 48 | $attestor_hash = sha256($attestor); |
| 49 | $attested_domain = sha256($domain_hash and $attestor_hash); |
| 50 | $evaluation_hash = sha256($attested_domain and $evaluated_address_hash and $user_address_hash); |
| 51 | $reputation_hash = sha256(($attested_domain and $evaluated_address_hash) || 'reputation'); |
| 52 | $evaluation_count_hash = sha256(($attested_domain and $evaluated_address_hash) || 'count'); |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | $evaluated_is_attested = attestation[[attestors=$attestor, address=$evaluated_address, ifnone=0]]; |
| 59 | $user_is_attested = attestation[[attestors=$attestor, address=$user_address, ifnone=0]]; |
| 60 | |
| 61 | |
| 62 | $attested_domain_exist = var['coad('||$attested_domain] otherwise false; |
| 63 | $balance_in_attestor_scope = var['bo('||$attestor_hash] otherwise 0; |
| 64 | $reputation = var['ro('||$reputation_hash] otherwise 0; |
| 65 | $eval_count = var['eco('||$evaluation_count_hash] otherwise 0; |
| 66 | $is_re_evaluation = var['leo('||$evaluation_hash] otherwise false; |
| 67 | $previous_evaluation = var['le(=)'||$evaluation_hash] otherwise 0; |
| 68 | |
| 69 | |
| 70 | $fee_received = trigger.output[[asset=base]].amount; |
| 71 | $is_creation_fee_received = $fee_received > $domain_creation_fee; |
| 72 | $is_requesting_fee_received = $fee_received > $requesting_reputation_fee; |
| 73 | }", |
| 74 | "messages": { |
| 75 | "cases": [ |
| 76 | { |
| 77 | "if": "{$is_requesting}", |
| 78 | "init": "{ |
| 79 | if (!$attested_domain_exist and !$attested_default_domain) |
| 80 | bounce('Sorry, You have requested reputation for a domain-attestor pair that do not exist.'); |
| 81 | $reputationExists = $reputation; |
| 82 | if (!$reputationExists) |
| 83 | 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.'); |
| 84 | if (!$is_requesting_fee_received) |
| 85 | bounce('Sorry, The fee to request a reputation is '|| $requesting_reputation_fee || 'bytes'); |
| 86 | |
| 87 | |
| 88 | $reputation_to_show = round($reputation,1); |
| 89 | if ($evaluated_is_attested){ |
| 90 | $message = 'Reputation for domain \''|| $domain ||'\' is '||$reputation_to_show||'/5 from '||$eval_count||' votes (and the address is attested by \''||$attestor_address||'\').'; |
| 91 | }else{ |
| 92 | $message = 'Reputation for domain \''|| $domain ||'\' is '||$reputation_to_show||'/5 from '||$eval_count||' votes BUT the address is NOT attested by \''||$attestor_address||'\')!'; |
| 93 | } |
| 94 | response['message'] = $message; |
| 95 | response['domain'] = $domain; |
| 96 | response['attestor'] = $attestor; |
| 97 | response['reputation'] = $reputation_to_show; |
| 98 | response['attested'] = $evaluated_is_attested; |
| 99 | }", |
| 100 | "messages": [ |
| 101 | { |
| 102 | "app": "data", |
| 103 | "payload": { |
| 104 | "message": "{$message}", |
| 105 | "reputation": "{$reputation}", |
| 106 | "is_attested": "{$evaluated_is_attested}" |
| 107 | } |
| 108 | }, |
| 109 | { |
| 110 | "app": "state", |
| 111 | "state": "{ |
| 112 | var['bo('||$attestor_hash] += trigger.output[[asset=base]].amount - 1000; |
| 113 | var['is_test_mode'] = $is_test_mode; |
| 114 | |
| 115 | var['user_address'] = $user_address; |
| 116 | var['evaluated_address'] = $evaluated_address; |
| 117 | var['domain'] = $domain; |
| 118 | var['evaluation'] = $evaluation; |
| 119 | var['attestor'] = $attestor; |
| 120 | var['user_address_hash'] = $user_address_hash; |
| 121 | var['evaluated_address_hash'] = $evaluated_address_hash; |
| 122 | var['domain_hash'] = $domain_hash; |
| 123 | var['attestor_hash'] = $attestor_hash; |
| 124 | var['attested_domain'] = $attested_domain; |
| 125 | var['evaluation_hash'] = $evaluation_hash; |
| 126 | var['reputation_hash'] = $reputation_hash; |
| 127 | var['evaluation_count_hash'] = $evaluation_count_hash; |
| 128 | var['evaluated_is_attested'] = $evaluated_is_attested; |
| 129 | var['user_is_attested'] = $user_is_attested; |
| 130 | var['attested_domain_exist'] = $attested_domain_exist; |
| 131 | var['balance_in_attestor_scope'] = $balance_in_attestor_scope; |
| 132 | var['reputation'] = $reputation; |
| 133 | var['eval_count'] = $eval_count; |
| 134 | var['old_evaluation_hash'] = var[$evaluation_hash]; |
| 135 | var['is_re_evaluation'] = $is_re_evaluation; |
| 136 | var['previous_evaluation'] = $previous_evaluation; |
| 137 | var['fee_received'] = $fee_received; |
| 138 | var['is_creation_fee_received'] = $is_creation_fee_received; |
| 139 | var['is_requesting_fee_received'] = $is_requesting_fee_received; |
| 140 | var['reward'] = $reward; |
| 141 | var['total_score'] = $total_score; |
| 142 | var['new_reputation'] = $new_reputation; |
| 143 | var['new_eval_count'] = $new_eval_count; |
| 144 | var['reputation_to_show'] = $reputation_to_show; |
| 145 | var['message'] =$message; |
| 146 | }" |
| 147 | } |
| 148 | ] |
| 149 | }, |
| 150 | { |
| 151 | "if": "{$is_contributing}", |
| 152 | "init": "{ |
| 153 | if (!$attested_domain_exist and !$is_creation_fee_received and !$attested_default_domain){ |
| 154 | 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');} |
| 155 | if (!$user_is_attested) |
| 156 | { |
| 157 | if(!$is_test_mode) |
| 158 | { |
| 159 | bounce('Sorry, to be able to give an evaluation you need to be attested by the following attestor: \''|| $attestor || '\' or it will be too easy to pump a reputation.'); |
| 160 | |
| 161 | } |
| 162 | else |
| 163 | $warning ='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. '; |
| 164 | $message_about_testing = $warning otherwise ''; |
| 165 | } |
| 166 | |
| 167 | |
| 168 | $reward = $evaluated_is_attested? |
| 169 | round($balance_in_attestor_scope* $reward_pourcentage /100) : |
| 170 | $symbolic_reward; |
| 171 | |
| 172 | |
| 173 | $total_score=($reputation * $eval_count); |
| 174 | |
| 175 | if ($is_re_evaluation){ |
| 176 | $new_reputation = ($total_score + ($evaluation-$previous_evaluation) / ($eval_count)); |
| 177 | $message_about_re_evaluation = 'Your evaluation was changed from '||$previous_evaluation||' to '||$evaluation||'. '; |
| 178 | $new_eval_count = $eval_count; |
| 179 | $message_about_number_of_eval = 'The number of votes for this address is still '||$new_eval_count||'. '; |
| 180 | } |
| 181 | else{ |
| 182 | $new_reputation = ($total_score + $evaluation) / ($eval_count+1); |
| 183 | $message_about_re_evaluation = ''; |
| 184 | $new_eval_count = $eval_count+1; |
| 185 | $message_about_number_of_eval = 'There is now '||$new_eval_count||' votes for this address. '; |
| 186 | } |
| 187 | |
| 188 | |
| 189 | $reputation_to_show = round($new_reputation,1); |
| 190 | if (!$attested_domain_exist) |
| 191 | $message_about_domain = 'The domain \''||$domain||'\' has been created in the scope of the attestor \''||$attestor||'\'. '; |
| 192 | else |
| 193 | $message_about_domain = ''; |
| 194 | $message = $message_about_testing||$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; |
| 195 | |
| 196 | response['message'] = $message; |
| 197 | response['domain'] = $domain; |
| 198 | response['attestor'] = $attestor; |
| 199 | response['vote_from'] = $user_address; |
| 200 | if ($is_re_evaluation) |
| 201 | { |
| 202 | response['old_evaluation'] = $previous_evaluation; |
| 203 | response['new_evaluation'] = $evaluation; |
| 204 | } |
| 205 | else |
| 206 | response['evaluation'] = $evaluation; |
| 207 | response['old_reputation'] = $reputation; |
| 208 | response['new_reputation'] = $new_reputation; |
| 209 | response['attested'] = $evaluated_is_attested; |
| 210 | }", |
| 211 | "messages": [ |
| 212 | { |
| 213 | "app": "payment", |
| 214 | "payload": { |
| 215 | "asset": "{'base'}", |
| 216 | "outputs": [ |
| 217 | { |
| 218 | "address": "{trigger.address}", |
| 219 | "amount": "{$reward}" |
| 220 | } |
| 221 | ] |
| 222 | } |
| 223 | }, |
| 224 | { |
| 225 | "app": "state", |
| 226 | "state": "{ |
| 227 | var['user_address'] = $user_address; |
| 228 | var['evaluated_address'] = $evaluated_address; |
| 229 | var['domain'] = $domain; |
| 230 | var['evaluation'] = $evaluation; |
| 231 | var['attestor'] = $attestor; |
| 232 | var['user_address_hash'] = $user_address_hash; |
| 233 | var['evaluated_address_hash'] = $evaluated_address_hash; |
| 234 | var['domain_hash'] = $domain_hash; |
| 235 | var['attestor_hash'] = $attestor_hash; |
| 236 | var['attested_domain'] = $attested_domain; |
| 237 | var['evaluation_hash'] = $evaluation_hash; |
| 238 | var['reputation_hash'] = $reputation_hash; |
| 239 | var['evaluation_count_hash'] = $evaluation_count_hash; |
| 240 | var['evaluated_is_attested'] = $evaluated_is_attested; |
| 241 | var['user_is_attested'] = $user_is_attested; |
| 242 | var['attested_domain_exist'] = $attested_domain_exist; |
| 243 | var['balance_in_attestor_scope'] = $balance_in_attestor_scope; |
| 244 | var['reputation'] = $reputation; |
| 245 | var['eval_count'] = $eval_count; |
| 246 | var['old_evaluation_hash'] = var[$evaluation_hash]; |
| 247 | var['is_re_evaluation'] = $is_re_evaluation; |
| 248 | var['previous_evaluation'] = $previous_evaluation; |
| 249 | var['fee_received'] = $fee_received; |
| 250 | var['is_creation_fee_received'] = $is_creation_fee_received; |
| 251 | var['is_requesting_fee_received'] = $is_requesting_fee_received; |
| 252 | var['reward'] = $reward; |
| 253 | var['total_score'] = $total_score; |
| 254 | var['new_reputation'] = $new_reputation; |
| 255 | var['new_eval_count'] = $new_eval_count; |
| 256 | var['reputation_to_show'] = $reputation_to_show; |
| 257 | var['message'] =$message; |
| 258 | |
| 259 | if (!$attested_domain_exist) |
| 260 | var['coad('||$attested_domain]=$user_address_hash; |
| 261 | var['is_test_mode'] = $is_test_mode; |
| 262 | var['eco('||$evaluation_count_hash] = $new_eval_count; |
| 263 | var['ro('||$reputation_hash] = $new_reputation; |
| 264 | var['leo('||$evaluation_hash] = $evaluation; |
| 265 | var['bo('||$attestor_hash] = $balance_in_attestor_scope - $reward; |
| 266 | }" |
| 267 | } |
| 268 | ] |
| 269 | } |
| 270 | ] |
| 271 | } |
| 272 | } |
| 273 | ] |