12 typedef std::vector<unsigned char>
valtype;
34 static bool MatchPayToPubkey(
const CScript& script,
valtype& pubkey)
47 static bool MatchPayToPubkeyHash(
const CScript& script,
valtype& pubkeyhash)
56 static bool MatchPayToColdStaking(
const CScript& script,
valtype& stakerPubKeyHash,
valtype& ownerPubKeyHash)
67 static constexpr
bool IsSmallInteger(
opcodetype opcode)
72 static bool MatchMultisig(
const CScript& script,
unsigned int& required, std::vector<valtype>& pubkeys)
79 if (!script.
GetOp(it, opcode, data) || !IsSmallInteger(opcode))
return false;
82 pubkeys.emplace_back(std::move(data));
84 if (!IsSmallInteger(opcode))
return false;
86 if (pubkeys.size() != keys || keys < required)
return false;
87 return (it + 1 == script.
end());
92 if (scriptPubKey.
empty())
95 vSolutionsRet.clear();
102 std::vector<unsigned char> hashBytes(scriptPubKey.
begin()+2, scriptPubKey.
begin()+22);
103 vSolutionsRet.push_back(hashBytes);
117 std::vector<unsigned char> data;
118 if (MatchPayToPubkey(scriptPubKey, data)) {
120 vSolutionsRet.push_back(std::move(data));
124 if (MatchPayToPubkeyHash(scriptPubKey, data)) {
126 vSolutionsRet.push_back(std::move(data));
133 std::vector<unsigned char> hashBytes(scriptPubKey.
begin()+4, scriptPubKey.
begin()+24);
134 vSolutionsRet.push_back(hashBytes);
139 std::vector<unsigned char> data1;
140 if (MatchPayToColdStaking(scriptPubKey, data, data1)) {
142 vSolutionsRet.push_back(std::move(data));
143 vSolutionsRet.push_back(std::move(data1));
147 unsigned int required;
148 std::vector<std::vector<unsigned char>> keys;
149 if (MatchMultisig(scriptPubKey, required, keys)) {
151 vSolutionsRet.push_back({
static_cast<unsigned char>(required)});
152 vSolutionsRet.insert(vSolutionsRet.end(), keys.begin(), keys.end());
153 vSolutionsRet.push_back({
static_cast<unsigned char>(keys.size())});
157 vSolutionsRet.clear();
164 std::vector<valtype> vSolutions;
166 if (!
Solver(scriptPubKey, whichType, vSolutions))
174 addressRet = pubKey.
GetID();
199 std::vector<valtype> vSolutions;
200 if (!
Solver(scriptPubKey, typeRet, vSolutions))
209 nRequiredRet = vSolutions.front()[0];
210 for (
unsigned int i = 1; i < vSolutions.size()-1; i++)
217 addressRet.push_back(address);
220 if (addressRet.empty())
225 if (vSolutions.size() < 2)
238 addressRet.push_back(address);
246 class CScriptVisitor :
public boost::static_visitor<bool>
251 explicit CScriptVisitor(
CScript *scriptin) { script = scriptin; }
258 bool operator()(
const CKeyID &keyID)
const {
270 bool operator()(
const CScriptID &scriptID)
const {
282 boost::apply_visitor(CScriptVisitor(&script), dest);
316 for (
const CPubKey& key : keys)
330 return dest.which() != 0;
A reference to a CKey: the Hash160 of its serialized public key, special case for exchange key.
A reference to a CKey: the Hash160 of its serialized public key.
An encapsulated public key.
const unsigned char * end() const
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
static bool ValidSize(const std::vector< unsigned char > &vch)
const unsigned char * begin() const
static constexpr unsigned int PUBLIC_KEY_SIZE
secp256k1:
static constexpr unsigned int COMPRESSED_PUBLIC_KEY_SIZE
Serialized script, used inside transaction inputs and outputs.
bool IsPushOnly(const_iterator pc) const
Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical).
bool IsPayToScriptHash() const
static int DecodeOP_N(opcodetype opcode)
Encode/decode small integers:
bool GetOp(iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet)
bool IsPayToColdStaking() const
bool IsPayToExchangeAddress() const
static opcodetype EncodeOP_N(int n)
A reference to a CScript: the Hash160 of its serialization (see script.h)
uint160 Hash160(const T1 pbegin, const T1 pend)
Compute the 160-bit hash an object.
std::vector< unsigned char > valtype
std::vector< unsigned char > ToByteVector(const T &in)
opcodetype
Script opcodes.
@ OP_CHECKCOLDSTAKEVERIFY
@ OP_CHECKCOLDSTAKEVERIFY_LOF
CScript GetScriptForOpReturn(const uint256 &message)
Generate an OP_RETURN output script with the given data.
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< CTxDestination > &addressRet, int &nRequiredRet)
Parse a standard scriptPubKey with one or more destination addresses.
CScript GetScriptForStakeDelegation(const CKeyID &stakingKey, const CKeyID &spendingKey)
Generate a P2CS script for the given staker and owner keys.
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
CScript GetScriptForStakeDelegationLOF(const CKeyID &stakingKey, const CKeyID &spendingKey)
bool Solver(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< std::vector< unsigned char > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
std::vector< unsigned char > valtype
const char * GetTxnOutputType(txnouttype t)
unsigned nMaxDatacarrierBytes
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a PIVX scriptPubKey for the given CTxDestination.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet, bool fColdStake)
Parse a standard scriptPubKey for the destination address.
boost::variant< CNoDestination, CKeyID, CScriptID, CExchangeKeyID > CTxDestination
A txout script template with a specific destination.