Unit ID
dZLoEn1eWCnLzzfavm3pJIF2ebD+61yqn4vqgamNk1I=
Received
30.11.2021 11:10:30
Confirmation delay (full node)
7 minutes 11 seconds
Confirmation delay (light node)
9 minutes 14 seconds
Messages
Definition
Definition: [ "autonomous agent", { "bounce_fees": { "base": 10000 }, "getters": "{ $attestor = 'QMWQRJV6NCYGUI6X7BWRKLLBQVQYLZ27'; $has_attestation = ($address, $github_username) => { $attestation = attestation[[attestors=$attestor, address=$address]].github_username; typeof($attestation) == 'string' AND $attestation == $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 }; }", "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'; response['new_rules'] = json_stringify($rules); }" } ] }, { "if": "{trigger.data.donate AND trigger.data.repo}", "messages": [ { "app": "state", "state": "{ $parse_repo_str(trigger.data.repo); if (trigger.output[[asset=base]] < 1000) { bounce('Not enough fee to pay storage'); } if (trigger.output[[asset=base]] > 10000) { $base_pool_var = trigger.data.repo || '*pool*base'; $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 (trigger.output[[asset=base]] <= 10000 AND $asset == 'none') { bounce('You only pay commission'); } 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.donor AND is_valid_address(trigger.data.donor)) { response['donor'] = trigger.data.donor; } }" } ] }, { "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,378 bytes
(452 headers, 6926 payload)
Level:2498367
Witnessed level:2498360
Main chain index:2478564
Latest included mc index:2478563
Status:stable/confirmed/final