Example #1
0
        protected override IEnumerable <IClientEvent> GetMessages()
        {
            WalletGeneralInfoClientEvent clientEvent = null;

            foreach (string walletName in this.walletManager.GetWalletsNames())
            {
                try
                {
                    Wallet.Wallet wallet = this.walletManager.GetWallet(walletName);

                    clientEvent = new WalletGeneralInfoClientEvent
                    {
                        WalletName            = walletName,
                        Network               = wallet.Network,
                        CreationTime          = wallet.CreationTime,
                        LastBlockSyncedHeight = wallet.AccountsRoot.Single().LastBlockSyncedHeight,
                        ConnectedNodes        = this.connectionManager.ConnectedPeers.Count(),
                        ChainTip              = this.chainIndexer.Tip.Height,
                        IsChainSynced         = this.chainIndexer.IsDownloaded(),
                        IsDecrypted           = true
                    };

                    // Get the wallet's file path.
                    (string folder, IEnumerable <string> fileNameCollection) = this.walletManager.GetWalletsFiles();
                    string searchFile = Path.ChangeExtension(walletName, this.walletManager.GetWalletFileExtension());
                    string fileName   = fileNameCollection.FirstOrDefault(i => i.Equals(searchFile));
                    if (!string.IsNullOrEmpty(folder) && !string.IsNullOrEmpty(fileName))
                    {
                        clientEvent.WalletFilePath = Path.Combine(folder, fileName);
                    }
                }
                catch (Exception e)
                {
                    this.logger.LogError(e, "Exception occurred: {0}");
                }
            }

            if (null != clientEvent)
            {
                yield return(clientEvent);
            }
        }
        private async Task <WalletGeneralInfoClientEvent> GetWalletInformationAsync(string walletName, CancellationToken cancellationToken)
        {
            WalletGeneralInfoClientEvent clientEvent = null;

            try
            {
                Task <WalletGeneralInfoModel> generalInfo = this.walletService.GetWalletGeneralInfo(walletName, cancellationToken);
                Task <WalletBalanceModel>     balances    = this.walletService.GetBalance(walletName, null, this.includeAddressBalances, cancellationToken);

                await Task.WhenAll(generalInfo, balances);

                clientEvent = new WalletGeneralInfoClientEvent(generalInfo.Result)
                {
                    AccountsBalances = balances.Result.AccountsBalances
                };
            }
            catch (Exception e)
            {
                this.logger.LogError(e, "Exception occurred: {0}");
            }

            return(clientEvent);
        }
        protected override IEnumerable <IClientEvent> GetMessages()
        {
            foreach (string walletName in this.walletManager.GetWalletsNames())
            {
                WalletGeneralInfoClientEvent clientEvent = null;
                try
                {
                    Wallet.Wallet wallet = this.walletManager.GetWallet(walletName);
                    IEnumerable <AccountBalance> balances             = this.walletManager.GetBalances(walletName);
                    IList <AccountBalanceModel>  accountBalanceModels = new List <AccountBalanceModel>();
                    foreach (var balance in balances)
                    {
                        HdAccount account = balance.Account;

                        var accountBalanceModel = new AccountBalanceModel
                        {
                            CoinType          = (CoinType)wallet.Network.Consensus.CoinType,
                            Name              = account.Name,
                            HdPath            = account.HdPath,
                            AmountConfirmed   = balance.AmountConfirmed,
                            AmountUnconfirmed = balance.AmountUnconfirmed,
                            SpendableAmount   = balance.SpendableAmount,
                            Addresses         = account.GetCombinedAddresses().Select(address =>
                            {
                                (Money confirmedAmount, Money unConfirmedAmount) = address.GetBalances(account.IsNormalAccount());
                                return(new AddressModel
                                {
                                    Address = address.Address,
                                    IsUsed = address.Transactions.Any(),
                                    IsChange = address.IsChangeAddress(),
                                    AmountConfirmed = confirmedAmount,
                                    AmountUnconfirmed = unConfirmedAmount
                                });
                            })
                        };

                        accountBalanceModels.Add(accountBalanceModel);
                    }

                    clientEvent = new WalletGeneralInfoClientEvent
                    {
                        WalletName            = walletName,
                        Network               = wallet.Network,
                        CreationTime          = wallet.CreationTime,
                        LastBlockSyncedHeight = wallet.AccountsRoot.Single().LastBlockSyncedHeight,
                        ConnectedNodes        = this.connectionManager.ConnectedPeers.Count(),
                        ChainTip              = this.chainIndexer.Tip.Height,
                        IsChainSynced         = this.chainIndexer.IsDownloaded(),
                        IsDecrypted           = true,
                        AccountsBalances      = accountBalanceModels
                    };

                    // Get the wallet's file path.
                    (string folder, IEnumerable <string> fileNameCollection) = this.walletManager.GetWalletsFiles();
                    string searchFile =
                        Path.ChangeExtension(walletName, this.walletManager.GetWalletFileExtension());
                    string fileName = fileNameCollection.FirstOrDefault(i => i.Equals(searchFile));
                    if (!string.IsNullOrEmpty(folder) && !string.IsNullOrEmpty(fileName))
                    {
                        clientEvent.WalletFilePath = Path.Combine(folder, fileName);
                    }
                }
                catch (Exception e)
                {
                    this.logger.LogError(e, "Exception occurred: {0}");
                }

                if (null != clientEvent)
                {
                    yield return(clientEvent);
                }
            }
        }