Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public override void UpdateLocalTransactionCacheEntry(TransactionId transactionId, WalletTransactionCache.TransactionStatuses status, long gossipMessageHash)
        {
            base.UpdateLocalTransactionCacheEntry(transactionId, status, gossipMessageHash);

            AccountId targetAccountId = transactionId.Account;

            TotalAPI total = this.GetAccountBalance(targetAccountId, true);

            this.centralCoordinator.PostSystemEvent(NeuraliumSystemEventGenerator.NeuraliumAccountTotalUpdated(targetAccountId.SequenceId, targetAccountId.AccountType, total));
        }
Ejemplo n.º 3
0
        public override void InsertLocalTransactionCacheEntry(ITransactionEnvelope transactionEnvelope)
        {
            base.InsertLocalTransactionCacheEntry(transactionEnvelope);

            AccountId targetAccountId = transactionEnvelope.Contents.Uuid.Account;

            TotalAPI total = this.GetAccountBalance(targetAccountId, true);

            this.centralCoordinator.PostSystemEvent(NeuraliumSystemEventGenerator.NeuraliumAccountTotalUpdated(targetAccountId.SequenceId, targetAccountId.AccountType, total));
        }
        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));
                    });
                }
            }
        }
Ejemplo n.º 5
0
        public static SystemEventGenerator NeuraliumAccountTotalUpdated(long accountSequenceId, Enums.AccountTypes accountType, TotalAPI total)
        {
            NeuraliumSystemEventGenerator generator = new NeuraliumSystemEventGenerator();

            generator.EventType  = NeuraliumBlockchainSystemEventTypes.NeuraliumInstance.AccountTotalUpdated;
            generator.Parameters = new object[] { new { AccountId = new AccountId(accountSequenceId, accountType).ToString(), Total = total } };

            return(generator);
        }