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()));
            }
        }
        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()));
            }
        }
예제 #3
0
 public BalanceSelector(WalletName walletName)
 {
     if (walletName == null)
     {
         throw new ArgumentNullException("walletName");
     }
     _Str = "W-" + walletName;
 }
        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()));
            }
        }
예제 #5
0
        public IActionResult GetBalance([FromQuery] WalletName model)
        {
            // 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
            {
                return(this.Json(this.walletWrapper.GetBalance(model.Name)));
            }
            catch (Exception e)
            {
                return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString()));
            }
        }
예제 #6
0
 public Task <IActionResult> GetGeneralInfo([FromQuery] WalletName request,
                                            CancellationToken cancellationToken = default(CancellationToken))
 {
     return(this.Execute(request, cancellationToken, async(req, token) =>
                         this.Json(await this.walletService.GetWalletGeneralInfo(req.Name, token))));
 }
예제 #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);
        }
예제 #8
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (CoinType != null)
         {
             hashCode = hashCode * 59 + CoinType.GetHashCode();
         }
         if (WalletName != null)
         {
             hashCode = hashCode * 59 + WalletName.GetHashCode();
         }
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (Symbol != null)
         {
             hashCode = hashCode * 59 + Symbol.GetHashCode();
         }
         if (WalletSymbol != null)
         {
             hashCode = hashCode * 59 + WalletSymbol.GetHashCode();
         }
         if (WalletType != null)
         {
             hashCode = hashCode * 59 + WalletType.GetHashCode();
         }
         if (TransactionFee != null)
         {
             hashCode = hashCode * 59 + TransactionFee.GetHashCode();
         }
         if (Precision != null)
         {
             hashCode = hashCode * 59 + Precision.GetHashCode();
         }
         if (BackingCoinType != null)
         {
             hashCode = hashCode * 59 + BackingCoinType.GetHashCode();
         }
         if (SupportsOutputMemos != null)
         {
             hashCode = hashCode * 59 + SupportsOutputMemos.GetHashCode();
         }
         if (Restricted != null)
         {
             hashCode = hashCode * 59 + Restricted.GetHashCode();
         }
         if (Authorized != null)
         {
             hashCode = hashCode * 59 + Authorized.GetHashCode();
         }
         if (NotAuthorizedReasons != null)
         {
             hashCode = hashCode * 59 + NotAuthorizedReasons.GetHashCode();
         }
         return(hashCode);
     }
 }
예제 #9
0
        /// <summary>
        /// Returns true if CoinInfo instances are equal
        /// </summary>
        /// <param name="other">Instance of CoinInfo to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(CoinInfo other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     CoinType == other.CoinType ||
                     CoinType != null &&
                     CoinType.Equals(other.CoinType)
                     ) &&
                 (
                     WalletName == other.WalletName ||
                     WalletName != null &&
                     WalletName.Equals(other.WalletName)
                 ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     Symbol == other.Symbol ||
                     Symbol != null &&
                     Symbol.Equals(other.Symbol)
                 ) &&
                 (
                     WalletSymbol == other.WalletSymbol ||
                     WalletSymbol != null &&
                     WalletSymbol.Equals(other.WalletSymbol)
                 ) &&
                 (
                     WalletType == other.WalletType ||
                     WalletType != null &&
                     WalletType.Equals(other.WalletType)
                 ) &&
                 (
                     TransactionFee == other.TransactionFee ||
                     TransactionFee != null &&
                     TransactionFee.Equals(other.TransactionFee)
                 ) &&
                 (
                     Precision == other.Precision ||
                     Precision != null &&
                     Precision.Equals(other.Precision)
                 ) &&
                 (
                     BackingCoinType == other.BackingCoinType ||
                     BackingCoinType != null &&
                     BackingCoinType.Equals(other.BackingCoinType)
                 ) &&
                 (
                     SupportsOutputMemos == other.SupportsOutputMemos ||
                     SupportsOutputMemos != null &&
                     SupportsOutputMemos.Equals(other.SupportsOutputMemos)
                 ) &&
                 (
                     Restricted == other.Restricted ||
                     Restricted != null &&
                     Restricted.Equals(other.Restricted)
                 ) &&
                 (
                     Authorized == other.Authorized ||
                     Authorized != null &&
                     Authorized.Equals(other.Authorized)
                 ) &&
                 (
                     NotAuthorizedReasons == other.NotAuthorizedReasons ||
                     NotAuthorizedReasons != null &&
                     NotAuthorizedReasons.SequenceEqual(other.NotAuthorizedReasons)
                 ));
        }