}     //end of public async Task<GetRecievedAddressInfoResponse> GetRecievedAddressBalence(string address)

        /// <summary>
        /// Gets The Balance of The Wallet
        /// </summary>
        /// <param name="walletName">Name of Wallet</param>
        /// <param name="account">Name of Account (Leave Blank for All)</param>
        /// <returns></returns>
        public async Task <GetWalletBalenceResponse> GetWalletBalance(string walletName, string account = null)
        {
            try
            {
                Guard.Null(walletName, nameof(walletName), "Unable To Get Wallet Addresses, Provided Wallet Name Is NULL/Empty!");

                StringBuilder queryURL = new StringBuilder($"api/Wallet/balance?WalletName={walletName.Trim()}");

                if (!string.IsNullOrWhiteSpace(account))
                {
                    queryURL.Append($"&AccountName={Uri.EscapeDataString(account.Trim())}");
                }

                GetWalletBalenceResponse response = await base.SendGet <GetWalletBalenceResponse>(queryURL.ToString());

                Guard.Null(response, nameof(response), "'api/Wallet/balance' API Response Was Null!");

                return(response);
            }
            catch (Exception ex)
            {
                Logger.Fatal($"An Error '{ex.Message}' Occured When Getting Ballence For Wallet '{walletName.Trim()}'!", ex);
                throw;
            } //end of try-catch
        }     //end of public async Task<string> GetWalletBalence(string walletName, string accountName = null)
Exemplo n.º 2
0
        }     //end of public async Task<GetWalletHistoryResponse> GetWalletHistory(string walletName, string account = null, int skip = -1, int take = -1, string searchQuery = null)

        /// <summary>
        ///     Build a TX Hex String Ready To Be Broadcast on The Network
        /// </summary>
        /// <param name="walletName">Wallet Name</param>
        /// <param name="account">Account Name</param>
        /// <param name="password">Wallet Password</param>
        /// <param name="destinationAddress">Destination Address</param>
        /// <param name="amount">Amount To Send</param>
        /// <param name="allowUnconfirmed">Include Unconfirmed TX's</param>
        /// <param name="shuffleCoins">Coin Control?</param>
        /// <returns>TX Hex String</returns>
        public async Task <BuildTXResponse> BuildTransaction(string walletName, string account, string password,
                                                             string destinationAddress, long amount, bool allowUnconfirmed = false, bool shuffleCoins = true)
        {
            try
            {
                Guard.Null(walletName, nameof(walletName), "Unable To Build TX, Provided Wallet Name Is NULL/Empty!");
                Guard.Null(account, nameof(account), "Unable To Build TX, Provided Account Name Is NULL/Empty!");
                Guard.Null(password, nameof(password), "Unable To Build TX, Provided Password Is NULL/Empty!");
                Guard.AssertTrue(await ValidateAddress(destinationAddress),
                                 $"Unable To Build TX, Destination Address '{destinationAddress.Trim()}' Is Not Valid!");

                GetWalletBalenceResponse accountBalence = await GetWalletBalance(walletName, account);

                Guard.Null(accountBalence, nameof(accountBalence),
                           $"Unable To Build TX, Account '{account}' Balence Request Was NULL/Empty!");

                Guard.AssertTrue(accountBalence.balances[0].amountConfirmed > 0,
                                 $"Unable To Build TX, Insufficient Funds! Trying To Send '{amount}' When Account Only Has '{accountBalence.balances[0].amountConfirmed}'");

                BuildTXRequest buildRequest = new BuildTXRequest
                {
                    feeAmount   = "0",
                    password    = password,
                    walletName  = walletName,
                    accountName = account,
                    recipients  = new[]
                    { new x42Recipient {
                          destinationAddress = destinationAddress, amount = amount.ToString()
                      } },
                    allowUnconfirmed = allowUnconfirmed,
                    shuffleOutputs   = shuffleCoins
                };

                BuildTXResponse response =
                    await base.SendPostJSON <BuildTXResponse>("api/Wallet/build-transaction", buildRequest);

                Guard.Null(response, nameof(response), "'api/Wallet/build-transaction' API Response Was Null!");

                return(response);
            }
            catch (Exception ex)
            {
                logger.LogCritical(
                    $"An Error '{ex.Message}' Occured When Building A TX! [Wallet: '{walletName.Trim()}', Account: '{account.Trim()}', To: '{destinationAddress.Trim()}', Amount: '{amount}'",
                    ex);
                throw;
            }
        }
Exemplo n.º 3
0
        }     //end of private void ProcessAccountTX(string wallet, string account)

        /// <summary>
        /// Gets The Balance of The Wallet
        /// </summary>
        /// <param name="WalletName">Wallet Name</param>
        /// <param name="accountName">Account Name (Optional)</param>
        /// <returns>2 Balences, First Is Confirmed, Second Is Unconfirmed</returns>
        public async Task <Tuple <decimal, decimal> > GetWalletBalance(string walletName, string accountName = null)
        {
            GetWalletBalenceResponse walletBalance = await _RestClient.GetWalletBalance(walletName, accountName);

            Guard.Null(walletBalance, nameof(walletBalance), $"Node '{Name}' ({Address}:{Port}) An Error Occured When Trying To Get The Wallet Balance of Wallet '{walletName}' and Account '{accountName}'");

            decimal confirmedBalance   = 0;
            decimal unConfirmedBalance = 0;

            foreach (AccountBalance accountBalence in walletBalance.balances)
            {
                confirmedBalance   += accountBalence.amountConfirmed.ParseAPIAmount();
                unConfirmedBalance += accountBalence.amountUnconfirmed.ParseAPIAmount();
            }//end of foreach (AccountBalance accountBalence in walletBalence.balances)

            return(new Tuple <decimal, decimal>(confirmedBalance, unConfirmedBalance));
        } //end of public decimal GetWalletBalence(string WalletName, string accountName)