public IActionResult GetTransactionFeeEstimate([FromQuery] TxFeeEstimateRequest request)
        {
            Guard.NotNull(request, nameof(request));

            // checks the request is valid
            if (!this.ModelState.IsValid)
            {
                return(BuildErrorResponse(this.ModelState));
            }

            try
            {
                var destination = BitcoinAddress.Create(request.DestinationAddress, this.network).ScriptPubKey;
                var context     = new TransactionBuildContext(
                    new WalletAccountReference(request.WalletName, request.AccountName),
                    new[] { new Recipient {
                                Amount = request.Amount, ScriptPubKey = destination
                            } }.ToList())
                {
                    FeeType          = FeeParser.Parse(request.FeeType),
                    MinConfirmations = request.AllowUnconfirmed ? 0 : 1,
                };

                return(this.Json(this.walletTransactionHandler.EstimateFee(context)));
            }
            catch (Exception e)
            {
                this.logger.LogError("Exception occurred: {0}", e.ToString());
                return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString()));
            }
        }
Exemplo n.º 2
0
 public async Task <IActionResult> GetTransactionFeeEstimate([FromBody] TxFeeEstimateRequest request,
                                                             CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await this.Execute(request, cancellationToken,
                               async (req, token) => Json(await this.walletService.GetTransactionFeeEstimate(req, token))));
 }