Пример #1
0
        public static async Task <ApiResponse> EstimateTxFeeForSendToAddress(string toAddress, long amount, string comment = "", string commentTo = "", bool subtractFeeFromAmount = false)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                TxFeeForSend fee   = new TxFeeForSend();
                Transaction  trans = new Transaction();

                TxFeeForSendOM result = await trans.EstimateTxFeeForSendToAddress(toAddress, amount, comment, commentTo, subtractFeeFromAmount);

                if (result != null)
                {
                    fee.TotalSize   = result.TotalSize;
                    fee.TotalFee    = result.TotalFee;
                    response.Result = Newtonsoft.Json.Linq.JToken.FromObject(fee);
                }
                else
                {
                    response.Result = null;
                }
            }
            catch (ApiCustomException ex)
            {
                Logger.Singleton.Error(ex.ToString());
                response.Error = new ApiError(ex.ErrorCode, ex.ToString());
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error(ex.ToString());
                response.Error = new ApiError(ex.HResult, ex.ToString());
            }
            return(response);
        }
Пример #2
0
        public async Task EstimateTxFeeForSendToAddress()
        {
            Transaction    tran      = new Transaction();
            string         address   = "1No2SahjFuguswiSvHv1DqotTRdMNs4FH";
            long           amount    = 100000000000;
            string         commentTo = "Join";
            TxFeeForSendOM om        = await tran.EstimateTxFeeForSendToAddress(address, amount, "", commentTo, false);

            Assert.IsNotNull(om);
        }
Пример #3
0
        public async Task EstimateTxFeeForSendMany()
        {
            Transaction tran        = new Transaction();
            string      fromAccount = "1B7CXXyT2KQSHprzbprQDXnmkFEUTJU7yS";

            SendManyOM[] om = new SendManyOM[] { new SendManyOM {
                                                     Address = "1317nkscoSnkZnGdFMqVawjJv3xxU5vyfb", Tag = "John", Amount = 100000000000
                                                 }, new SendManyOM {
                                                     Address = "1No2SahjFuguswiSvHv1DqotTRdMNs4FH", Tag = null, Amount = 100000000000
                                                 } };
            string[]       subtractFeeFromAmount = new string[] { "1317nkscoSnkZnGdFMqVawjJv3xxU5vyfb", "1No2SahjFuguswiSvHv1DqotTRdMNs4FH" };
            TxFeeForSendOM result = await tran.EstimateTxFeeForSendMany(fromAccount, om, subtractFeeFromAmount);

            Assert.IsNotNull(result);
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fromAccount"></param>
        /// <param name="many"></param>
        /// <param name="subtractFeeFromAmount"></param>
        /// <returns></returns>
        public async Task <TxFeeForSendOM> EstimateTxFeeForSendMany(string fromAccount, SendManyOM[] many, string[] subtractFeeFromAmount = null)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient  client  = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json");
            RpcRequest request = RpcRequest.WithParameterList("EstimateTxFeeForSendMany", new List <object> {
                fromAccount, many, subtractFeeFromAmount
            }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
            TxFeeForSendOM responseValue = response.GetResult <TxFeeForSendOM>();

            return(responseValue);
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="toAddress"></param>
        /// <param name="amount"></param>
        /// <param name="comment"></param>
        /// <param name="commentTo"></param>
        /// <param name="subtractFeeFromAmount"></param>
        /// <returns></returns>
        public async Task <TxFeeForSendOM> EstimateTxFeeForSendToAddress(string toAddress, long amount, string comment = "", string commentTo = "", bool subtractFeeFromAmount = false)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient  client  = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json");
            RpcRequest request = RpcRequest.WithParameterList("EstimateTxFeeForSendToAddress", new List <object> {
                toAddress, amount, comment, commentTo, subtractFeeFromAmount
            }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

            if (response.HasError)
            {
                throw new ApiCustomException(response.Error.Code, response.Error.Message);
            }
            TxFeeForSendOM responseValue = response.GetResult <TxFeeForSendOM>();

            return(responseValue);
        }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fromAccount"></param>
        /// <param name="many"></param>
        /// <param name="subtractFeeFromAmount"></param>
        /// <returns></returns>
        public static async Task <ApiResponse> EstimateTxFeeForSendMany(string fromAccount, SendManyModel[] many, string[] subtractFeeFromAmount)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                Transaction       trans  = new Transaction();
                TxFeeForSend      fee    = new TxFeeForSend();
                List <SendManyOM> omList = new List <SendManyOM>();
                for (int i = 0; i < many.Length; i++)
                {
                    omList.Add(new SendManyOM {
                        Address = many[i].Address, Amount = many[i].Amount, Tag = many[i].Tag
                    });
                }
                SendManyOM[] om = omList.ToArray();

                TxFeeForSendOM result = await trans.EstimateTxFeeForSendMany(fromAccount, om, subtractFeeFromAmount);

                if (result != null)
                {
                    fee.TotalFee    = result.TotalFee;
                    fee.TotalSize   = result.TotalSize;
                    response.Result = Newtonsoft.Json.Linq.JToken.FromObject(fee);
                }
                else
                {
                    response.Result = null;
                }
            }
            catch (ApiCustomException ex)
            {
                Logger.Singleton.Error(ex.ToString());
                response.Error = new ApiError(ex.ErrorCode, ex.ToString());
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error(ex.ToString());
                response.Error = new ApiError(ex.HResult, ex.ToString());
            }
            return(response);
        }