Recognize pegout scripts

This commit is contained in:
Steven Roose 2018-12-12 11:56:37 +01:00
parent 4688e3eb8e
commit 7bb9380260
2 changed files with 53 additions and 0 deletions

View file

@ -194,6 +194,49 @@ unsigned int CScript::GetSigOpCount(const CScript& scriptSig) const
return subscript.GetSigOpCount(true);
}
//
// ELEMENTS:
bool CScript::IsPegoutScript(uint256& genesis_hash, CScript& pegout_scriptpubkey) const
{
const_iterator pc = begin();
std::vector<unsigned char> data;
opcodetype opcode;
// OP_RETURN
if (!GetOp(pc, opcode, data) || opcode != OP_RETURN) {
return false;
}
if (!GetOp(pc, opcode, data) || data.size() != 32 ) {
return false;
}
genesis_hash = uint256(data);
// Read in parent chain destination scriptpubkey
if (!GetOp(pc, opcode, data) || data.size() == 0 ) {
return false;
}
pegout_scriptpubkey = CScript(data.begin(), data.end());
return true;
}
bool CScript::IsPegoutScript(const uint256& genesis_hash_check) const
{
uint256 genesis_hash;
CScript pegout_scriptpubkey;
// Ensure hash matches parent chain genesis block
if (this->IsPegoutScript(genesis_hash, pegout_scriptpubkey) &&
genesis_hash_check == genesis_hash) {
return true;
}
return false;
}
// END ELEMENTS
//
bool CScript::IsPayToScriptHash() const
{
// Extra-fast test for pay-to-script-hash CScripts:

View file

@ -17,6 +17,7 @@
#include <stdint.h>
#include <string.h>
#include <string>
#include <uint256.h>
#include <vector>
// Maximum number of bytes pushable to the stack
@ -540,6 +541,15 @@ public:
bool IsPayToWitnessScriptHash() const;
bool IsWitnessProgram(int& version, std::vector<unsigned char>& program) const;
// ELEMENTS:
// Returns true if script follows OP_RETURN <genesis_block_hash> <pegout_scriptpubkey>
// and if correct it returns both things in the output parameters.
bool IsPegoutScript(uint256& genesis_hash, CScript& pegout_scriptpubkey) const;
// Returns true if script follows OP_RETURN <genesis_block_hash> <destination_scriptpubkey>
// it may also have additional pushes at the end. It checks
// the genesis hash matches the specified one.
bool IsPegoutScript(const uint256& genesis_hash) const;
/** Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical). */
bool IsPushOnly(const_iterator pc) const;
bool IsPushOnly() const;