Unit ID
tkYw2KNGvruqrajH/59U+G9UmCezhmID+UrFIxntag4=
Received
07.06.2021 05:35:24
Confirmation delay (full node)
3 minutes 9 seconds
Confirmation delay (light node)
6 minutes 0 seconds
Messages
Definition
Definition: [ "autonomous agent", { "bounce_fees": { "base": 10000 }, "getters": "{ $attestor = 'QBIAZQZWO3YK2I2C3X37DCVY643S4NI4'; $has_attestation = ($address, $github_username) => { $attestation = attestation[[attestors=$attestor, address=$address]].github_username; typeof($attestation) == 'string' AND to_lower($attestation) == to_lower($github_username) }; $parse_repo_str = ($str) => { $sp = split($str, '/'); if (length($sp) != 2 OR length($sp[0]) < 1 OR length($sp[1]) < 1) { bounce('Invalid repo: ' || $str); } $sp }; $check_rules_and_count_total = ($rules, $own_repo) => { if (typeof($rules) != 'object' OR is_array($rules)) { bounce('rules is not an object'); } if (length($rules) > 10) { bounce('Maximum number of nested repositories is 10'); } if (length($rules) == 0) { return 0; } $total = reduce($rules, 10, ($acc, $key, $value) => { $parse_repo_str($key); if ($key == $own_repo) { bounce('Invalid repo: ' || $key || ' Don\'t set own repo in rules; You will receive the unshared remainder'); } if (typeof($value) != 'number') { bounce('Not a number ' || $value || ' in repo ' || $key); } $acc + $value }, 0); $total }; }", "init": "{ if (exists(trigger.data.repo) AND (trigger.data.repo != to_lower(trigger.data.repo))){ bounce('repo must be lowercase'); } }", "messages": { "cases": [ { "if": "{trigger.data.set_rules AND trigger.data.repo}", "messages": [ { "app": "state", "state": "{ if (trigger.output[[asset=base]] < 4224) { bounce('Not enough fee to pay rules storage'); } $sp = $parse_repo_str(trigger.data.repo); $owner = $sp[0]; $project = $sp[1]; if (!$has_attestation(trigger.address, $owner)) { bounce('Address ' || trigger.address || ' has no attestation for ' || $owner); } $rules = trigger.data.rules OTHERWISE {}; $total = $check_rules_and_count_total($rules, trigger.data.repo); if ($total > 100) { bounce('Sum of rules distribution is more than 100'); } var[trigger.data.repo || '*rules'] = $rules; response['message'] = 'Rules for ' || trigger.data.repo || ' are set'; }" } ] }, { "if": "{trigger.data.donate AND trigger.data.repo}", "messages": [ { "app": "state", "state": "{ $parse_repo_str(trigger.data.repo); $base_pool_var = trigger.data.repo || '*pool*base'; if (trigger.output[[asset=base]] < 1000) { bounce('Not enough fee to pay storage'); } $base_amount = trigger.output[[asset=base]] - 1000; // 1000 bytes storage fee var[$base_pool_var] += $base_amount; $stat_total_base_var = trigger.data.repo || '*total_received_base'; var[$stat_total_base_var] += $base_amount; response['donated_in_base'] = $base_amount; $asset = trigger.output[[asset!=base]].asset; if ($asset == 'ambiguous') { bounce('Ambiguous asset'); } if ($asset != 'none') { $asset_amount = trigger.output[[asset!=base]]; $asset_pool_var = trigger.data.repo || '*pool*' || $asset; var[$asset_pool_var] += $asset_amount; $stat_total_asset_var = trigger.data.repo || '*total_received*' || $asset; var[$stat_total_asset_var] += $asset_amount; response['donated_in_' || $asset] = $asset_amount; } response['message'] = 'Successful donation to ' || trigger.data.repo; }" } ] }, { "if": "{trigger.data.distribute AND trigger.data.repo}", "init": "{ $sp = $parse_repo_str(trigger.data.repo); $owner = $sp[0]; $project = $sp[1]; $rules_var = trigger.data.repo || '*rules'; $claimer = $has_attestation(trigger.address, $owner) ? trigger.data.to OTHERWISE trigger.address : false; if (exists(var[$rules_var])) { $asset = trigger.data.asset OTHERWISE 'base'; $asset_pool_var = trigger.data.repo || '*pool*' || $asset; $unclaimed_var = trigger.data.repo || '*unclaimed*' || $asset; $unclaimed = var[$unclaimed_var] OTHERWISE 0; if (!var[$asset_pool_var] AND !($claimer AND $unclaimed)) { bounce('Nothing to distribute in repo ' || trigger.data.repo || ' for asset ' || $asset); } $to_self = var[$asset_pool_var] - reduce(var[$rules_var], 10, ($acc, $repo, $percent) => { $acc + floor(var[$asset_pool_var] * $percent / 100) }, 0); } else { bounce('Rules for repo ' || trigger.data.repo || ' are not set yet'); } }", "messages": [ { "if": "{$claimer}", "app": "payment", "payload": { "asset": "{$asset}", "outputs": [ { "address": "{$claimer}", "amount": "{$to_self + $unclaimed}" } ] } }, { "app": "state", "state": "{ foreach(var[$rules_var], 10, ($repo, $percent) => { $to_share = floor(var[$asset_pool_var] * $percent / 100); $repo_pool_var = $repo || '*pool*' || $asset; var[$repo_pool_var] += $to_share; $stat_forwarded_var = trigger.data.repo || '*to*' || $repo || '*' || $asset; var[$stat_forwarded_var] += $to_share; $stat_total_recv_var = $repo || '*total_received*' || $asset; var[$stat_total_recv_var] += $to_share; }); if ($claimer) { $stat_paid_to_var = 'paid_to*' || $claimer || '*' || $asset; var[$stat_paid_to_var] += $to_self + $unclaimed; var[$unclaimed_var] = 0; response['claimer'] = $claimer; response['claimed'] = $to_self + $unclaimed; } else { var[$unclaimed_var] += $to_self; } var[$asset_pool_var] = 0; response['asset'] = $asset; response['message'] = 'Distribution for repo ' || trigger.data.repo || ' in asset ' || $asset || ' done'; }" } ] }, { "if": "{trigger.data.nickname}", "messages": [ { "app": "state", "state": "{ if (typeof(trigger.data.nickname) != 'string') { bounce('Nickname is not a string'); } if (exists(var['nickname_owner*' || trigger.data.nickname])) { bounce('Nickname ' || trigger.data.nickname || ' is already taken'); } else { $old_nickname = var['nickname*' || trigger.address]; if ($old_nickname) { var['nickname_owner*' || $old_nickname] = false; } var['nickname*' || trigger.address] = trigger.data.nickname; var['nickname_owner*' || trigger.data.nickname] = trigger.address; } response['message'] = 'Nickname for ' || trigger.address || ' is now ' || trigger.data.nickname; }" } ] } ] } } ]
Technical information
Fees:
7,140 bytes
(452 headers, 6688 payload)
Level:2036626
Witnessed level:2036619
Main chain index:2028634
Latest included mc index:2028633
Status:stable/confirmed/final