mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-15 09:09:46 +02:00
Have PSBTInput and PSBTOutput know the PSBT's version
This commit is contained in:
@@ -15,8 +15,8 @@ using common::PSBTError;
|
||||
|
||||
PartiallySignedTransaction::PartiallySignedTransaction(const CMutableTransaction& tx) : tx(tx)
|
||||
{
|
||||
inputs.resize(tx.vin.size());
|
||||
outputs.resize(tx.vout.size());
|
||||
inputs.resize(tx.vin.size(), PSBTInput(GetVersion()));
|
||||
outputs.resize(tx.vout.size(), PSBTOutput(GetVersion()));
|
||||
}
|
||||
|
||||
bool PartiallySignedTransaction::IsNull() const
|
||||
|
||||
30
src/psbt.h
30
src/psbt.h
@@ -263,6 +263,9 @@ static inline void ExpectedKeySize(const std::string& key_name, const std::vecto
|
||||
/** A structure for PSBTs which contain per-input information */
|
||||
class PSBTInput
|
||||
{
|
||||
private:
|
||||
uint32_t m_psbt_version;
|
||||
|
||||
public:
|
||||
CTransactionRef non_witness_utxo;
|
||||
CTxOut witness_utxo;
|
||||
@@ -300,7 +303,12 @@ public:
|
||||
void FillSignatureData(SignatureData& sigdata) const;
|
||||
void FromSignatureData(const SignatureData& sigdata);
|
||||
void Merge(const PSBTInput& input);
|
||||
PSBTInput() = default;
|
||||
uint32_t GetVersion() const { return m_psbt_version; }
|
||||
explicit PSBTInput(uint32_t psbt_version)
|
||||
: m_psbt_version(psbt_version)
|
||||
{
|
||||
assert(m_psbt_version == 0);
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline void Serialize(Stream& s) const {
|
||||
@@ -794,6 +802,9 @@ public:
|
||||
/** A structure for PSBTs which contains per output information */
|
||||
class PSBTOutput
|
||||
{
|
||||
private:
|
||||
uint32_t m_psbt_version;
|
||||
|
||||
public:
|
||||
CScript redeem_script;
|
||||
CScript witness_script;
|
||||
@@ -809,7 +820,12 @@ public:
|
||||
void FillSignatureData(SignatureData& sigdata) const;
|
||||
void FromSignatureData(const SignatureData& sigdata);
|
||||
void Merge(const PSBTOutput& output);
|
||||
PSBTOutput() = default;
|
||||
uint32_t GetVersion() const { return m_psbt_version; }
|
||||
explicit PSBTOutput(uint32_t psbt_version)
|
||||
: m_psbt_version(psbt_version)
|
||||
{
|
||||
assert(m_psbt_version == 0);
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline void Serialize(Stream& s) const {
|
||||
@@ -1031,6 +1047,9 @@ public:
|
||||
/** A version of CTransaction with the PSBT format*/
|
||||
class PartiallySignedTransaction
|
||||
{
|
||||
private:
|
||||
std::optional<uint32_t> m_version;
|
||||
|
||||
public:
|
||||
std::optional<CMutableTransaction> tx;
|
||||
// We use a vector of CExtPubKey in the event that there happens to be the same KeyOriginInfos for different CExtPubKeys
|
||||
@@ -1039,7 +1058,6 @@ public:
|
||||
std::vector<PSBTInput> inputs;
|
||||
std::vector<PSBTOutput> outputs;
|
||||
std::map<std::vector<unsigned char>, std::vector<unsigned char>> unknown;
|
||||
std::optional<uint32_t> m_version;
|
||||
std::set<PSBTProprietary> m_proprietary;
|
||||
|
||||
bool IsNull() const;
|
||||
@@ -1241,10 +1259,12 @@ public:
|
||||
throw std::ios_base::failure("No unsigned transaction was provided");
|
||||
}
|
||||
|
||||
const uint32_t psbt_ver = GetVersion();
|
||||
|
||||
// Read input data
|
||||
unsigned int i = 0;
|
||||
while (!s.empty() && i < tx->vin.size()) {
|
||||
PSBTInput input;
|
||||
PSBTInput input(psbt_ver);
|
||||
s >> input;
|
||||
inputs.push_back(input);
|
||||
|
||||
@@ -1267,7 +1287,7 @@ public:
|
||||
// Read output data
|
||||
i = 0;
|
||||
while (!s.empty() && i < tx->vout.size()) {
|
||||
PSBTOutput output;
|
||||
PSBTOutput output(psbt_ver);
|
||||
s >> output;
|
||||
outputs.push_back(output);
|
||||
++i;
|
||||
|
||||
@@ -1652,10 +1652,10 @@ static RPCMethod createpsbt()
|
||||
PartiallySignedTransaction psbtx;
|
||||
psbtx.tx = rawTx;
|
||||
for (unsigned int i = 0; i < rawTx.vin.size(); ++i) {
|
||||
psbtx.inputs.emplace_back();
|
||||
psbtx.inputs.emplace_back(0);
|
||||
}
|
||||
for (unsigned int i = 0; i < rawTx.vout.size(); ++i) {
|
||||
psbtx.outputs.emplace_back();
|
||||
psbtx.outputs.emplace_back(0);
|
||||
}
|
||||
|
||||
// Serialize the PSBT
|
||||
@@ -1720,10 +1720,10 @@ static RPCMethod converttopsbt()
|
||||
PartiallySignedTransaction psbtx;
|
||||
psbtx.tx = tx;
|
||||
for (unsigned int i = 0; i < tx.vin.size(); ++i) {
|
||||
psbtx.inputs.emplace_back();
|
||||
psbtx.inputs.emplace_back(0);
|
||||
}
|
||||
for (unsigned int i = 0; i < tx.vout.size(); ++i) {
|
||||
psbtx.outputs.emplace_back();
|
||||
psbtx.outputs.emplace_back(0);
|
||||
}
|
||||
|
||||
// Serialize the PSBT
|
||||
|
||||
@@ -192,11 +192,11 @@ FUZZ_TARGET_DESERIALIZE(prefilled_transaction_deserialize, {
|
||||
DeserializeFromFuzzingInput(buffer, prefilled_transaction);
|
||||
})
|
||||
FUZZ_TARGET_DESERIALIZE(psbt_input_deserialize, {
|
||||
PSBTInput psbt_input;
|
||||
PSBTInput psbt_input(0);
|
||||
DeserializeFromFuzzingInput(buffer, psbt_input);
|
||||
})
|
||||
FUZZ_TARGET_DESERIALIZE(psbt_output_deserialize, {
|
||||
PSBTOutput psbt_output;
|
||||
PSBTOutput psbt_output(0);
|
||||
DeserializeFromFuzzingInput(buffer, psbt_output);
|
||||
})
|
||||
FUZZ_TARGET_DESERIALIZE(block_deserialize, {
|
||||
|
||||
Reference in New Issue
Block a user