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);
        }
        public override IWalletElectionsHistory InsertElectionsHistoryEntry(SynthesizedBlock.SynthesizedElectionResult electionResult, AccountId electedAccountId)
        {
            this.EnsureWalletLoaded();
            IWalletElectionsHistory historyEntry = base.InsertElectionsHistoryEntry(electionResult, electedAccountId);

            // now let's add a neuralium timeline entry
            if (historyEntry is INeuraliumWalletElectionsHistory neuraliumWalletElectionsHistory && electionResult is NeuraliumSynthesizedBlock.NeuraliumSynthesizedElectionResult neuraliumSynthesizedElectionResult)
            {
                IWalletAccount account = this.WalletFileInfo.WalletBase.Accounts.Values.SingleOrDefault(a => a.GetAccountId() == electedAccountId);

                if (account == null)
                {
                    throw new ApplicationException("Invalid account");
                }

                if (this.WalletFileInfo.Accounts[account.AccountUuid] is INeuraliumAccountFileInfo neuraliumAccountFileInfo)
                {
                    NeuraliumWalletTimeline          neuraliumWalletTimeline         = new NeuraliumWalletTimeline();
                    INeuraliumWalletTimelineFileInfo neuraliumWalletTimelineFileInfo = neuraliumAccountFileInfo.WalletTimelineFileInfo;

                    neuraliumWalletTimeline.Timestamp = neuraliumSynthesizedElectionResult.Timestamp;
                    neuraliumWalletTimeline.Amount    = neuraliumSynthesizedElectionResult.ElectedGains[electedAccountId].bountyShare;
                    neuraliumWalletTimeline.Tips      = neuraliumSynthesizedElectionResult.ElectedGains[electedAccountId].tips;

                    neuraliumWalletTimeline.RecipientAccountId = electedAccountId;
                    neuraliumWalletTimeline.Direction          = NeuraliumWalletTimeline.MoneratyTransactionTypes.Credit;
                    neuraliumWalletTimeline.CreditType         = NeuraliumWalletTimeline.CreditTypes.Election;

                    neuraliumWalletTimeline.Total = this.GetAccountBalance(electedAccountId, false).Total + neuraliumWalletTimeline.Amount + neuraliumWalletTimeline.Tips;

                    neuraliumWalletTimelineFileInfo.InsertTimelineEntry(neuraliumWalletTimeline);
                }
            }

            return(historyEntry);
        }
 protected override void FillWalletElectionsHistoryEntry(IWalletElectionsHistory walletElectionsHistory, SynthesizedBlock.SynthesizedElectionResult electionResult, AccountId electedAccountId)
 {
     if (walletElectionsHistory is INeuraliumWalletElectionsHistory neuraliumWalletElectionsHistory && electionResult is NeuraliumSynthesizedBlock.NeuraliumSynthesizedElectionResult neuraliumSynthesizedElectionResult)
     {
         neuraliumWalletElectionsHistory.Bounty = neuraliumSynthesizedElectionResult.ElectedGains[electedAccountId].bountyShare;
         neuraliumWalletElectionsHistory.Tips   = neuraliumSynthesizedElectionResult.ElectedGains[electedAccountId].tips;
     }
 }