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

Class DescribeWalletAddressVisitor

src/wallet/rpcwallet.cpp:4037–4135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4035}
4036
4037class DescribeWalletAddressVisitor : public boost::static_visitor<UniValue>
4038{
4039public:
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
4088 UniValue operator()(const CNoDestination& dest) const { return UniValue(UniValue::VOBJ); }
4089
4090 UniValue operator()(const CKeyID& keyID) const
4091 {
4092 UniValue obj(UniValue::VOBJ);
4093 CPubKey vchPubKey;
4094 if (pwallet && pwallet->GetPubKey(keyID, vchPubKey)) {

Callers 1

DescribeWalletAddressFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected