Exemplo n.º 1
0
        public override IWalletTransactionHistoryFileInfo UpdateLocalTransactionHistoryEntry(TransactionId transactionId, WalletTransactionHistory.TransactionStatuses status)
        {
            this.EnsureWalletLoaded();
            IWalletTransactionHistoryFileInfo historyEntry = base.UpdateLocalTransactionHistoryEntry(transactionId, status);

            IWalletAccount account = this.WalletFileInfo.WalletBase.Accounts.Values.SingleOrDefault(a => (a.GetAccountId() == transactionId.Account) || (a.PresentationTransactionId == transactionId));

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

            if (historyEntry is INeuraliumWalletTransactionHistoryFileInfo neuraliumWalletTransactionHistoryFileInfo && this.WalletFileInfo.Accounts[account.AccountUuid] is INeuraliumAccountFileInfo neuraliumAccountFileInfo)
            {
                INeuraliumWalletTimelineFileInfo neuraliumWalletTimelineFileInfo = neuraliumAccountFileInfo.WalletTimelineFileInfo;

                if (status == WalletTransactionHistory.TransactionStatuses.Confirmed)
                {
                    // now let's add a neuralium timeline entry
                    neuraliumWalletTimelineFileInfo.ConfirmLocalTimelineEntry(transactionId);
                }
                else if (status == WalletTransactionHistory.TransactionStatuses.Rejected)
                {
                    // now let's add a neuralium timeline entry
                    neuraliumWalletTimelineFileInfo.RemoveLocalTimelineEntry(transactionId);
                }
            }

            return(historyEntry);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        private void InsertNeuraliumTransactionTimelineEntry(ITransaction transaction, AccountId targetAccountId, INeuraliumWalletTransactionHistory neuraliumWalletTransactionHistory)
        {
            if ((neuraliumWalletTransactionHistory.Amount == 0) && (neuraliumWalletTransactionHistory.Tip == 0))
            {
                // this transaction is most probably not a token influencing transaction. let's ignore 0 values
                return;
            }

            // this is an incomming transaction, now let's add a neuralium timeline entry

            IWalletAccount account = this.WalletFileInfo.WalletBase.Accounts.Values.SingleOrDefault(a => a.GetAccountId() == targetAccountId);

            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 = this.serviceSet.TimeService.GetTimestampDateTime(transaction.TransactionId.Timestamp.Value, this.centralCoordinator.ChainComponentProvider.ChainStateProvider.ChainInception);
                neuraliumWalletTimeline.Amount    = neuraliumWalletTransactionHistory.Amount;
                neuraliumWalletTimeline.Tips      = 0;

                neuraliumWalletTimeline.TransactionId = transaction.TransactionId.ToString();

                bool local = targetAccountId == transaction.TransactionId.Account;
                neuraliumWalletTimeline.SenderAccountId    = transaction.TransactionId.Account;
                neuraliumWalletTimeline.RecipientAccountId = targetAccountId;

                decimal total = this.GetAccountBalance(targetAccountId, false).Total;

                if (local)
                {
                    // in most cases, transactions we make wil be debits
                    neuraliumWalletTimeline.Direction = NeuraliumWalletTimeline.MoneratyTransactionTypes.Debit;
                    neuraliumWalletTimeline.Total     = total - neuraliumWalletTimeline.Amount;
                    neuraliumWalletTimeline.Tips      = neuraliumWalletTransactionHistory.Tip;

#if TESTNET || DEVNET
                    if (transaction is INeuraliumRefillNeuraliumsTransaction)
                    {
                        neuraliumWalletTimeline.Total      = total + neuraliumWalletTimeline.Amount;
                        neuraliumWalletTimeline.Direction  = NeuraliumWalletTimeline.MoneratyTransactionTypes.Credit;
                        neuraliumWalletTimeline.CreditType = NeuraliumWalletTimeline.CreditTypes.Tranasaction;
                    }
#endif

                    neuraliumWalletTimeline.Total    -= neuraliumWalletTimeline.Tips;
                    neuraliumWalletTimeline.Confirmed = false;
                }
                else
                {
                    neuraliumWalletTimeline.Total = total + neuraliumWalletTimeline.Amount;

                    neuraliumWalletTimeline.Confirmed  = true;
                    neuraliumWalletTimeline.Direction  = NeuraliumWalletTimeline.MoneratyTransactionTypes.Credit;
                    neuraliumWalletTimeline.CreditType = NeuraliumWalletTimeline.CreditTypes.Tranasaction;
                }

                neuraliumWalletTimelineFileInfo.InsertTimelineEntry(neuraliumWalletTimeline);
            }
        }