[bitcoin/bitcoin] Moving final scriptSig construction from CombineSignatures to ProduceSignature (PSBT signer logic) (#13425)

sipa commented on this pull request.

utACK 1d5c2bbaba8e3b66195acefe37053d9048c81ecf

Some tiny nits only, feel free to ignore.

> + stack.witness.pop_back();
+ stack.script = std::move(stack.witness);
+ stack.witness.clear();
+ sigversion = SigVersion::WITNESS_V0;
+ }
+ if (script_type == TX_MULTISIG && !stack.script.empty()) {
+ // Build a map of pubkey -> signature by matching sigs to pubkeys:
+ assert(solutions.size() > 1);
+ unsigned int num_pubkeys = solutions.size()-2;
+ unsigned int last_success_key = 0;
+ for (const valtype& sig : stack.script) {
+ for (unsigned int i = last_success_key; i < num_pubkeys; i++) { + const valtype& pubkey = solutions[i+1]; + // We either have a signature for this pubkey, or we have found a signature and it is valid + if (data.signatures.count(CPubKey(pubkey).GetID()) || checker.CheckSig(sig, pubkey, next_script, sigversion)) { + last_success_key = i; `i + 1` even, I think (the same signature can't be reused for another pubkey). > @@ -187,6 +280,17 @@ void UpdateInput(CTxIn& input, const SignatureData& data)
input.scriptWitness = data.scriptWitness;
}

+void SignatureData::MergeSignatureData(SignatureData sigdata)
+{
+ if (complete) return;
+ if (sigdata.complete) {
+ *this = std::move(sigdata);
+ return;
+ }
+ scripts.insert(sigdata.scripts.begin(), sigdata.scripts.end());

Very nitty: this line and the next will perform an unnecessary copy. You can avoid it with `scripts.insert(std::make_move_iterator(sigdata.scripts.begin()), std::make_move_iterator(sigdata.scripts.end());` etc.

Добавить комментарий