Skip to content

Commit

Permalink
Recognize pegout scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenroose committed Jan 2, 2019
1 parent 4688e3e commit 7bb9380
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/script/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions src/script/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -540,6 +541,15 @@ class CScript : public CScriptBase
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;
Expand Down

0 comments on commit 7bb9380

Please sign in to comment.