MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / ProcessSubScript

Method ProcessSubScript

src/wallet/rpcwallet.cpp:4042–4084  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4040 CWallet * const pwallet;
4041
4042 void ProcessSubScript(const CScript& subscript, UniValue& obj, bool include_addresses = false) const
4043 {
4044 // Always present: script type and redeemscript
4045 txnouttype which_type;
4046 std::vector<std::vector<unsigned char>> solutions_data;
4047 Solver(subscript, which_type, solutions_data);
4048 obj.pushKV("script", GetTxnOutputType(which_type));
4049 obj.pushKV("hex", HexStr(subscript.begin(), subscript.end()));
4050
4051 CTxDestination embedded;
4052 UniValue a(UniValue::VARR);
4053 if (ExtractDestination(subscript, embedded)) {
4054 // Only when the script corresponds to an address.
4055 UniValue subobj(UniValue::VOBJ);
4056 UniValue detail = DescribeAddress(embedded);
4057 subobj.pushKVs(detail);
4058 UniValue wallet_detail = boost::apply_visitor(*this, embedded);
4059 subobj.pushKVs(wallet_detail);
4060 subobj.pushKV("address", EncodeDestination(embedded));
4061 subobj.pushKV("scriptPubKey", HexStr(subscript.begin(), subscript.end()));
4062 // Always report the pubkey at the top level, so that `getnewaddress()['pubkey']` always works.
4063 if (subobj.exists("pubkey")) obj.pushKV("pubkey", subobj["pubkey"]);
4064 obj.pushKV("embedded", std::move(subobj));
4065 if (include_addresses) a.push_back(EncodeDestination(embedded));
4066 } else if (which_type == TX_MULTISIG) {
4067 // Also report some information on multisig scripts (which do not have a corresponding address).
4068 // TODO: abstract out the common functionality between this logic and ExtractDestinations.
4069 obj.pushKV("sigsrequired", solutions_data[0][0]);
4070 UniValue pubkeys(UniValue::VARR);
4071 for (size_t i = 1; i < solutions_data.size() - 1; ++i) {
4072 CPubKey key(solutions_data[i].begin(), solutions_data[i].end());
4073 if (include_addresses) a.push_back(EncodeDestination(key.GetID()));
4074 pubkeys.push_back(HexStr(key.begin(), key.end()));
4075 }
4076 obj.pushKV("pubkeys", std::move(pubkeys));
4077 }
4078
4079 // The "addresses" field is confusing because it refers to public keys using their P2PKH address.
4080 // For that reason, only add the 'addresses' field when needed for backward compatibility. New applications
4081 // can use the 'embedded'->'address' field for P2SH or P2WSH wrapped addresses, and 'pubkeys' for
4082 // inspecting multisig participants.
4083 if (include_addresses) obj.pushKV("addresses", std::move(a));
4084 }
4085
4086 explicit DescribeWalletAddressVisitor(CWallet* _pwallet) : pwallet(_pwallet) {}
4087

Callers

nothing calls this directly

Calls 14

SolverFunction · 0.85
GetTxnOutputTypeFunction · 0.85
HexStrFunction · 0.85
ExtractDestinationFunction · 0.85
DescribeAddressFunction · 0.85
EncodeDestinationFunction · 0.85
pushKVsMethod · 0.80
GetIDMethod · 0.80
pushKVMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected