-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTARAA.oscript.txt
182 lines (156 loc) · 8.82 KB
/
TARAA.oscript.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
{
/*
Check in explorer: https://testnetexplorer.obyte.org/#JX2GzM1B+1i878slzmid3LtuO28DCCX0lSGC8fIGa8E=
Agent address: JUKEC3ZUXUEFWFGZESVQDGHRKE53NBDK
*/
"bounce_fees": {
"base": 10000
},
"init": "{
// Instructions bounced to user
$INSTRUCTIONS_TO_VOTE = "To vote, use 'evaluate' = <evaluated address> + 'score' = < 0 to 5 > and optionaly 'domain' = < domain name > to vote in a specific domain. ";
$INSTRUCTIONS_TO_CREATE_A_DOMAIN = 'A new domain 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;
// FOREVER CONSTANTS
$AA_OWNER = 'SX66Y36BOU77S7MWML6JQQA3CJLX4COR';
$DEFAULT_DOMAIN = 'base';
$DEFAULT_ATTESTOR = '35IT3ZYKEPQSCXG2F7A7KWNRAD3SZXN4'; // official attestor
$DEFAULT_CREATION_FEE = 500000; // 500,000.0 bytes
$DEFAULT_REWARD = 1; // in percentage
$DEFAULT_FORGIVING_DELAY = 36500; // in days, to be use
// variable depending on the aa state and the input
$i = trigger.data;
$user = trigger.address;
$anonym_user = sha256($user);
$target = $i.evaluate;
$score = $i.score otherwise -1; // Evaluation: 0-5
$domain = $i.domain otherwise $DEFAULT_DOMAIN;
$balance = var[$domain||"_balance"] otherwise trigger.output[[asset=base]].amount - 1000;
$count = var[$domain||"_count"] otherwise 0;
$last_eval = var[$domain||"_"||$anonym_user] otherwise false;
$last_eval_time = var[$domain||"_eval_time"] otherwise timestamp;
$attestor = var[$domain||"_attestor"] otherwise $i.attestor otherwise $DEFAULT_ATTESTOR;
$reward = var[$domain||"_reward"] otherwise $i.reward otherwise $DEFAULT_REWARD;
$use_balance_weigth = var[$domain||"_use_balance_weigth"] otherwise $i.use_balance_weigth;
$forgiving_delay = var[$domain||"_forgive_delay"] otherwise $i.forgive otherwise $DEFAULT_FORGIVING_DELAY;
$creation_fee = $i.creation_fee otherwise $DEFAULT_CREATION_FEE;
}",
"messages": {
"cases": [
{ // vote
"if": "{ !! trigger.data.evaluate }",
"init": "{
// bouncing
if (!$score) bounce ($INSTRUCTIONS_TO_VOTE);
if ($score < 0 or $score > 5) bounce('Score must be set between 0 and 5 !');
if ($target == $user) bounce('You can NOT vote for yourself !');
if (!var[$domain]) bounce('Domain do NOT exist !');
if (attestation[[attestors=$attestor, address=$user, ifnone=0]]) bounce ("You must be attested by "||$attestor);
// reputation computation
$reputation_corrected = ($reputation == -1)? 0: $reputation;
$total_score=($reputation * $eval_count);
if ($is_re_evaluation){
$new_reputation = ($total_score + ($evaluation-$previous_evaluation) / ($eval_count));
$new_eval_count = $eval_count;
}
else{
$new_reputation = ($total_score + $evaluation) / ($eval_count+1);
$new_eval_count = $eval_count+1;
}
$reputation_to_show = round($new_reputation,1);
// calculating reward
if ($user_is_attested){
$reward = round($balance_in_attestor_scope* $reward_pourcentage /100);
$message_about_the_reward = 'The reward is '||$reward_pourcentage||'% of the attested scope which is '|| $balance_in_attestor_scope ||" bytes. ";
}
else{
$reward = $symbolic_reward;
$message_about_the_reward = 'The reward is symbolic because you are not attested by '|| $attestor_address||'. ';
}
if ($AA_in_debug_mode){
$REWARD_COMPUTATION = 'The reward will be ('|| $reward ||'). '|| $message_about_the_reward ||'. ';
response['REWARD_COMPUTATION'] = $REWARD_COMPUTATION;
}
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "{'base'}",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{$reward}"
}
]
}
},
{
"app": "state",
"state": "{
var[$domain||"_balance"] = $balance;
var[$domain||"_count"] = $count otherwise 0;
var[$domain||"_"||$anonym_user] = $last_eval;
var[$domain||"_eval_time"] = $last_eval_time;
var[$domain||"_attestor"] = $attestor;
var[$domain||"_reward"] = $reward;
var[$domain||"_use_balance_weigth"] = $use_balance_weigth;
var[$domain||"_forgive_delay"] = $forgiving_delay;
}"
}
]
},
{
"if": "{!!trigger.data.create}",
"init": "{
// Domain exist? bounce
if ($attested_domain_exist)
bounce('Sorry, The domain \''||$domain||'\' in the scope of the attestor \''||$attestor_address||'\' already exist. ');
// fee paied?
if (!$is_creation_fee_received)
bounce('Sorry, The fee to create a domain is '|| $DOMAIN_CREATION_FEE ||'bytes. ');
// prepare meesages
$message_about_creation_requirements = 'In creation mode you should have '||$message_creation_howto||' and you should not specify any \'evaluation\'. ';
// to much param? bounce
if($is_requesting or $is_contributing)
bounce('Sorry, '|| $message_about_creation_requirements);
// check if creation mode ok
$moa = $mode_of_average_for_creation;
if(($moa != $AVERAGING_MODE_UNWEIGHTED) and ($moa != $AVERAGING_MODE_TIME_WEIGHTED) and ($moa != $mode_cbwa) and ($moa != $AVERAGING_MODE_REPUTATION_WEIGHTED))
bounce('Sorry, '|| $message_about_creation_requirements);
$ok_to_create_domain=true;
$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||'\'. ';
response['message'] = $message_about_creation;
if ($AA_in_debug_mode){
$DOMAIN_CREATION = $message_about_creation;
response['DOMAIN_CREATION'] = $DOMAIN_CREATION;
}
}",
"messages": [
{
"app": "state",
"state": "{
$saved_fee = trigger.output[[asset=base]].amount - 1000; // 1000 is the data transfert fee approximation
var['coad('||$attested_domain]=$user_address_hash; // creating the var.
var['moa('||$attested_domain]=$mode_of_average_for_creation;
var['bo('||$attestor_hash] += $saved_fee;
if ($AA_in_debug_mode){
$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. ';
response['FINAL_DAG_STATE'] = $FINAL_DAG_STATE;
}
}"
}
]
},
{
"messages": [
{
"app": "state",
"state": "{
bounce ($INSTRUCTIONS_TO_VOTE || " " ||$INSTRUCTIONS_TO_CREATE_A_DOMAIN);
}"
}
]
}
]
}
}