예제 #1
0
        public TotalAPI GetAccountBalance(Guid accountUuid, bool includeReserved)
        {
            this.EnsureWalletLoaded();

            TotalAPI result = new TotalAPI();

            if (!this.WalletFileInfo.Accounts.ContainsKey(accountUuid))
            {
                return(result);
            }

            IWalletAccountSnapshot accountBase = this.WalletFileInfo.Accounts[accountUuid].WalletSnapshotInfo.WalletAccountSnapshot;

            if (accountBase is INeuraliumWalletAccountSnapshot walletAccountSnapshot)
            {
                result.Total = walletAccountSnapshot.Balance;
            }

            if (includeReserved)
            {
                IWalletTransactionCacheFileInfo accountCacheBase = this.WalletFileInfo.Accounts[accountUuid].WalletTransactionCacheInfo;

                if (accountCacheBase is NeuraliumWalletTransactionCacheFileInfo neuraliumWalletTransactionCacheFileInfo)
                {
                    (decimal debit, decimal credit, decimal tip)results = neuraliumWalletTransactionCacheFileInfo.GetTransactionAmounts();

                    result.ReservedDebit  = results.debit + results.tip;
                    result.ReservedCredit = results.credit;
                }
            }

            return(result);
        }
        protected override void LocalAccountSnapshotEntryChanged(Dictionary <AccountId, List <Action> > changedLocalAccounts, IAccountSnapshot newEntry, IWalletAccountSnapshot original)
        {
            base.LocalAccountSnapshotEntryChanged(changedLocalAccounts, newEntry, original);

            if (newEntry is INeuraliumAccountSnapshot neuraliumAccountSnapshot && original is INeuraliumWalletAccountSnapshot neuraliumWalletAccountSnapshot)
            {
                if (neuraliumAccountSnapshot.Balance != neuraliumWalletAccountSnapshot.Balance)
                {
                    AccountId accountId = newEntry.AccountId.ToAccountId();

                    this.InsertChangedLocalAccountsEvent(changedLocalAccounts, accountId, () => {
                        // seems our total was updated for this account

                        TotalAPI total = this.CentralCoordinator.ChainComponentProvider.WalletProvider.GetAccountBalance(accountId, true);
                        this.CentralCoordinator.PostSystemEvent(NeuraliumSystemEventGenerator.NeuraliumAccountTotalUpdated(accountId.SequenceId, accountId.AccountType, total));
                    });
                }
            }
        }