コード例 #1
0
        public override SynthesizedBlock ConvertApiSynthesizedBlock(SynthesizedBlockAPI synthesizedBlockApi)
        {
            SynthesizedBlock synthesizedBlock = base.ConvertApiSynthesizedBlock(synthesizedBlockApi);

            AccountId accountId = synthesizedBlockApi.AccountId != null ? new AccountId(synthesizedBlockApi.AccountId) : new AccountId(synthesizedBlockApi.AccountHash);

            if (synthesizedBlockApi is NeuraliumSynthesizedBlockApi neuraliumSynthesizedBlockApi && synthesizedBlock is NeuraliumSynthesizedBlock neuraliumSynthesizedBlock)
            {
                foreach (NeuraliumSynthesizedBlockApi.NeuraliumSynthesizedElectionResultAPI electionResult in neuraliumSynthesizedBlockApi.FinalElectionResults)
                {
                    NeuraliumSynthesizedBlock.NeuraliumSynthesizedElectionResult neuraliumSynthesizedElectionResult = new NeuraliumSynthesizedBlock.NeuraliumSynthesizedElectionResult();

                    neuraliumSynthesizedElectionResult.BlockId   = synthesizedBlockApi.BlockId;
                    neuraliumSynthesizedElectionResult.Timestamp = synthesizedBlockApi.Timestamp;

                    AccountId delegateAccountId = null;

                    if (!string.IsNullOrWhiteSpace(electionResult.DelegateAccountId))
                    {
                        delegateAccountId = new AccountId(electionResult.DelegateAccountId);
                    }

                    neuraliumSynthesizedElectionResult.ElectedAccounts.Add(accountId, (accountId, delegateAccountId, (Enums.ElectedPeerShareTypes)electionResult.PeerType, electionResult.SelectedTransactions));
                    neuraliumSynthesizedElectionResult.BlockId = synthesizedBlockApi.BlockId - electionResult.Offset;
                    neuraliumSynthesizedElectionResult.ElectedGains.Add(accountId, (electionResult.BountyShare, electionResult.Tips));

                    neuraliumSynthesizedBlock.FinalElectionResults.Add(neuraliumSynthesizedElectionResult);
                }
            }

            return(synthesizedBlock);
        }
コード例 #2
0
        protected override SynthesizedBlock SynthesizeBlock(IBlock block, AccountCache accountCache, Dictionary <TransactionId, ITransaction> blockConfirmedTransactions)
        {
            SynthesizedBlock synthesizedBlock = base.SynthesizeBlock(block, accountCache, blockConfirmedTransactions);

            if (synthesizedBlock is NeuraliumSynthesizedBlock neuraliumSynthesizedBlock && block is INeuraliumBlock neuraliumBlock)
            {
            }

            return(synthesizedBlock);
        }
コード例 #3
0
        protected override SynthesizedBlock.SynthesizedElectionResult SynthesizeElectionResult(SynthesizedBlock synthesizedBlock, IFinalElectionResults result, IBlock block, AccountCache accountCache, Dictionary <TransactionId, ITransaction> blockConfirmedTransactions)
        {
            SynthesizedBlock.SynthesizedElectionResult synthesizedElectionResult = base.SynthesizeElectionResult(synthesizedBlock, result, block, accountCache, blockConfirmedTransactions);

            if (synthesizedElectionResult is NeuraliumSynthesizedBlock.NeuraliumSynthesizedElectionResult neuraliumSynthesizedElectionResult && result is INeuraliumFinalElectionResults neuraliumFinalElectionResults)
            {
                neuraliumSynthesizedElectionResult.InfrastructureServiceFees = neuraliumFinalElectionResults.InfrastructureServiceFees ?? 0;

                foreach (AccountId delegateAccount in synthesizedElectionResult.DelegateAccounts)
                {
                    if (neuraliumFinalElectionResults.DelegateAccounts[delegateAccount] is INeuraliumDelegateResults neuraliumDelegateResults)
                    {
                        neuraliumSynthesizedElectionResult.DelegateBounties.Add(delegateAccount, neuraliumDelegateResults.BountyShare.Value);
                    }
                }

                foreach (var electedAccount in synthesizedElectionResult.ElectedAccounts)
                {
                    if (neuraliumFinalElectionResults.ElectedCandidates[electedAccount.Key] is INeuraliumElectedResults neuraliumElectedResults)
                    {
                        decimal tips = 0;

                        // let's sum up the tips we get!
                        foreach (TransactionId transationId in neuraliumElectedResults.Transactions)
                        {
                            if (blockConfirmedTransactions.ContainsKey(transationId))
                            {
                                if (blockConfirmedTransactions[transationId] is ITipTransaction tipTransaction)
                                {
                                    tips += tipTransaction.Tip;
                                }
                            }
                        }

                        neuraliumSynthesizedElectionResult.ElectedGains.Add(electedAccount.Key, (neuraliumElectedResults.BountyShare, tips));
                    }
                }
            }

            return(synthesizedElectionResult);
        }