| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | |
| 9 | $i_domain_creation_fee = 500000; |
| 10 | $i_requesting_reputation_fee = 10000; |
| 11 | $i_reward_pourcentage = 1; |
| 12 | $i_symbolic_reward= 10; |
| 13 | $i_evaluation_delay = 2*24*60*60; |
| 14 | |
| 15 | |
| 16 | $default_domain = 'base'; |
| 17 | $default_attestor = '35IT3ZYKEPQSCXG2F7A7KWNRAD3SZXN4'; |
| 18 | |
| 19 | $reputation_word_hash = '556ec7485db6ec2596054ef0374f50e4dfbcc3962c879e9464cdca80ebdfc34e'; |
| 20 | $evaluation_count_word_hash = '039adc37a247cfd497f19d106479ac55aab96db3ae74114c74edf8143e1eb29e'; |
| 21 | |
| 22 | |
| 23 | $user = trigger.address; |
| 24 | $evaluated_address = trigger.data.adress otherwise trigger.data.ad; |
| 25 | $domain = trigger.data.domain otherwise trigger.data.do otherwise $default_domain; |
| 26 | $evaluation = trigger.data.evaluation otherwise trigger.data.ev; |
| 27 | $attestator = trigger.data.attestor otherwise trigger.data.at otherwise $default_attestor; |
| 28 | |
| 29 | |
| 30 | $is_requesting = $evaluation == '?'; |
| 31 | $is_contributing = (!$is_requesting)? $evaluation >= 0 and $evaluation <= 5 : false; |
| 32 | |
| 33 | |
| 34 | if(!$is_requesting and !$is_contributing) |
| 35 | 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.'); |
| 36 | if(!$evaluated_address) |
| 37 | bounce('Sorry, You have to specify which address you want to find reputation for. Please add an \'address\' field in the data section.'); |
| 38 | |
| 39 | |
| 40 | $user_hash = sha256($user); |
| 41 | $evaluated_address_hash = sha256($evaluated_address); |
| 42 | $domain_hash = sha256($domain); |
| 43 | $attestator_hash = sha256($attestor); |
| 44 | $attested_domain = sha256($domain_hash and $attested_domain); |
| 45 | $evaluation_hash = sha256($attested_domain and $user_hash and $evaluated_address_hash); |
| 46 | $reputation_hash = sha256($attested_domain and $evaluated_address_hash and $reputation_word_hash); |
| 47 | $evaluation_count_hash = sha256($attested_domain and $evaluated_address_hash and $evaluation_count_wordhash); |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | $evaluated_is_attested = attestation[[attestors=$attestor_address, address=$evaluated_address, ifnone=0]]; |
| 54 | $user_is_attested = attestation[[attestors=$attestor_address, address=$evaluated_address, ifnone=0]]; |
| 55 | |
| 56 | |
| 57 | $attested_domain_exist = var[$attested_domain]; |
| 58 | $balance_in_attestator_scope = var[$attestator_hash]; |
| 59 | $reputation = var[$reputation_hash]; |
| 60 | $eval_count = var[$evaluation_count_hash]; |
| 61 | $previous_evaluation = var[$evaluation_hash]; |
| 62 | |
| 63 | |
| 64 | $fee_received = trigger.output[[asset=base]].amount; |
| 65 | $creation_fee_received = $fee_received > $i_domain_creation_fee; |
| 66 | $requesting_fee_received = $fee_received > $getting_reputation_fee; |
| 67 | |
| 68 | }", |
| 69 | "messages": { |
| 70 | "cases": [ |
| 71 | { |
| 72 | "if": "{$requesting}", |
| 73 | "init": "{ |
| 74 | if (!$attested_domain_exist) |
| 75 | bounce('Sorry, You have requested reputation for a domain-attestor pair that do not exist.'); |
| 76 | $reputationExists = $reputation != false; |
| 77 | if (!$reputationExists) |
| 78 | 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.'); |
| 79 | if (!$requesting_fee_received) |
| 80 | bounce('Sorry, The fee to request a reputation is '|| $i_requesting_reputation_fee || 'bytes'); |
| 81 | |
| 82 | |
| 83 | $reputation_to_show = round($reputation,1); |
| 84 | if ($evaluated_is_attested){ |
| 85 | $message = 'Reputation for domain \''|| $domain ||'\' is '||$reputation_to_show||'/5 from '||$eval_count||' votes (and the address is attested by \''||$attestor_address||'\').'; |
| 86 | }else{ |
| 87 | $message = 'Reputation for domain \''|| $domain ||'\' is '||$reputation_to_show||'/5 from '||$eval_count||' votes BUT the address is NOT attested by \''||$attestor_address||'\')!'; |
| 88 | } |
| 89 | response['message'] = $message; |
| 90 | response['domain'] = $domain; |
| 91 | response['attestor'] = $attestor; |
| 92 | response['reputation'] = $reputation_to_show; |
| 93 | response['attestated'] = $evaluated_is_attested == true; |
| 94 | }", |
| 95 | "messages": [ |
| 96 | { |
| 97 | "app": "data", |
| 98 | "payload": { |
| 99 | "message": "{$message}", |
| 100 | "reputation": "{$reputation}", |
| 101 | "is_attestated": "{$evaluated_is_attested}" |
| 102 | } |
| 103 | }, |
| 104 | { |
| 105 | "app": "state", |
| 106 | "state": "{ |
| 107 | var[$attestator_hash] += trigger.output[[asset=base]].amount - 1000; |
| 108 | }" |
| 109 | } |
| 110 | ] |
| 111 | }, |
| 112 | { |
| 113 | "if": "{$is_contributing}", |
| 114 | "init": "{ |
| 115 | if (!$attested_domain_exist and !$creation_fee_received){ |
| 116 | bounce('Sorry, the domain-attestator pair do not exists. It can be created but the fee is \''||$i_domain_creation_fee || '\' bytes, this money will be used to reward the evaluators');} |
| 117 | if (!$user_is_attested) |
| 118 | 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.'); |
| 119 | |
| 120 | $is_re_evaluation = $previous_evaluation != false; |
| 121 | $previous_evaluation = $is_re_evaluation? $previous_evaluation : 0; |
| 122 | |
| 123 | |
| 124 | $reward = $evaluated_is_attested? |
| 125 | round($balance_in_attestator_scope* $i_reward_pourcentage /100) : |
| 126 | $i_symbolic_reward; |
| 127 | }", |
| 128 | "messages": [ |
| 129 | { |
| 130 | "app": "payment", |
| 131 | "payload": { |
| 132 | "asset": "{'base'}", |
| 133 | "outputs": [ |
| 134 | { |
| 135 | "address": "{trigger.address}", |
| 136 | "amount": "{$reward}" |
| 137 | } |
| 138 | ] |
| 139 | } |
| 140 | }, |
| 141 | { |
| 142 | "app": "state", |
| 143 | "state": "{ |
| 144 | $message=''; |
| 145 | if (!$attested_domain_exist){ |
| 146 | var[$attested_domain]=true; |
| 147 | $message = $message||'Domain \''||$domain||'\' created '; |
| 148 | $message = $message||'in the scope the attestator \''||$attestator||'\';'; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | $total_score=($reputation * $eval_count); |
| 153 | |
| 154 | if ($is_re_evaluation){ |
| 155 | $new_reputation = ($total_score + ($evaluation-$previous_evaluation) / ($eval_count)); |
| 156 | } |
| 157 | else{ |
| 158 | $new_reputation = ($total_score + $evaluation) / ($eval_count+1); |
| 159 | var[$evaluation_count_hash] +=1; |
| 160 | } |
| 161 | |
| 162 | var[$reputation_hash] = $new_reputation; |
| 163 | |
| 164 | |
| 165 | var[$evaluation_hash] = $evaluation; |
| 166 | |
| 167 | |
| 168 | var[$attestator_hash] = $evaluated_is_attested - $reward; |
| 169 | |
| 170 | |
| 171 | $message = $message||'Thank you for your contribution, '; |
| 172 | $message = $message||'a reward of '||$reward||'byte have been sent to you.;'; |
| 173 | $message = $message||'New reputation of '||$evaluated_address||' is '||$reputation_to_show||'/5'; |
| 174 | $message = $message||'New reputation of '||$evaluated_address||' is '||$reputation_to_show||'/5'; |
| 175 | |
| 176 | response['message'] = $message; |
| 177 | response['domain'] = $domain; |
| 178 | response['attestor'] = $attestor; |
| 179 | response['old_reputation'] = $reputation; |
| 180 | response['new_reputation'] = $new_reputation; |
| 181 | response['attestated'] = $evaluated_is_attested == true; |
| 182 | |
| 183 | }" |
| 184 | } |
| 185 | ] |
| 186 | } |
| 187 | ] |
| 188 | } |
| 189 | } |
| 190 | ] |