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); }
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); }
public async Task TestEstimateTxFeeForSendToAddress() { string address = "fiiitCPyohiEPn9q11AXCdvVDouoVvgojXBcVj"; long amount = 100000000000; string commentTo = "Join"; ApiResponse response = await TransactionApi.EstimateTxFeeForSendToAddress(address, amount, "", commentTo, false); Assert.IsFalse(response.HasError); TxFeeForSend result = response.GetResult <TxFeeForSend>(); Assert.IsNotNull(result); }
public async Task TestEstimateTxFeeForSendMany() { string fromAccount = "fiiitCPyohiEPn9q11AXCdvVDouoVvgojXBcVj"; SendManyModel[] om = new SendManyModel[] { new SendManyModel { Address = "fiiitCPyohiEPn9q11AXCdvVDouoVvgojXBcVj", Tag = "John", Amount = 100000000000 }, new SendManyModel { Address = "fiiitCPyohiEPn9q11AXCdvVDouoVvgojXBcVj", Tag = null, Amount = 100000000000 } }; string[] subtractFeeFromAmount = new string[] { "fiiitCPyohiEPn9q11AXCdvVDouoVvgojXBcVj", "fiiitCPyohiEPn9q11AXCdvVDouoVvgojXBcVj" }; ApiResponse response = await TransactionApi.EstimateTxFeeForSendMany(fromAccount, om, subtractFeeFromAmount); Assert.IsFalse(response.HasError); TxFeeForSend result = response.GetResult <TxFeeForSend>(); Assert.IsNotNull(result); }
/// <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); }