Пример #1
0
        internal override async ContractTask PostPersist(ApplicationEngine engine)
        {
            // Distribute GAS for committee

            int m           = engine.ProtocolSettings.CommitteeMembersCount;
            int n           = engine.ProtocolSettings.ValidatorsCount;
            int index       = (int)(engine.PersistingBlock.Index % (uint)m);
            var gasPerBlock = GetGasPerBlock(engine.Snapshot);
            var committee   = GetCommitteeFromCache(engine.Snapshot);
            var pubkey      = committee[index].PublicKey;
            var account     = Contract.CreateSignatureRedeemScript(pubkey).ToScriptHash();
            await GAS.Mint(engine, account, gasPerBlock *CommitteeRewardRatio / 100, false);

            // Record the cumulative reward of the voters of committee

            if (ShouldRefreshCommittee(engine.PersistingBlock.Index, m))
            {
                BigInteger voterRewardOfEachCommittee = gasPerBlock * VoterRewardRatio * 100000000L * m / (m + n) / 100; // Zoom in 100000000 times, and the final calculation should be divided 100000000L
                for (index = 0; index < committee.Count; index++)
                {
                    var member = committee[index];
                    var factor = index < n ? 2 : 1; // The `voter` rewards of validator will double than other committee's
                    if (member.Votes > 0)
                    {
                        BigInteger voterSumRewardPerNEO = factor * voterRewardOfEachCommittee / member.Votes;
                        StorageKey voterRewardKey       = CreateStorageKey(Prefix_VoterRewardPerCommittee).Add(member.PublicKey).AddBigEndian(engine.PersistingBlock.Index + 1);
                        byte[]     border = CreateStorageKey(Prefix_VoterRewardPerCommittee).Add(member.PublicKey).ToArray();
                        (_, var item)         = engine.Snapshot.FindRange(voterRewardKey.ToArray(), border, SeekDirection.Backward).FirstOrDefault();
                        voterSumRewardPerNEO += (item ?? BigInteger.Zero);
                        engine.Snapshot.Add(voterRewardKey, new StorageItem(voterSumRewardPerNEO));
                    }
                }
            }
        }
Пример #2
0
        private void DistributeGas(ApplicationEngine engine, UInt160 account, NeoAccountState state)
        {
            BigInteger gas = CalculateBonus(engine.Snapshot, state.Balance, state.BalanceHeight, engine.Snapshot.PersistingBlock.Index);

            state.BalanceHeight = engine.Snapshot.PersistingBlock.Index;
            GAS.Mint(engine, account, gas);
        }
Пример #3
0
        private void DistributeGas(ApplicationEngine engine, UInt160 account, AccountState state)
        {
            BigInteger gas = CalculateBonus(engine.Snapshot, state.Balance, state.BalanceHeight, engine.Snapshot.PersistingBlock.Index);

            state.BalanceHeight = engine.Snapshot.PersistingBlock.Index;
            GAS.Mint(engine, account, gas);
            engine.Snapshot.Storages.GetAndChange(CreateAccountKey(account)).Value = state.ToByteArray();
        }
Пример #4
0
        private protected override async ContractTask PostTransfer(ApplicationEngine engine, UInt160 from, UInt160 to, BigInteger amount, StackItem data, bool callOnPayment)
        {
            await base.PostTransfer(engine, from, to, amount, data, callOnPayment);

            var list = engine.CurrentContext.GetState <List <GasDistribution> >();

            foreach (var distribution in list)
            {
                await GAS.Mint(engine, distribution.Account, distribution.Amount, callOnPayment);
            }
        }
Пример #5
0
        private void DistributeGas(ApplicationEngine engine, UInt160 account, NeoAccountState state)
        {
            // PersistingBlock is null when running under the debugger
            if (engine.Snapshot.PersistingBlock == null)
            {
                return;
            }

            BigInteger gas = CalculateBonus(engine.Snapshot, state.Balance, state.BalanceHeight, engine.Snapshot.PersistingBlock.Index);

            state.BalanceHeight = engine.Snapshot.PersistingBlock.Index;
            GAS.Mint(engine, account, gas);
        }
Пример #6
0
        protected override void PostPersist(ApplicationEngine engine)
        {
            base.PostPersist(engine);

            // Distribute GAS for committee

            int index       = (int)(engine.Snapshot.PersistingBlock.Index % (uint)ProtocolSettings.Default.CommitteeMembersCount);
            var gasPerBlock = GetGasPerBlock(engine.Snapshot);
            var pubkey      = GetCommittee(engine.Snapshot)[index];
            var account     = Contract.CreateSignatureRedeemScript(pubkey).ToScriptHash();

            GAS.Mint(engine, account, gasPerBlock * CommitteeRewardRatio / 100);
        }
Пример #7
0
        private async ContractTask DistributeGas(ApplicationEngine engine, UInt160 account, NeoAccountState state)
        {
            // PersistingBlock is null when running under the debugger
            if (engine.PersistingBlock is null)
            {
                return;
            }

            BigInteger gas = CalculateBonus(engine.Snapshot, state.VoteTo, state.Balance, state.BalanceHeight, engine.PersistingBlock.Index);

            state.BalanceHeight = engine.PersistingBlock.Index;
            await GAS.Mint(engine, account, gas, true);
        }