public async Task <Tuple <List <UnspentOutput>, Amount> > SelectUnspentOutputs(Account account, Amount targetAmount, int requiredConfirmations) { var client = WalletService.NewClient(_channel); var request = new FundTransactionRequest { Account = account.AccountNumber, TargetAmount = targetAmount, RequiredConfirmations = requiredConfirmations, IncludeImmatureCoinbases = false, IncludeChangeScript = false, }; var response = await client.FundTransactionAsync(request, cancellationToken : _tokenSource.Token); var outputs = response.SelectedOutputs.Select(MarshalUnspentOutput).ToList(); var total = (Amount)response.TotalAmount; return(Tuple.Create(outputs, total)); }
public async Task<Tuple<List<UnspentOutput>, Amount>> FundTransactionAsync( Account account, Amount targetAmount, int requiredConfirmations) { var client = new WalletService.WalletServiceClient(_channel); var request = new FundTransactionRequest { Account = account.AccountNumber, TargetAmount = targetAmount, RequiredConfirmations = requiredConfirmations, IncludeImmatureCoinbases = false, IncludeChangeScript = false, }; var response = await client.FundTransactionAsync(request, cancellationToken: _tokenSource.Token); var outputs = response.SelectedOutputs.Select(MarshalUnspentOutput).ToList(); var total = (Amount)response.TotalAmount; return Tuple.Create(outputs, total); }
public async Task<Tuple<List<UnspentOutput>, Amount, OutputScript>> FundTransactionAsync( Account account, Amount targetAmount, int requiredConfirmations) { var client = WalletService.NewClient(_channel); var request = new FundTransactionRequest { Account = account.AccountNumber, TargetAmount = targetAmount, RequiredConfirmations = requiredConfirmations, IncludeImmatureCoinbases = false, IncludeChangeScript = true, }; var response = await client.FundTransactionAsync(request, cancellationToken: _tokenSource.Token); var outputs = response.SelectedOutputs.Select(MarshalUnspentOutput).ToList(); var total = (Amount)response.TotalAmount; var changeScript = (OutputScript)null; if (response.ChangePkScript?.Length != 0) { changeScript = OutputScript.ParseScript(response.ChangePkScript.ToByteArray()); } return Tuple.Create(outputs, total, changeScript); }
public async Task <IActionResult> FundTransactionAsync(string account, [FromBody] FundTransactionRequest request) { try { if (request == null || request.Password == null || request.Address == null || request.Inputs == null || request.Inputs.Count() == 0 || request.FeeType == null) { return(new ObjectResult(new FailureResponse { Message = "Bad request", Details = "" })); } var fail = Global.WalletWrapper.GetAccount(account, out SafeAccount safeAccount); if (fail != null) { return(new ObjectResult(fail)); } BitcoinAddress address; try { address = BitcoinAddress.Create(request.Address, Global.WalletWrapper.WalletJob.CurrentNetwork); } catch (Exception) { return(new ObjectResult(new FailureResponse { Message = "Wrong address", Details = "" })); } var inputs = new List <OutPoint>(); try { foreach (var input in request.Inputs) { var inputParts = input.Split(":"); inputs.Add(new OutPoint(new uint256(inputParts[1]), int.Parse(inputParts[0]))); } } catch (Exception) { return(new ObjectResult(new FailureResponse { Message = "Wrong amount", Details = "" })); } FeeType feeType; if (request.FeeType.Equals("high", StringComparison.OrdinalIgnoreCase)) { feeType = FeeType.High; } else if (request.FeeType.Equals("medium", StringComparison.OrdinalIgnoreCase)) { feeType = FeeType.Medium; } else if (request.FeeType.Equals("low", StringComparison.OrdinalIgnoreCase)) { feeType = FeeType.Low; } else { return(new ObjectResult(new FailureResponse { Message = "Wrong fee type", Details = "" })); } return(new ObjectResult(await Global.WalletWrapper.BuildTransactionAsync(request.Password, safeAccount, address, Money.Zero, feeType, true, null, inputs))); } catch (Exception ex) { return(new ObjectResult(new FailureResponse { Message = ex.Message, Details = ex.ToString() })); } }