public IActionResult GetGeneralInfo()
        {
            try
            {
                FederationWallet wallet = this.walletManager.GetWallet();

                if (wallet == null)
                {
                    return(this.NotFound("No federation wallet found."));
                }

                var model = new WalletGeneralInfoModel
                {
                    Network               = wallet.Network,
                    CreationTime          = wallet.CreationTime,
                    LastBlockSyncedHeight = wallet.LastBlockSyncedHeight,
                    ConnectedNodes        = this.connectionManager.ConnectedPeers.Count(),
                    ChainTip              = this.chainIndexer.Tip.Height,
                    IsChainSynced         = this.chainIndexer.IsDownloaded(),
                    IsDecrypted           = true
                };

                return(this.Json(model));
            }
            catch (Exception e)
            {
                this.logger.LogError("Exception occurred: {0}", e.ToString());
                return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString()));
            }
        }
        public IActionResult GetGeneralInfo([FromQuery] WalletName request)
        {
            // checks the request is valid
            if (!this.ModelState.IsValid)
            {
                var errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage));
                return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors)));
            }

            try
            {
                Wallet wallet = this.walletManager.GetWallet(request.Name);

                var model = new WalletGeneralInfoModel
                {
                    Network               = wallet.Network,
                    CreationTime          = wallet.CreationTime,
                    LastBlockSyncedHeight = wallet.AccountsRoot.Single(a => a.CoinType == this.coinType).LastBlockSyncedHeight,
                    ConnectedNodes        = this.connectionManager.ConnectedNodes.Count(),
                    ChainTip              = this.chain.Tip.Height,
                    IsDecrypted           = true
                };
                return(this.Json(model));
            }
            catch (Exception e)
            {
                return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString()));
            }
        }
        public IActionResult GetGeneralInfo([FromQuery] WalletName request)
        {
            Guard.NotNull(request, nameof(request));

            // checks the request is valid
            if (!this.ModelState.IsValid)
            {
                return(BuildErrorResponse(this.ModelState));
            }

            try
            {
                Wallet wallet = this.walletManager.GetWallet(request.Name);

                var model = new WalletGeneralInfoModel
                {
                    Network               = wallet.Network,
                    CreationTime          = wallet.CreationTime,
                    LastBlockSyncedHeight = wallet.AccountsRoot.Single(a => a.CoinType == this.coinType).LastBlockSyncedHeight,
                    ConnectedNodes        = this.connectionManager.ConnectedNodes.Count(),
                    ChainTip              = this.chain.Tip.Height,
                    IsChainSynced         = this.chain.IsDownloaded(),
                    IsDecrypted           = true
                };
                return(this.Json(model));
            }
            catch (Exception e)
            {
                this.logger.LogError("Exception occurred: {0}", e.ToString());
                return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString()));
            }
        }
Пример #4
0
        public void GetGeneralInfo()
        {
            this.connectionManager.ConnectedPeers.Returns(info => new NetworkPeerCollection());

            IActionResult          result = this.controller.GetGeneralInfo();
            WalletGeneralInfoModel model  = this.ActionResultToModel <WalletGeneralInfoModel>(result);

            Assert.Equal(this.fedWallet.CreationTime, model.CreationTime);
            Assert.Equal(this.fedWallet.LastBlockSyncedHeight, model.LastBlockSyncedHeight);
            Assert.Equal(this.fedWallet.Network, model.Network);
        }
 public WalletGeneralInfoClientEvent(WalletGeneralInfoModel generalInfoModel)
 {
     this.WalletName            = generalInfoModel.WalletName;
     this.Network               = generalInfoModel.Network;
     this.ChainTip              = generalInfoModel.ChainTip;
     this.ConnectedNodes        = generalInfoModel.ConnectedNodes;
     this.CreationTime          = generalInfoModel.CreationTime;
     this.IsDecrypted           = generalInfoModel.IsDecrypted;
     this.IsChainSynced         = generalInfoModel.IsChainSynced;
     this.LastBlockSyncedHeight = generalInfoModel.LastBlockSyncedHeight;
 }
        public IActionResult GetGeneralInfo([FromQuery] WalletName request)
        {
            Guard.NotNull(request, nameof(request));

            // checks the request is valid
            if (!this.ModelState.IsValid)
            {
                return(BuildErrorResponse(this.ModelState));
            }

            try
            {
                Wallet wallet = this.walletManager.GetWallet(request.Name);

                var model = new WalletGeneralInfoModel
                {
                    Network               = wallet.Network,
                    CreationTime          = wallet.CreationTime,
                    LastBlockSyncedHeight = wallet.AccountsRoot.Single(a => a.CoinType == this.coinType).LastBlockSyncedHeight,
                    ConnectedNodes        = this.connectionManager.ConnectedPeers.Count(),
                    ChainTip              = this.chain.Tip.Height,
                    IsChainSynced         = this.chain.IsDownloaded(),
                    IsDecrypted           = true
                };

                // Get the wallet's file path.
                (string folder, IEnumerable <string> fileNameCollection) = this.walletManager.GetWalletsFiles();
                string searchFile = Path.ChangeExtension(request.Name, this.walletManager.GetWalletFileExtension());
                string fileName   = fileNameCollection.FirstOrDefault(i => i.Equals(searchFile));
                if (folder != null && fileName != null)
                {
                    model.WalletFilePath = Path.Combine(folder, fileName);
                }

                return(this.Json(model));
            }
            catch (Exception e)
            {
                this.logger.LogError(e, "Exception occurred: {0}", e.StackTrace);
                if (e is System.FormatException)
                {
                    return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString()));
                }

                return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.InternalServerError, e.Message, e.ToString()));
            }
        }
Пример #7
0
        private async Task <bool> CheckWalletRequirementsAsync(NodeType nodeType, int apiPort)
        {
            var chainName     = nodeType == NodeType.MainChain ? "STRAX" : "CIRRUS";
            var amountToCheck = nodeType == NodeType.MainChain ? CollateralRequirement : FeeRequirement;
            var chainTicker   = nodeType == NodeType.MainChain ? this.mainchainNetwork.CoinTicker : this.sidechainNetwork.CoinTicker;

            Console.WriteLine($"Please enter the name of the {chainName} wallet that contains the required collateral of {amountToCheck} {chainTicker}:");

            var walletName = Console.ReadLine();

            WalletInfoModel walletInfoModel = await $"http://localhost:{apiPort}/api".AppendPathSegment("Wallet/list-wallets").GetJsonAsync <WalletInfoModel>();

            if (walletInfoModel.WalletNames.Contains(walletName))
            {
                Console.WriteLine($"SUCCESS: Wallet with name '{chainName}' found.");
            }
            else
            {
                Console.WriteLine($"{chainName} wallet with name '{walletName}' does not exist.");

                ConsoleKeyInfo key;
                do
                {
                    Console.WriteLine($"Would you like to restore you {chainName} wallet that holds the required amount of {amountToCheck} {chainTicker} now? Enter (Y) to continue or (N) to exit.");
                    key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Y || key.Key == ConsoleKey.N)
                    {
                        break;
                    }
                } while (true);

                if (key.Key == ConsoleKey.N)
                {
                    Console.WriteLine($"You have chosen to exit the registration script.");
                    return(false);
                }

                if (!await RestoreWalletAsync(apiPort, chainName, walletName))
                {
                    return(false);
                }
            }

            // Check wallet height (sync) status.
            do
            {
                var walletNameRequest = new WalletName()
                {
                    Name = walletName
                };
                WalletGeneralInfoModel walletInfo = await $"http://localhost:{apiPort}/api".AppendPathSegment("wallet/general-info").SetQueryParams(walletNameRequest).GetJsonAsync <WalletGeneralInfoModel>();
                StatusModel            blockModel = await $"http://localhost:{apiPort}/api".AppendPathSegment("node/status").GetJsonAsync <StatusModel>();

                if (walletInfo.LastBlockSyncedHeight > (blockModel.ConsensusHeight - 50))
                {
                    Console.WriteLine($"{chainName} wallet is synced.");
                    break;
                }

                Console.WriteLine($"Syncing {chainName} wallet, current height {walletInfo.LastBlockSyncedHeight}...");
                await Task.Delay(TimeSpan.FromSeconds(3));
            } while (true);

            // Check wallet balance.
            try
            {
                var walletBalanceRequest = new WalletBalanceRequest()
                {
                    WalletName = walletName
                };
                WalletBalanceModel walletBalanceModel = await $"http://localhost:{apiPort}/api"
                                                        .AppendPathSegment("wallet/balance")
                                                        .SetQueryParams(walletBalanceRequest)
                                                        .GetJsonAsync <WalletBalanceModel>();

                if (walletBalanceModel.AccountsBalances[0].SpendableAmount / 100000000 > amountToCheck)
                {
                    Console.WriteLine($"SUCCESS: The {chainName} wallet contains the required amount of {amountToCheck} {chainTicker}.");
                    return(true);
                }

                Console.WriteLine($"ERROR: The {chainName} wallet does not contain the required amount of {amountToCheck} {chainTicker}.");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"ERROR: An exception occurred trying to check the wallet balance: {ex}");
            }

            return(false);
        }