@@ -87,41 +87,36 @@ static bool MatchMultisig(const CScript& script, unsigned int& required, std::ve
8787 return (it + 1 == script.end ());
8888}
8989
90- bool Solver (const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char > >& vSolutionsRet)
90+ txnouttype Solver (const CScript& scriptPubKey, std::vector<std::vector<unsigned char >>& vSolutionsRet)
9191{
9292 vSolutionsRet.clear ();
9393
9494 // Shortcut for pay-to-script-hash, which are more constrained than the other types:
9595 // it is always OP_HASH160 20 [20 byte hash] OP_EQUAL
9696 if (scriptPubKey.IsPayToScriptHash ())
9797 {
98- typeRet = TX_SCRIPTHASH;
9998 std::vector<unsigned char > hashBytes (scriptPubKey.begin ()+2 , scriptPubKey.begin ()+22 );
10099 vSolutionsRet.push_back (hashBytes);
101- return true ;
100+ return TX_SCRIPTHASH ;
102101 }
103102
104103 int witnessversion;
105104 std::vector<unsigned char > witnessprogram;
106105 if (scriptPubKey.IsWitnessProgram (witnessversion, witnessprogram)) {
107106 if (witnessversion == 0 && witnessprogram.size () == WITNESS_V0_KEYHASH_SIZE) {
108- typeRet = TX_WITNESS_V0_KEYHASH;
109107 vSolutionsRet.push_back (witnessprogram);
110- return true ;
108+ return TX_WITNESS_V0_KEYHASH ;
111109 }
112110 if (witnessversion == 0 && witnessprogram.size () == WITNESS_V0_SCRIPTHASH_SIZE) {
113- typeRet = TX_WITNESS_V0_SCRIPTHASH;
114111 vSolutionsRet.push_back (witnessprogram);
115- return true ;
112+ return TX_WITNESS_V0_SCRIPTHASH ;
116113 }
117114 if (witnessversion != 0 ) {
118- typeRet = TX_WITNESS_UNKNOWN;
119115 vSolutionsRet.push_back (std::vector<unsigned char >{(unsigned char )witnessversion});
120116 vSolutionsRet.push_back (std::move (witnessprogram));
121- return true ;
117+ return TX_WITNESS_UNKNOWN ;
122118 }
123- typeRet = TX_NONSTANDARD;
124- return false ;
119+ return TX_NONSTANDARD;
125120 }
126121
127122 // Provably prunable, data-carrying output
@@ -130,47 +125,39 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::v
130125 // byte passes the IsPushOnly() test we don't care what exactly is in the
131126 // script.
132127 if (scriptPubKey.size () >= 1 && scriptPubKey[0 ] == OP_RETURN && scriptPubKey.IsPushOnly (scriptPubKey.begin ()+1 )) {
133- typeRet = TX_NULL_DATA;
134- return true ;
128+ return TX_NULL_DATA;
135129 }
136130
137131 std::vector<unsigned char > data;
138132 if (MatchPayToPubkey (scriptPubKey, data)) {
139- typeRet = TX_PUBKEY;
140133 vSolutionsRet.push_back (std::move (data));
141- return true ;
134+ return TX_PUBKEY ;
142135 }
143136
144137 if (MatchPayToPubkeyHash (scriptPubKey, data)) {
145- typeRet = TX_PUBKEYHASH;
146138 vSolutionsRet.push_back (std::move (data));
147- return true ;
139+ return TX_PUBKEYHASH ;
148140 }
149141
150142 unsigned int required;
151143 std::vector<std::vector<unsigned char >> keys;
152144 if (MatchMultisig (scriptPubKey, required, keys)) {
153- typeRet = TX_MULTISIG;
154145 vSolutionsRet.push_back ({static_cast <unsigned char >(required)}); // safe as required is in range 1..16
155146 vSolutionsRet.insert (vSolutionsRet.end (), keys.begin (), keys.end ());
156147 vSolutionsRet.push_back ({static_cast <unsigned char >(keys.size ())}); // safe as size is in range 1..16
157- return true ;
148+ return TX_MULTISIG ;
158149 }
159150
160151 vSolutionsRet.clear ();
161- typeRet = TX_NONSTANDARD;
162- return false ;
152+ return TX_NONSTANDARD;
163153}
164154
165155bool ExtractDestination (const CScript& scriptPubKey, CTxDestination& addressRet)
166156{
167157 std::vector<valtype> vSolutions;
168- txnouttype whichType;
169- if (!Solver (scriptPubKey, whichType, vSolutions))
170- return false ;
158+ txnouttype whichType = Solver (scriptPubKey, vSolutions);
171159
172- if (whichType == TX_PUBKEY)
173- {
160+ if (whichType == TX_PUBKEY) {
174161 CPubKey pubKey (vSolutions[0 ]);
175162 if (!pubKey.IsValid ())
176163 return false ;
@@ -212,11 +199,11 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
212199bool ExtractDestinations (const CScript& scriptPubKey, txnouttype& typeRet, std::vector<CTxDestination>& addressRet, int & nRequiredRet)
213200{
214201 addressRet.clear ();
215- typeRet = TX_NONSTANDARD;
216202 std::vector<valtype> vSolutions;
217- if (!Solver (scriptPubKey, typeRet, vSolutions))
203+ typeRet = Solver (scriptPubKey, vSolutions);
204+ if (typeRet == TX_NONSTANDARD) {
218205 return false ;
219- if (typeRet == TX_NULL_DATA){
206+ } else if (typeRet == TX_NULL_DATA) {
220207 // This is data, not addresses
221208 return false ;
222209 }
@@ -324,14 +311,12 @@ CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys)
324311
325312CScript GetScriptForWitness (const CScript& redeemscript)
326313{
327- txnouttype typ;
328314 std::vector<std::vector<unsigned char > > vSolutions;
329- if (Solver (redeemscript, typ, vSolutions)) {
330- if (typ == TX_PUBKEY) {
331- return GetScriptForDestination (WitnessV0KeyHash (Hash160 (vSolutions[0 ].begin (), vSolutions[0 ].end ())));
332- } else if (typ == TX_PUBKEYHASH) {
333- return GetScriptForDestination (WitnessV0KeyHash (vSolutions[0 ]));
334- }
315+ txnouttype typ = Solver (redeemscript, vSolutions);
316+ if (typ == TX_PUBKEY) {
317+ return GetScriptForDestination (WitnessV0KeyHash (Hash160 (vSolutions[0 ].begin (), vSolutions[0 ].end ())));
318+ } else if (typ == TX_PUBKEYHASH) {
319+ return GetScriptForDestination (WitnessV0KeyHash (vSolutions[0 ]));
335320 }
336321 return GetScriptForDestination (WitnessV0ScriptHash (redeemscript));
337322}
0 commit comments