MCPcopy Create free account
hub / github.com/LUX-Core/lux / ProcessSubScript

Method ProcessSubScript

src/rpcmisc.cpp:164–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162 DescribeAddressVisitor(isminetype mineIn) : mine(mineIn) {}
163
164 void ProcessSubScript(const CScript& subscript, UniValue& obj, bool include_addresses = false) const
165 {
166 // Always present: script type and redeemscript
167 txnouttype which_type;
168 std::vector<std::vector<unsigned char>> solutions_data;
169 Solver(subscript, which_type, solutions_data);
170 obj.pushKV("script", GetTxnOutputType(which_type));
171 obj.pushKV("hex", HexStr(subscript.begin(), subscript.end()));
172
173 CTxDestination embedded;
174 UniValue a(UniValue::VARR);
175 if (ExtractDestination(subscript, embedded)) {
176 // Only when the script corresponds to an address.
177 UniValue subobj = boost::apply_visitor(*this, embedded);
178 subobj.pushKV("address", EncodeDestination(embedded));
179 subobj.pushKV("scriptPubKey", HexStr(subscript.begin(), subscript.end()));
180 // Always report the pubkey at the top level, so that `getnewaddress()['pubkey']` always works.
181 if (subobj.exists("pubkey")) obj.pushKV("pubkey", subobj["pubkey"]);
182 obj.pushKV("embedded", std::move(subobj));
183 if (include_addresses) a.push_back(EncodeDestination(embedded));
184 } else if (which_type == TX_MULTISIG) {
185 // Also report some information on multisig scripts (which do not have a corresponding address).
186 // TODO: abstract out the common functionality between this logic and ExtractDestinations.
187 obj.pushKV("sigsrequired", solutions_data[0][0]);
188 UniValue pubkeys(UniValue::VARR);
189 for (size_t i = 1; i < solutions_data.size() - 1; ++i) {
190 CPubKey key(solutions_data[i].begin(), solutions_data[i].end());
191 if (include_addresses) a.push_back(EncodeDestination(key.GetID()));
192 pubkeys.push_back(HexStr(key.begin(), key.end()));
193 }
194 obj.pushKV("pubkeys", std::move(pubkeys));
195 }
196
197 // The "addresses" field is confusing because it refers to public keys using their P2PKH address.
198 // For that reason, only add the 'addresses' field when needed for backward compatibility. New applications
199 // can use the 'embedded'->'address' field for P2SH or P2WSH wrapped addresses, and 'pubkeys' for
200 // inspecting multisig participants.
201 if (include_addresses) obj.pushKV("addresses", std::move(a));
202 }
203
204 UniValue operator()(const CNoDestination& dest) const { return UniValue(UniValue::VOBJ); }
205

Callers

nothing calls this directly

Calls 12

SolverFunction · 0.85
GetTxnOutputTypeFunction · 0.85
HexStrFunction · 0.85
ExtractDestinationFunction · 0.85
EncodeDestinationFunction · 0.85
pushKVMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
existsMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45
GetIDMethod · 0.45

Tested by

no test coverage detected