mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-12 08:35:31 +01:00
26fe9b9909Add support for descriptors to utxoupdatepsbt (Pieter Wuille)3135c1a2d2Abstract out UpdatePSBTOutput from FillPSBT (Pieter Wuille)fb90ec3c33Abstract out EvalDescriptorStringOrObject from scantxoutset (Pieter Wuille)eaf4f88734Abstract out IsSegWitOutput from utxoupdatepsbt (Pieter Wuille) Pull request description: This adds a descriptors argument to the `utxoupdatepsbt` RPC. This means: * Input and output scripts and keys will be filled in when known. * P2SH-witness inputs will be filled in from the UTXO set when a descriptor is provided that shows they're spending segwit outputs. This also moves some (newly) shared code to separate functions: `UpdatePSBTOutput` (an analogue to `SignPSBTInput`), `IsSegWitOutput`, and `EvalDescriptorStringOrObject` (implementing the string or object notation parsing used in `scantxoutset`). ACKs for top commit: jnewbery: utACK26fe9b9909laanwj: utACK26fe9b9909(will hold merging until response to promag's comments) promag: ACK26fe9b9, checked refactors and tests look comprehensive. Still missing a release note but can be added later. Tree-SHA512: 1d833b7351b59d6c5ded6da399ff371a8a2a6ad04c0a8f90e6e46105dc737fa6f2740b1e5340280d59e01f42896c40b720c042f44417e38dfbee6477b894b245
52 lines
2.1 KiB
C++
52 lines
2.1 KiB
C++
// Copyright (c) 2009-2019 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <wallet/psbtwallet.h>
|
|
|
|
TransactionError FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, bool& complete, int sighash_type, bool sign, bool bip32derivs)
|
|
{
|
|
LOCK(pwallet->cs_wallet);
|
|
// Get all of the previous transactions
|
|
complete = true;
|
|
for (unsigned int i = 0; i < psbtx.tx->vin.size(); ++i) {
|
|
const CTxIn& txin = psbtx.tx->vin[i];
|
|
PSBTInput& input = psbtx.inputs.at(i);
|
|
|
|
if (PSBTInputSigned(input)) {
|
|
continue;
|
|
}
|
|
|
|
// Verify input looks sane. This will check that we have at most one uxto, witness or non-witness.
|
|
if (!input.IsSane()) {
|
|
return TransactionError::INVALID_PSBT;
|
|
}
|
|
|
|
// If we have no utxo, grab it from the wallet.
|
|
if (!input.non_witness_utxo && input.witness_utxo.IsNull()) {
|
|
const uint256& txhash = txin.prevout.hash;
|
|
const auto it = pwallet->mapWallet.find(txhash);
|
|
if (it != pwallet->mapWallet.end()) {
|
|
const CWalletTx& wtx = it->second;
|
|
// We only need the non_witness_utxo, which is a superset of the witness_utxo.
|
|
// The signing code will switch to the smaller witness_utxo if this is ok.
|
|
input.non_witness_utxo = wtx.tx;
|
|
}
|
|
}
|
|
|
|
// Get the Sighash type
|
|
if (sign && input.sighash_type > 0 && input.sighash_type != sighash_type) {
|
|
return TransactionError::SIGHASH_MISMATCH;
|
|
}
|
|
|
|
complete &= SignPSBTInput(HidingSigningProvider(pwallet, !sign, !bip32derivs), psbtx, i, sighash_type);
|
|
}
|
|
|
|
// Fill in the bip32 keypaths and redeemscripts for the outputs so that hardware wallets can identify change
|
|
for (unsigned int i = 0; i < psbtx.tx->vout.size(); ++i) {
|
|
UpdatePSBTOutput(HidingSigningProvider(pwallet, true, !bip32derivs), psbtx, i);
|
|
}
|
|
|
|
return TransactionError::OK;
|
|
}
|