mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-27 03:33:27 -03:00
psbt: Allow both non_witness_utxo and witness_utxo
This commit is contained in:
parent
72f6bec1da
commit
5279d8bc07
5 changed files with 0 additions and 53 deletions
29
src/psbt.cpp
29
src/psbt.cpp
|
@ -35,14 +35,6 @@ bool PartiallySignedTransaction::Merge(const PartiallySignedTransaction& psbt)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PartiallySignedTransaction::IsSane() const
|
|
||||||
{
|
|
||||||
for (PSBTInput input : inputs) {
|
|
||||||
if (!input.IsSane()) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PartiallySignedTransaction::AddInput(const CTxIn& txin, PSBTInput& psbtin)
|
bool PartiallySignedTransaction::AddInput(const CTxIn& txin, PSBTInput& psbtin)
|
||||||
{
|
{
|
||||||
if (std::find(tx->vin.begin(), tx->vin.end(), txin) != tx->vin.end()) {
|
if (std::find(tx->vin.begin(), tx->vin.end(), txin) != tx->vin.end()) {
|
||||||
|
@ -158,18 +150,6 @@ void PSBTInput::Merge(const PSBTInput& input)
|
||||||
if (final_script_witness.IsNull() && !input.final_script_witness.IsNull()) final_script_witness = input.final_script_witness;
|
if (final_script_witness.IsNull() && !input.final_script_witness.IsNull()) final_script_witness = input.final_script_witness;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PSBTInput::IsSane() const
|
|
||||||
{
|
|
||||||
// Cannot have both witness and non-witness utxos
|
|
||||||
if (!witness_utxo.IsNull() && non_witness_utxo) return false;
|
|
||||||
|
|
||||||
// If we have a witness_script or a scriptWitness, we must also have a witness utxo
|
|
||||||
if (!witness_script.empty() && witness_utxo.IsNull()) return false;
|
|
||||||
if (!final_script_witness.IsNull() && witness_utxo.IsNull()) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PSBTOutput::FillSignatureData(SignatureData& sigdata) const
|
void PSBTOutput::FillSignatureData(SignatureData& sigdata) const
|
||||||
{
|
{
|
||||||
if (!redeem_script.empty()) {
|
if (!redeem_script.empty()) {
|
||||||
|
@ -261,11 +241,6 @@ bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction&
|
||||||
bool require_witness_sig = false;
|
bool require_witness_sig = false;
|
||||||
CTxOut utxo;
|
CTxOut utxo;
|
||||||
|
|
||||||
// Verify input sanity, which checks that at most one of witness or non-witness utxos is provided.
|
|
||||||
if (!input.IsSane()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.non_witness_utxo) {
|
if (input.non_witness_utxo) {
|
||||||
// If we're taking our information from a non-witness UTXO, verify that it matches the prevout.
|
// If we're taking our information from a non-witness UTXO, verify that it matches the prevout.
|
||||||
COutPoint prevout = tx.vin[index].prevout;
|
COutPoint prevout = tx.vin[index].prevout;
|
||||||
|
@ -356,10 +331,6 @@ TransactionError CombinePSBTs(PartiallySignedTransaction& out, const std::vector
|
||||||
return TransactionError::PSBT_MISMATCH;
|
return TransactionError::PSBT_MISMATCH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!out.IsSane()) {
|
|
||||||
return TransactionError::INVALID_PSBT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TransactionError::OK;
|
return TransactionError::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,6 @@ struct PSBTInput
|
||||||
void FillSignatureData(SignatureData& sigdata) const;
|
void FillSignatureData(SignatureData& sigdata) const;
|
||||||
void FromSignatureData(const SignatureData& sigdata);
|
void FromSignatureData(const SignatureData& sigdata);
|
||||||
void Merge(const PSBTInput& input);
|
void Merge(const PSBTInput& input);
|
||||||
bool IsSane() const;
|
|
||||||
PSBTInput() {}
|
PSBTInput() {}
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
|
@ -284,7 +283,6 @@ struct PSBTOutput
|
||||||
void FillSignatureData(SignatureData& sigdata) const;
|
void FillSignatureData(SignatureData& sigdata) const;
|
||||||
void FromSignatureData(const SignatureData& sigdata);
|
void FromSignatureData(const SignatureData& sigdata);
|
||||||
void Merge(const PSBTOutput& output);
|
void Merge(const PSBTOutput& output);
|
||||||
bool IsSane() const;
|
|
||||||
PSBTOutput() {}
|
PSBTOutput() {}
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
|
@ -401,7 +399,6 @@ struct PartiallySignedTransaction
|
||||||
/** Merge psbt into this. The two psbts must have the same underlying CTransaction (i.e. the
|
/** Merge psbt into this. The two psbts must have the same underlying CTransaction (i.e. the
|
||||||
* same actual Bitcoin transaction.) Returns true if the merge succeeded, false otherwise. */
|
* same actual Bitcoin transaction.) Returns true if the merge succeeded, false otherwise. */
|
||||||
NODISCARD bool Merge(const PartiallySignedTransaction& psbt);
|
NODISCARD bool Merge(const PartiallySignedTransaction& psbt);
|
||||||
bool IsSane() const;
|
|
||||||
bool AddInput(const CTxIn& txin, PSBTInput& psbtin);
|
bool AddInput(const CTxIn& txin, PSBTInput& psbtin);
|
||||||
bool AddOutput(const CTxOut& txout, const PSBTOutput& psbtout);
|
bool AddOutput(const CTxOut& txout, const PSBTOutput& psbtout);
|
||||||
PartiallySignedTransaction() {}
|
PartiallySignedTransaction() {}
|
||||||
|
@ -551,10 +548,6 @@ struct PartiallySignedTransaction
|
||||||
if (outputs.size() != tx->vout.size()) {
|
if (outputs.size() != tx->vout.size()) {
|
||||||
throw std::ios_base::failure("Outputs provided does not match the number of outputs in transaction.");
|
throw std::ios_base::failure("Outputs provided does not match the number of outputs in transaction.");
|
||||||
}
|
}
|
||||||
// Sanity check
|
|
||||||
if (!IsSane()) {
|
|
||||||
throw std::ios_base::failure("PSBT is not sane.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
|
|
|
@ -39,7 +39,6 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)psbt.IsNull();
|
(void)psbt.IsNull();
|
||||||
(void)psbt.IsSane();
|
|
||||||
|
|
||||||
Optional<CMutableTransaction> tx = psbt.tx;
|
Optional<CMutableTransaction> tx = psbt.tx;
|
||||||
if (tx) {
|
if (tx) {
|
||||||
|
@ -50,7 +49,6 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
||||||
for (const PSBTInput& input : psbt.inputs) {
|
for (const PSBTInput& input : psbt.inputs) {
|
||||||
(void)PSBTInputSigned(input);
|
(void)PSBTInputSigned(input);
|
||||||
(void)input.IsNull();
|
(void)input.IsNull();
|
||||||
(void)input.IsSane();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const PSBTOutput& output : psbt.outputs) {
|
for (const PSBTOutput& output : psbt.outputs) {
|
||||||
|
|
|
@ -597,11 +597,6 @@ TransactionError LegacyScriptPubKeyMan::FillPSBT(PartiallySignedTransaction& psb
|
||||||
continue;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the Sighash type
|
// Get the Sighash type
|
||||||
if (sign && input.sighash_type > 0 && input.sighash_type != sighash_type) {
|
if (sign && input.sighash_type > 0 && input.sighash_type != sighash_type) {
|
||||||
return TransactionError::SIGHASH_MISMATCH;
|
return TransactionError::SIGHASH_MISMATCH;
|
||||||
|
@ -2086,11 +2081,6 @@ TransactionError DescriptorScriptPubKeyMan::FillPSBT(PartiallySignedTransaction&
|
||||||
continue;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the Sighash type
|
// Get the Sighash type
|
||||||
if (sign && input.sighash_type > 0 && input.sighash_type != sighash_type) {
|
if (sign && input.sighash_type > 0 && input.sighash_type != sighash_type) {
|
||||||
return TransactionError::SIGHASH_MISMATCH;
|
return TransactionError::SIGHASH_MISMATCH;
|
||||||
|
|
|
@ -2491,11 +2491,6 @@ TransactionError CWallet::FillPSBT(PartiallySignedTransaction& psbtx, bool& comp
|
||||||
continue;
|
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 we have no utxo, grab it from the wallet.
|
||||||
if (!input.non_witness_utxo && input.witness_utxo.IsNull()) {
|
if (!input.non_witness_utxo && input.witness_utxo.IsNull()) {
|
||||||
const uint256& txhash = txin.prevout.hash;
|
const uint256& txhash = txin.prevout.hash;
|
||||||
|
|
Loading…
Add table
Reference in a new issue