25 if (
tx->GetHash() != psbt.
tx->GetHash()) {
29 for (
unsigned int i = 0; i <
inputs.size(); ++i) {
32 for (
unsigned int i = 0; i <
outputs.size(); ++i) {
42 if (std::find(
tx->vin.begin(),
tx->vin.end(), txin) !=
tx->vin.end()) {
45 tx->vin.push_back(txin);
55 tx->vout.push_back(txout);
63 uint32_t prevout_index =
tx->vin[input_index].prevout.n;
107 sigdata.
misc_pubkeys.emplace(key_pair.first.GetID(), key_pair);
167 sigdata.
misc_pubkeys.emplace(key_pair.first.GetID(), key_pair);
204 for (
const auto& input : psbt.
inputs) {
236 bool have_all_spent_outputs =
true;
237 std::vector<CTxOut> utxos(tx.
vin.size());
238 for (
size_t idx = 0; idx < tx.
vin.size(); ++idx) {
239 if (!psbt.
GetInputUTXO(utxos[idx], idx)) have_all_spent_outputs =
false;
242 if (have_all_spent_outputs) {
243 txdata.
Init(tx, std::move(utxos),
true);
245 txdata.
Init(tx, {},
true);
264 bool require_witness_sig =
false;
283 require_witness_sig =
true;
290 if (txdata ==
nullptr) {
297 if (require_witness_sig && !sigdata.
witness)
return false;
324 bool complete =
true;
326 for (
unsigned int i = 0; i < psbtx.
tx->vin.size(); ++i) {
342 for (
unsigned int i = 0; i < result.
vin.size(); ++i) {
343 result.
vin[i].scriptSig = psbtx.
inputs[i].final_script_sig;
344 result.
vin[i].scriptWitness = psbtx.
inputs[i].final_script_witness;
354 for (
auto it = std::next(psbtxs.begin()); it != psbtxs.end(); ++it) {
355 if (!out.
Merge(*it)) {
377 std::string tx_data =
DecodeBase64(base64_tx, &invalid);
379 error =
"invalid base64";
390 if (!ss_data.
empty()) {
391 error =
"extra data after PSBT";
394 }
catch (
const std::exception& e) {
#define Assert(val)
Identity function.
Double ended buffer combining vector and stream-like interfaces.
An outpoint - a combination of a transaction hash and an index n into its vout.
An input of a transaction.
An output of a transaction.
A signature creator for transactions.
An interface to be implemented by keystores that support signing.
static unsigned const char sighash[]
bool DecodeRawPSBT(PartiallySignedTransaction &psbt, const std::string &tx_data, std::string &error)
Decode a raw (binary blob) PSBT into a PartiallySignedTransaction.
bool DecodeBase64PSBT(PartiallySignedTransaction &psbt, const std::string &base64_tx, std::string &error)
Decode a base64ed PSBT into a PartiallySignedTransaction.
void UpdatePSBTOutput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index)
Updates a PSBTOutput with information from provider.
std::string PSBTRoleName(PSBTRole role)
size_t CountPSBTUnsignedInputs(const PartiallySignedTransaction &psbt)
Counts the unsigned inputs of a PSBT.
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized.
bool SignPSBTInput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index, const PrecomputedTransactionData *txdata, int sighash, SignatureData *out_sigdata)
Signs a PSBTInput, verifying that all provided data matches what is being signed.
bool PSBTInputSigned(const PSBTInput &input)
Checks whether a PSBTInput is already signed.
PrecomputedTransactionData PrecomputePSBTData(const PartiallySignedTransaction &psbt)
Compute a PrecomputedTransactionData object from a psbt.
TransactionError CombinePSBTs(PartiallySignedTransaction &out, const std::vector< PartiallySignedTransaction > &psbtxs)
Combines PSBTs with the same underlying transaction, resulting in a single PSBT with all partial sign...
bool FinalizePSBT(PartiallySignedTransaction &psbtx)
Finalizes a PSBT if possible, combining partial signatures.
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
const BaseSignatureCreator & DUMMY_SIGNATURE_CREATOR
A signature creator that just produces 71-byte empty signatures.
const SigningProvider & DUMMY_SIGNING_PROVIDER
constexpr auto MakeUCharSpan(V &&v) -> decltype(UCharSpanCast(MakeSpan(std::forward< V >(v))))
Like MakeSpan, but for (const) unsigned char member types only.
std::vector< unsigned char > DecodeBase64(const char *p, bool *pf_invalid)
A mutable version of CTransaction.
std::vector< CTxOut > vout
A structure for PSBTs which contains per output information.
void Merge(const PSBTOutput &output)
std::map< CPubKey, KeyOriginInfo > hd_keypaths
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
void FillSignatureData(SignatureData &sigdata) const
void FromSignatureData(const SignatureData &sigdata)
A version of CTransaction with the PSBT format.
bool Merge(const PartiallySignedTransaction &psbt)
Merge psbt into this.
PartiallySignedTransaction()
bool GetInputUTXO(CTxOut &utxo, int input_index) const
Finds the UTXO for a given input index.
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
bool AddOutput(const CTxOut &txout, const PSBTOutput &psbtout)
std::vector< PSBTInput > inputs
std::optional< CMutableTransaction > tx
bool AddInput(const CTxIn &txin, PSBTInput &psbtin)
std::vector< PSBTOutput > outputs
void Init(const T &tx, std::vector< CTxOut > &&spent_outputs, bool force=false)
Initialize this PrecomputedTransactionData with transaction data.
uint160 missing_redeem_script
ScriptID of the missing redeemScript (if any)
std::vector< CKeyID > missing_sigs
KeyIDs of pubkeys for signatures which could not be found.
std::map< CKeyID, SigPair > signatures
BIP 174 style partial signatures for the input. May contain all signatures necessary for producing a ...
bool witness
Stores whether the input this SigData corresponds to is a witness input.
std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo > > misc_pubkeys
CScript scriptSig
The scriptSig of an input. Contains complete signatures or the traditional partial signatures format.
CScript redeem_script
The redeemScript (if any) for the input.
uint256 missing_witness_script
SHA256 of the missing witnessScript (if any)
std::vector< CKeyID > missing_pubkeys
KeyIDs of pubkeys which could not be found.
CScript witness_script
The witnessScript (if any) for the input. witnessScripts are used in P2WSH outputs.
CScriptWitness scriptWitness
The scriptWitness of an input. Contains complete signatures or the traditional partial signatures for...
bool complete
Stores whether the scriptSig and scriptWitness are complete.
bool error(const char *fmt, const Args &... args)
static const int PROTOCOL_VERSION
network protocol versioning