15 typedef std::vector<unsigned char>
valtype;
44 static bool MatchPayToPubkey(
const CScript& script,
valtype& pubkey)
57 static bool MatchPayToPubkeyHash(
const CScript& script,
valtype& pubkeyhash)
60 pubkeyhash =
valtype(script.begin () + 3, script.begin() + 23);
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 vSolutionsRet.clear();
98 std::vector<unsigned char> hashBytes(scriptPubKey.
begin()+2, scriptPubKey.
begin()+22);
99 vSolutionsRet.push_back(hashBytes);
104 std::vector<unsigned char> witnessprogram;
106 if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_KEYHASH_SIZE) {
107 vSolutionsRet.push_back(witnessprogram);
110 if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_SCRIPTHASH_SIZE) {
111 vSolutionsRet.push_back(witnessprogram);
114 if (witnessversion != 0) {
115 vSolutionsRet.push_back(std::vector<unsigned char>{(
unsigned char)witnessversion});
116 vSolutionsRet.push_back(std::move(witnessprogram));
131 std::vector<unsigned char> data;
132 if (MatchPayToPubkey(scriptPubKey, data)) {
133 vSolutionsRet.push_back(std::move(data));
137 if (MatchPayToPubkeyHash(scriptPubKey, data)) {
138 vSolutionsRet.push_back(std::move(data));
142 unsigned int required;
143 std::vector<std::vector<unsigned char>> keys;
144 if (MatchMultisig(scriptPubKey, required, keys)) {
145 vSolutionsRet.push_back({
static_cast<unsigned char>(required)});
146 vSolutionsRet.insert(vSolutionsRet.end(), keys.begin(), keys.end());
147 vSolutionsRet.push_back({
static_cast<unsigned char>(keys.size())});
151 vSolutionsRet.clear();
157 std::vector<valtype> vSolutions;
165 addressRet = pubKey.
GetID();
179 std::copy(vSolutions[0].begin(), vSolutions[0].
end(), hash.
begin());
184 std::copy(vSolutions[0].begin(), vSolutions[0].
end(), hash.
begin());
189 unk.
version = vSolutions[0][0];
190 std::copy(vSolutions[1].begin(), vSolutions[1].
end(), unk.
program);
191 unk.
length = vSolutions[1].size();
202 std::vector<valtype> vSolutions;
203 typeRet =
Solver(scriptPubKey, vSolutions);
213 nRequiredRet = vSolutions.front()[0];
214 for (
unsigned int i = 1; i < vSolutions.size()-1; i++)
221 addressRet.push_back(address);
224 if (addressRet.empty())
233 addressRet.push_back(address);
241 class CScriptVisitor :
public boost::static_visitor<bool>
246 explicit CScriptVisitor(
CScript *scriptin) { script = scriptin; }
253 bool operator()(
const CKeyID &keyID)
const {
259 bool operator()(
const CScriptID &scriptID)
const {
282 *script <<
CScript::EncodeOP_N(
id.version) << std::vector<unsigned char>(
id.program,
id.program +
id.length);
292 boost::apply_visitor(CScriptVisitor(&script), dest);
306 for (
const CPubKey& key : keys)
314 std::vector<std::vector<unsigned char> > vSolutions;
325 return dest.which() != 0;
static int DecodeOP_N(opcodetype opcode)
Encode/decode small integers:
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
unspendable OP_RETURN script that carries data
unsigned char program[40]
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet) const
bool IsPayToScriptHash() const
static constexpr unsigned int PUBLIC_KEY_SIZE
secp256k1:
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
bool fAcceptDatacarrier
A data carrying output is an unspendable output containing data.
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
txnouttype Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char >> &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
bool IsWitnessProgram(int &version, std::vector< unsigned char > &program) const
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
const unsigned char * begin() const
static constexpr unsigned int COMPRESSED_PUBLIC_KEY_SIZE
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< CTxDestination > &addressRet, int &nRequiredRet)
Parse a standard scriptPubKey with one or more destination addresses.
static bool ValidSize(const std::vector< unsigned char > &vch)
opcodetype
Script opcodes.
Only for Witness versions not already defined above.
const unsigned char * end() const
boost::variant< CNoDestination, CKeyID, CScriptID, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
CTxDestination subtype to encode any future Witness version.
bool IsPushOnly(const_iterator pc) const
Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical).
An encapsulated public key.
std::vector< unsigned char > valtype
const char * GetTxnOutputType(txnouttype t)
Get the name of a txnouttype as a C string, or nullptr if unknown.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
A hasher class for SHA3-256.
static opcodetype EncodeOP_N(int n)
Serialized script, used inside transaction inputs and outputs.
A reference to a CKey: the Hash360 of its serialized public key.
CSHA3 & Write(const unsigned char *data, size_t len)
std::vector< unsigned char > valtype
A reference to a CScript: the Hash360 of its serialization (see script.h)
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
uint160 Hash360(const T1 pbegin, const T1 pend)
Compute the 160-bit hash an object.
CScript GetScriptForWitness(const CScript &redeemscript)
Generate a pay-to-witness script for the given redeem script.
unsigned nMaxDatacarrierBytes
Maximum size of TX_NULL_DATA scripts that this node considers standard.
std::vector< unsigned char > ToByteVector(const T &in)