mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-18 13:17:55 +02:00
BIP141: Other consensus critical limits, and BIP145
Includes changes by Suhas Daftuar, Luke-jr, and mruddy.
This commit is contained in:
parent
7c4bf779e8
commit
2b1f6f9ccf
31 changed files with 344 additions and 136 deletions
|
|
@ -1470,3 +1470,50 @@ bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const C
|
|||
|
||||
return set_success(serror);
|
||||
}
|
||||
|
||||
size_t static WitnessSigOps(int witversion, const std::vector<unsigned char>& witprogram, const CScriptWitness& witness, int flags)
|
||||
{
|
||||
if (witversion == 0) {
|
||||
if (witprogram.size() == 20)
|
||||
return 1;
|
||||
|
||||
if (witprogram.size() == 32 && witness.stack.size() > 0) {
|
||||
CScript subscript(witness.stack.back().begin(), witness.stack.back().end());
|
||||
return subscript.GetSigOpCount(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Future flags may be implemented here.
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t CountWitnessSigOps(const CScript& scriptSig, const CScript& scriptPubKey, const CScriptWitness* witness, unsigned int flags)
|
||||
{
|
||||
static const CScriptWitness witnessEmpty;
|
||||
|
||||
if ((flags & SCRIPT_VERIFY_WITNESS) == 0) {
|
||||
return 0;
|
||||
}
|
||||
assert((flags & SCRIPT_VERIFY_P2SH) != 0);
|
||||
|
||||
int witnessversion;
|
||||
std::vector<unsigned char> witnessprogram;
|
||||
if (scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram)) {
|
||||
return WitnessSigOps(witnessversion, witnessprogram, witness ? *witness : witnessEmpty, flags);
|
||||
}
|
||||
|
||||
if (scriptPubKey.IsPayToScriptHash() && scriptSig.IsPushOnly()) {
|
||||
CScript::const_iterator pc = scriptSig.begin();
|
||||
vector<unsigned char> data;
|
||||
while (pc < scriptSig.end()) {
|
||||
opcodetype opcode;
|
||||
scriptSig.GetOp(pc, opcode, data);
|
||||
}
|
||||
CScript subscript(data.begin(), data.end());
|
||||
if (subscript.IsWitnessProgram(witnessversion, witnessprogram)) {
|
||||
return WitnessSigOps(witnessversion, witnessprogram, witness ? *witness : witnessEmpty, flags);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue