Unit ID
DK7Vg5AaG8LM2erCtU+0k0WPjr5PiIFmOTc80pIYvz4=
Received
27.06.2021 15:53:19
Confirmation delay (full node)
15 minutes 26 seconds
Confirmation delay (light node)
22 minutes 11 seconds
Authors
KUNNTFAD3G55IWXSNKTDRKH222E4DF7R
Definition
Messages
Definition
Definition: [ "autonomous agent", { "doc_url": "https://counterstake.org/bridge-export-governance.json", "getters": "{ $get_challenging_periods = $periods_string => { $periods = split($periods_string, " "); if (length($periods) > 20) bounce("too many periods"); $prev = {period: 0}; map($periods, 20, $period => { $nPeriod = +$period; if ($nPeriod <= 0 OR $nPeriod > 3*365*24) bounce("bad challenging period: " || $period); if ($nPeriod < $prev.period) bounce("subsequent periods cannot get shorter"); $prev.period = $nPeriod; $nPeriod }) }; $get_parsed_value = ($name, $value) => { if ($name == 'challenging_periods' OR $name == 'large_challenging_periods') return $get_challenging_periods($value); $value }; }", "init": "{ $challenging_period = params.challenging_period OTHERWISE 3*24*3600; // one cannot withdraw for this period after voting for a winning value $freeze_period = params.freeze_period OTHERWISE 30*24*3600; $export_aa = params.export_aa; if (!$export_aa) bounce("no export_aa"); $asset = definition[$export_aa][1].params.asset; $names = ['ratio', 'counterstake_coef', 'min_tx_age', 'min_stake', 'large_threshold', 'challenging_periods', 'large_challenging_periods']; $is_allowed_name = $name => { length(filter($names, 20, $n => $n == $name)) == 1 }; $get_value_key = $value => $value; }", "messages": { "cases": [ { "if": "{ trigger.data.name AND trigger.data.commit }", "init": "{ $name = trigger.data.name; $leader = var['leader_' || $name]; $current_value = var[$name]; if (!exists($leader)) // can be 0 bounce("no leader"); if (exists($current_value) AND $leader == $current_value) bounce("already equal to leader"); if (var['challenging_period_start_ts_' || $name] + $challenging_period > timestamp) bounce("challenging period not expired yet"); }", "messages": [ { "app": "payment", "payload": { "asset": "base", "outputs": [ { "address": "{$export_aa}", "amount": 5000 } ] } }, { "app": "data", "payload": { "name": "{$name}", "value": "{$get_parsed_value($name, $leader)}" } }, { "app": "state", "state": "{ var[$name] = $leader; }" } ] }, { "if": "{ trigger.data.name }", "init": "{ $balance = var['balance_' || trigger.address] + trigger.output[[asset=$asset]]; if (!$balance) bounce("you have no deposited balance and cannot vote"); $name = trigger.data.name; $value = trigger.data.value; // can be empty to remove one's vote if (!$is_allowed_name($name)) bounce("unknown name: " || $name); if (exists($value)){ if ($name == 'ratio' AND !(typeof($value) == 'number' AND $value > 0)) bounce("invalid value"); if ($name == 'counterstake_coef' AND !(typeof($value) == 'number' AND $value > 1)) bounce("invalid value"); if ($name == 'min_stake' AND !(is_integer($value) AND $value >= 0)) bounce("invalid value"); if ($name == 'min_tx_age' AND !(is_integer($value) AND $value >= 0)) bounce("invalid value"); if ($name == 'large_threshold' AND !(is_integer($value) AND $value >= 0)) bounce("invalid value"); if ($name == 'challenging_periods' OR $name == 'large_challenging_periods') $data = $get_parsed_value($name, $value); // will bounce if the format is bad } }", "messages": [ { "app": "state", "state": "{ if (trigger.output[[asset=$asset]]) var['balance_' || trigger.address] += trigger.output[[asset=$asset]]; $prev_choice = var['choice_' || trigger.address || '_' || $name]; $leader = var['leader_' || $name]; if (exists($leader) AND exists($prev_choice) AND $prev_choice == $leader AND var['challenging_period_start_ts_' || $name] + $challenging_period + $freeze_period > timestamp) bounce("you cannot change your vote yet"); var['choice_' || trigger.address || '_' || $name] = $value; if (exists($prev_choice)){ $prev_choice_key = $get_value_key($prev_choice); var['support_' || $name || '_' || $prev_choice_key] -= var['support_' || $name || '_' || $prev_choice_key || '_' || trigger.address]; var['support_' || $name || '_' || $prev_choice_key || '_' || trigger.address] = false; } if (exists($value)){ $value_key = $get_value_key($value); var['support_' || $name || '_' || $value_key] += $balance; var['support_' || $name || '_' || $value_key || '_' || trigger.address] = $balance; if (!exists($leader) OR var['support_' || $name || '_' || $value_key] > var['support_' || $name || '_' || $get_value_key($leader)]){ var['leader_' || $name] = $value; var['challenging_period_start_ts_' || $name] = timestamp; } } }" } ] }, { "if": "{ trigger.data.withdraw }", "init": "{ $balance = var['balance_' || trigger.address] + trigger.output[[asset=$asset]]; if (!$balance) bounce("you have no deposited balance and cannot withdraw"); $amount = trigger.data.amount OTHERWISE $balance; if ($amount > $balance) bounce("your balance is only " || $balance); foreach($names, 12, $name => { if (var['choice_' || trigger.address || '_' || $name]) bounce("support for " || $name || " not removed yet"); }); }", "messages": [ { "app": "payment", "payload": { "asset": "{$asset}", "outputs": [ { "address": "{trigger.address}", "amount": "{ $amount }" } ] } }, { "app": "state", "state": "{ var['balance_' || trigger.address] -= $amount; }" } ] } ] } } ]
Technical information
Fees:
6,186 bytes
(514 headers, 5672 payload)
Level:7815278
Witnessed level:7815268
Main chain index:7499972
Latest included mc index:7499971
Status:stable/confirmed/final