Ejemplo n.º 1
0
        public static async Task <ApiResponse> EstimateRawTransaction(SendRawTransactionInputsIM[] senders, SendRawTransactionOutputsIM[] receivers, string changeAddress, long feeRate)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                Transaction              trans  = new Transaction();
                TxFeeForSend             txFee  = new TxFeeForSend();
                EstimateRawTransactionOM result = await trans.EstimateRawTransaction(senders, receivers, changeAddress, feeRate);

                if (result != null)
                {
                    txFee.TotalFee  = result.totalFee;
                    txFee.TotalSize = result.totalSize;
                    txFee.Change    = result.Change;
                    response.Result = Newtonsoft.Json.Linq.JToken.FromObject(txFee);
                }
                else
                {
                    response.Result = null;
                }
            }
            catch (ApiCustomException ex)
            {
                Logger.Singleton.Error(ex.ToString());
                var errorMsg = string.IsNullOrEmpty(ex.ErrorMsg) ? ex.ToString() : ex.ErrorMsg;
                response.Error = new ApiError(ex.ErrorCode, errorMsg);
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error(ex.ToString());
                response.Error = new ApiError(ex.HResult, ex.ToString());
            }
            return(response);
        }
Ejemplo n.º 2
0
        public async Task <EstimateRawTransactionOM> EstimateRawTransaction(SendRawTransactionInputsIM[] senders, SendRawTransactionOutputsIM[] receivers, string changeAddress, long feeRate)
        {
            AuthenticationHeaderValue authHeaderValue = null;
            RpcClient  client  = new RpcClient(new Uri(WalletNetwork.NetWork), authHeaderValue, null, null, "application/json");
            RpcRequest request = RpcRequest.WithParameterList("EstimateRawTransaction", new List <object> {
                senders, receivers, changeAddress, feeRate
            }, 1);
            RpcResponse response = await client.SendRequestAsync(request);

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

            return(responseValue);
        }