MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / Solver

Function Solver

src/script/standard.cpp:40–160  ·  view source on GitHub ↗

* Return public keys or hashes from scriptPubKey, for 'standard' transaction types. */

Source from the content-addressed store, hash-verified

38 * Return public keys or hashes from scriptPubKey, for 'standard' transaction types.
39 */
40bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsigned char> >& vSolutionsRet)
41{
42 // Templates
43 static multimap<txnouttype, CScript> mTemplates;
44 if (mTemplates.empty())
45 {
46 // Standard tx, sender provides pubkey, receiver adds signature
47 mTemplates.insert(make_pair(TX_PUBKEY, CScript() << OP_PUBKEY << OP_CHECKSIG));
48
49 // Bitcoin address tx, sender provides hash of pubkey, receiver provides signature and pubkey
50 mTemplates.insert(make_pair(TX_PUBKEYHASH, CScript() << OP_DUP << OP_HASH160 << OP_PUBKEYHASH << OP_EQUALVERIFY << OP_CHECKSIG));
51
52 // Sender provides N pubkeys, receivers provides M signatures
53 mTemplates.insert(make_pair(TX_MULTISIG, CScript() << OP_SMALLINTEGER << OP_PUBKEYS << OP_SMALLINTEGER << OP_CHECKMULTISIG));
54
55 // Empty, provably prunable, data-carrying output
56 if (GetBoolArg("-datacarrier", true))
57 mTemplates.insert(make_pair(TX_NULL_DATA, CScript() << OP_RETURN << OP_SMALLDATA));
58 mTemplates.insert(make_pair(TX_NULL_DATA, CScript() << OP_RETURN));
59 }
60
61 // Shortcut for pay-to-script-hash, which are more constrained than the other types:
62 // it is always OP_HASH160 20 [20 byte hash] OP_EQUAL
63 if (scriptPubKey.IsPayToScriptHash())
64 {
65 typeRet = TX_SCRIPTHASH;
66 vector<unsigned char> hashBytes(scriptPubKey.begin()+2, scriptPubKey.begin()+22);
67 vSolutionsRet.push_back(hashBytes);
68 return true;
69 }
70
71 // Scan templates
72 const CScript& script1 = scriptPubKey;
73 BOOST_FOREACH(const PAIRTYPE(txnouttype, CScript)& tplate, mTemplates)
74 {
75 const CScript& script2 = tplate.second;
76 vSolutionsRet.clear();
77
78 opcodetype opcode1, opcode2;
79 vector<unsigned char> vch1, vch2;
80
81 // Compare
82 CScript::const_iterator pc1 = script1.begin();
83 CScript::const_iterator pc2 = script2.begin();
84 while (true)
85 {
86 if (pc1 == script1.end() && pc2 == script2.end())
87 {
88 // Found a match
89 typeRet = tplate.first;
90 if (typeRet == TX_MULTISIG)
91 {
92 // Additional checks for TX_MULTISIG:
93 unsigned char m = vSolutionsRet.front()[0];
94 unsigned char n = vSolutionsRet.back()[0];
95 if (m < 1 || n < 1 || m > n || vSolutionsRet.size()-2 != n)
96 return false;
97 }

Callers 9

IsRelevantAndUpdateMethod · 0.85
AreInputsStandardFunction · 0.85
IsMineFunction · 0.85
IsStandardFunction · 0.85
ExtractDestinationFunction · 0.85
ExtractDestinationsFunction · 0.85
SignStepFunction · 0.85
CombineSignaturesFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 8

GetBoolArgFunction · 0.85
IsPayToScriptHashMethod · 0.80
CScriptClass · 0.70
emptyMethod · 0.45
insertMethod · 0.45
beginMethod · 0.45
push_backMethod · 0.45
clearMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68