Changeset View
Changeset View
Standalone View
Standalone View
src/script/sign.h
Show First 20 Lines • Show All 196 Lines • ▼ Show 20 Lines | struct PSBTInput { | ||||
CScript redeem_script; | CScript redeem_script; | ||||
CScript final_script_sig; | CScript final_script_sig; | ||||
std::map<CPubKey, std::vector<uint32_t>> hd_keypaths; | std::map<CPubKey, std::vector<uint32_t>> hd_keypaths; | ||||
std::map<CKeyID, SigPair> partial_sigs; | std::map<CKeyID, SigPair> partial_sigs; | ||||
std::map<std::vector<uint8_t>, std::vector<uint8_t>> unknown; | std::map<std::vector<uint8_t>, std::vector<uint8_t>> unknown; | ||||
SigHashType sighash_type = SigHashType(0); | SigHashType sighash_type = SigHashType(0); | ||||
bool IsNull() const; | bool IsNull() const; | ||||
void FillSignatureData(SignatureData &sigdata) const; | |||||
void FromSignatureData(const SignatureData &sigdata); | |||||
void Merge(const PSBTInput &input); | |||||
bool IsSane() const; | |||||
PSBTInput() {} | PSBTInput() {} | ||||
template <typename Stream> inline void Serialize(Stream &s) const { | template <typename Stream> inline void Serialize(Stream &s) const { | ||||
// Write the utxo | // Write the utxo | ||||
SerializeToVector(s, PSBT_IN_UTXO); | SerializeToVector(s, PSBT_IN_UTXO); | ||||
SerializeToVector(s, utxo); | SerializeToVector(s, utxo); | ||||
if (final_script_sig.empty()) { | if (final_script_sig.empty()) { | ||||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | |||||
/** A structure for PSBTs which contains per output information */ | /** A structure for PSBTs which contains per output information */ | ||||
struct PSBTOutput { | struct PSBTOutput { | ||||
CScript redeem_script; | CScript redeem_script; | ||||
std::map<CPubKey, std::vector<uint32_t>> hd_keypaths; | std::map<CPubKey, std::vector<uint32_t>> hd_keypaths; | ||||
std::map<std::vector<uint8_t>, std::vector<uint8_t>> unknown; | std::map<std::vector<uint8_t>, std::vector<uint8_t>> unknown; | ||||
bool IsNull() const; | bool IsNull() const; | ||||
void FillSignatureData(SignatureData &sigdata) const; | |||||
void FromSignatureData(const SignatureData &sigdata); | |||||
void Merge(const PSBTOutput &output); | |||||
bool IsSane() const; | |||||
PSBTOutput() {} | PSBTOutput() {} | ||||
template <typename Stream> inline void Serialize(Stream &s) const { | template <typename Stream> inline void Serialize(Stream &s) const { | ||||
// Write the redeem script | // Write the redeem script | ||||
if (!redeem_script.empty()) { | if (!redeem_script.empty()) { | ||||
SerializeToVector(s, PSBT_OUT_REDEEMSCRIPT); | SerializeToVector(s, PSBT_OUT_REDEEMSCRIPT); | ||||
s << redeem_script; | s << redeem_script; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
struct PartiallySignedTransaction { | struct PartiallySignedTransaction { | ||||
boost::optional<CMutableTransaction> tx; | boost::optional<CMutableTransaction> tx; | ||||
std::vector<PSBTInput> inputs; | std::vector<PSBTInput> inputs; | ||||
std::vector<PSBTOutput> outputs; | std::vector<PSBTOutput> outputs; | ||||
std::map<std::vector<uint8_t>, std::vector<uint8_t>> unknown; | std::map<std::vector<uint8_t>, std::vector<uint8_t>> unknown; | ||||
bool IsNull() const; | bool IsNull() const; | ||||
void Merge(const PartiallySignedTransaction &psbt); | |||||
bool IsSane() const; | |||||
PartiallySignedTransaction() {} | PartiallySignedTransaction() {} | ||||
PartiallySignedTransaction(const PartiallySignedTransaction &psbt_in) | PartiallySignedTransaction(const PartiallySignedTransaction &psbt_in) | ||||
: tx(psbt_in.tx), inputs(psbt_in.inputs), outputs(psbt_in.outputs), | : tx(psbt_in.tx), inputs(psbt_in.inputs), outputs(psbt_in.outputs), | ||||
unknown(psbt_in.unknown) {} | unknown(psbt_in.unknown) {} | ||||
// Only checks if they refer to the same transaction | // Only checks if they refer to the same transaction | ||||
friend bool operator==(const PartiallySignedTransaction &a, | friend bool operator==(const PartiallySignedTransaction &a, | ||||
const PartiallySignedTransaction &b) { | const PartiallySignedTransaction &b) { | ||||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | template <typename Stream> inline void Unserialize(Stream &s) { | ||||
++i; | ++i; | ||||
} | } | ||||
// Make sure that the number of outputs matches the number of outputs in | // Make sure that the number of outputs matches the number of outputs in | ||||
// the transaction | // the transaction | ||||
if (outputs.size() != tx->vout.size()) { | if (outputs.size() != tx->vout.size()) { | ||||
throw std::ios_base::failure("Outputs provided does not match the " | throw std::ios_base::failure("Outputs provided does not match the " | ||||
"number of outputs in transaction."); | "number of outputs in transaction."); | ||||
} | } | ||||
// Sanity check | |||||
if (!IsSane()) { | |||||
throw std::ios_base::failure("PSBT is not sane."); | |||||
} | |||||
} | } | ||||
template <typename Stream> | template <typename Stream> | ||||
PartiallySignedTransaction(deserialize_type, Stream &s) { | PartiallySignedTransaction(deserialize_type, Stream &s) { | ||||
Unserialize(s); | Unserialize(s); | ||||
} | } | ||||
}; | }; | ||||
Show All 19 Lines |