13 #include <boost/foreach.hpp> 16 #include <validation.h> 18 typedef std::vector<unsigned char>
valtype;
46 bool Solver(
const CScript& scriptPubKey,
txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet,
bool contractConsensus)
53 static std::multimap<txnouttype, CScript> mTemplates;
54 if (mTemplates.empty())
71 vSolutionsRet.clear();
78 std::vector<unsigned char> hashBytes(scriptPubKey.
begin()+2, scriptPubKey.
begin()+22);
79 vSolutionsRet.push_back(hashBytes);
84 std::vector<unsigned char> witnessprogram;
86 if (witnessversion == 0 && witnessprogram.size() == 20) {
88 vSolutionsRet.push_back(witnessprogram);
91 if (witnessversion == 0 && witnessprogram.size() == 32) {
93 vSolutionsRet.push_back(witnessprogram);
110 const CScript& script1 = scriptPubKey;
111 for (
const std::pair<txnouttype, CScript>& tplate : mTemplates)
113 const CScript& script2 = tplate.second;
114 vSolutionsRet.
clear();
117 std::vector<unsigned char> vch1, vch2;
126 if (pc1 == script1.
end() && pc2 == script2.
end())
129 typeRet = tplate.first;
133 unsigned char m = vSolutionsRet.front()[0];
134 unsigned char n = vSolutionsRet.back()[0];
135 if (m < 1 || n < 1 || m > n || vSolutionsRet.size()-2 != n)
140 if (!script1.
GetOp(pc1, opcode1, vch1))
142 if (!script2.
GetOp(pc2, opcode2, vch2))
148 while (vch1.size() >= 33 && vch1.size() <= 65)
150 vSolutionsRet.push_back(vch1);
151 if (!script1.
GetOp(pc1, opcode1, vch1))
154 if (!script2.
GetOp(pc2, opcode2, vch2))
162 if (vch1.size() < 33 || vch1.size() > 65)
164 vSolutionsRet.push_back(vch1);
168 if (vch1.size() !=
sizeof(
uint160))
170 vSolutionsRet.push_back(vch1);
174 if (opcode1 ==
OP_0 ||
178 vSolutionsRet.push_back(
valtype(1, n));
188 if(vch1.empty() || vch1.size() > 4 || (vch1.back() & 0x80))
201 if(contractConsensus) {
203 if (version.
rootVM != 0 && val < 1) {
206 if (val > MAX_BLOCK_GAS_LIMIT_DGP) {
213 if (version.
rootVM != 0 && val < STANDARD_MINIMUM_GAS_LIMIT) {
216 if (val > DEFAULT_BLOCK_GAS_LIMIT_DGP / 2) {
230 if(contractConsensus) {
232 if (version.
rootVM != 0 && val < 1) {
237 if (version.
rootVM != 0 && val < STANDARD_MINIMUM_GAS_PRICE) {
255 else if (opcode1 != opcode2 || vch1 != vch2)
263 vSolutionsRet.clear();
270 std::vector<valtype> vSolutions;
272 if (!
Solver(scriptPubKey, whichType, vSolutions))
276 *typeRet = whichType;
285 addressRet = pubKey.
GetID();
306 std::vector<valtype> vSolutions;
307 if (!
Solver(scriptPubKey, typeRet, vSolutions))
316 nRequiredRet = vSolutions.front()[0];
317 for (
unsigned int i = 1; i < vSolutions.size()-1; i++)
324 addressRet.push_back(address);
327 if (addressRet.empty())
336 addressRet.push_back(address);
344 class CScriptVisitor :
public boost::static_visitor<bool>
349 CScriptVisitor(
CScript *scriptin) { script = scriptin; }
356 bool operator()(
const CKeyID &keyID)
const {
362 bool operator()(
const CScriptID &scriptID)
const {
374 boost::apply_visitor(CScriptVisitor(&script), dest);
388 for (
const CPubKey& key : keys)
399 std::vector<std::vector<unsigned char> > vSolutions;
400 if (
Solver(redeemscript, typ, vSolutions)) {
402 unsigned char h160[20];
404 ret << OP_0 << std::vector<unsigned char>(&h160[0], &h160[20]);
407 ret <<
OP_0 << vSolutions[0];
CSHA256 & Write(const unsigned char *data, size_t len)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
bool Solver(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< std::vector< unsigned char > > &vSolutionsRet, bool contractConsensus)
Return public keys or hashes from scriptPubKey, for 'standard' transaction types. ...
static int DecodeOP_N(opcodetype opcode)
Encode/decode small integers:
static VersionVM GetNoExec()
bool IsPushOnly(const_iterator pc) const
Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical).
bool IsPayToScriptHash() const
static VersionVM GetEVMDefault()
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
uint160 Hash160(const T1 pbegin, const T1 pend)
Compute the 160-bit hash an object.
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< CTxDestination > &addressRet, int &nRequiredRet)
opcodetype
Script opcodes.
static uint64_t vch_to_uint64(const std::vector< unsigned char > &vch)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet, txnouttype *typeRet)
An encapsulated public key.
bool IsWitnessProgram(int &version, std::vector< unsigned char > &program) const
std::vector< unsigned char > valtype
CHash160 & Write(const unsigned char *data, size_t len)
const char * GetTxnOutputType(txnouttype t)
static VersionVM fromRaw(uint32_t val)
CScript GetScriptForDestination(const CTxDestination &dest)
const unsigned char * begin() const
static opcodetype EncodeOP_N(int n)
Serialized script, used inside transaction inputs and outputs.
void Finalize(unsigned char hash[OUTPUT_SIZE])
A reference to a CKey: the Hash160 of its serialized public key.
A reference to a CScript: the Hash160 of its serialization (see script.h)
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
bool GetOp(iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet)
struct evm_uint160be address(struct evm_env *env)
A hasher class for Fabcoin's 160-bit hash (SHA-256 + RIPEMD-160).
A hasher class for SHA-256.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
CScript GetScriptForWitness(const CScript &redeemscript)
unsigned nMaxDatacarrierBytes
const unsigned char * end() const
std::vector< unsigned char > ToByteVector(const T &in)
unsigned int size() const