Changeset View
Changeset View
Standalone View
Standalone View
src/psbt.cpp
Show All 28 Lines | bool PartiallySignedTransaction::Merge(const PartiallySignedTransaction &psbt) { | ||||
for (size_t i = 0; i < outputs.size(); ++i) { | for (size_t i = 0; i < outputs.size(); ++i) { | ||||
outputs[i].Merge(psbt.outputs[i]); | outputs[i].Merge(psbt.outputs[i]); | ||||
} | } | ||||
unknown.insert(psbt.unknown.begin(), psbt.unknown.end()); | unknown.insert(psbt.unknown.begin(), psbt.unknown.end()); | ||||
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, | bool PartiallySignedTransaction::AddInput(const CTxIn &txin, | ||||
PSBTInput &psbtin) { | 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()) { | ||||
return false; | return false; | ||||
} | } | ||||
tx->vin.push_back(txin); | tx->vin.push_back(txin); | ||||
psbtin.partial_sigs.clear(); | psbtin.partial_sigs.clear(); | ||||
psbtin.final_script_sig.clear(); | psbtin.final_script_sig.clear(); | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | void PSBTInput::Merge(const PSBTInput &input) { | ||||
if (redeem_script.empty() && !input.redeem_script.empty()) { | if (redeem_script.empty() && !input.redeem_script.empty()) { | ||||
redeem_script = input.redeem_script; | redeem_script = input.redeem_script; | ||||
} | } | ||||
if (final_script_sig.empty() && !input.final_script_sig.empty()) { | if (final_script_sig.empty() && !input.final_script_sig.empty()) { | ||||
final_script_sig = input.final_script_sig; | final_script_sig = input.final_script_sig; | ||||
} | } | ||||
} | } | ||||
bool PSBTInput::IsSane() const { | |||||
return true; | |||||
} | |||||
void PSBTOutput::FillSignatureData(SignatureData &sigdata) const { | void PSBTOutput::FillSignatureData(SignatureData &sigdata) const { | ||||
if (!redeem_script.empty()) { | if (!redeem_script.empty()) { | ||||
sigdata.redeem_script = redeem_script; | sigdata.redeem_script = redeem_script; | ||||
} | } | ||||
for (const auto &key_pair : hd_keypaths) { | for (const auto &key_pair : hd_keypaths) { | ||||
sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair); | sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | bool SignPSBTInput(const SigningProvider &provider, | ||||
// Fill SignatureData with input info | // Fill SignatureData with input info | ||||
SignatureData sigdata; | SignatureData sigdata; | ||||
input.FillSignatureData(sigdata); | input.FillSignatureData(sigdata); | ||||
// Get UTXO | // Get UTXO | ||||
CTxOut utxo; | CTxOut utxo; | ||||
// Verify input sanity | |||||
if (!input.IsSane()) { | |||||
return false; | |||||
} | |||||
if (input.utxo.IsNull()) { | if (input.utxo.IsNull()) { | ||||
return false; | return false; | ||||
} | } | ||||
utxo = input.utxo; | utxo = input.utxo; | ||||
bool sig_complete{false}; | bool sig_complete{false}; | ||||
if (use_dummy) { | if (use_dummy) { | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | CombinePSBTs(PartiallySignedTransaction &out, | ||||
out = psbtxs[0]; | out = psbtxs[0]; | ||||
// Merge | // Merge | ||||
for (auto it = std::next(psbtxs.begin()); it != psbtxs.end(); ++it) { | for (auto it = std::next(psbtxs.begin()); it != psbtxs.end(); ++it) { | ||||
if (!out.Merge(*it)) { | if (!out.Merge(*it)) { | ||||
return TransactionError::PSBT_MISMATCH; | return TransactionError::PSBT_MISMATCH; | ||||
} | } | ||||
} | } | ||||
if (!out.IsSane()) { | |||||
return TransactionError::INVALID_PSBT; | |||||
} | |||||
return TransactionError::OK; | return TransactionError::OK; | ||||
} | } | ||||
std::string PSBTRoleName(const PSBTRole role) { | std::string PSBTRoleName(const PSBTRole role) { | ||||
switch (role) { | switch (role) { | ||||
case PSBTRole::CREATOR: | case PSBTRole::CREATOR: | ||||
return "creator"; | return "creator"; | ||||
Show All 40 Lines |