33
33
34
34
#include < univalue.h>
35
35
36
- #ifdef ENABLE_WALLET
37
36
class DescribeAddressVisitor : public boost ::static_visitor<UniValue>
38
37
{
39
38
public:
40
- CWallet * const pwallet;
39
+ explicit DescribeAddressVisitor () {}
40
+
41
+ UniValue operator ()(const CNoDestination &dest) const { return UniValue (UniValue::VOBJ); }
42
+
43
+ UniValue operator ()(const CKeyID &keyID) const {
44
+ UniValue obj (UniValue::VOBJ);
45
+ obj.pushKV (" isscript" , false );
46
+ obj.pushKV (" iswitness" , false );
47
+ return obj;
48
+ }
49
+
50
+ UniValue operator ()(const CScriptID &scriptID) const {
51
+ UniValue obj (UniValue::VOBJ);
52
+ obj.pushKV (" isscript" , true );
53
+ obj.pushKV (" iswitness" , false );
54
+ return obj;
55
+ }
56
+
57
+ UniValue operator ()(const WitnessV0KeyHash& id) const
58
+ {
59
+ UniValue obj (UniValue::VOBJ);
60
+ obj.pushKV (" isscript" , false );
61
+ obj.pushKV (" iswitness" , true );
62
+ obj.pushKV (" witness_version" , 0 );
63
+ obj.pushKV (" witness_program" , HexStr (id.begin (), id.end ()));
64
+ return obj;
65
+ }
66
+
67
+ UniValue operator ()(const WitnessV0ScriptHash& id) const
68
+ {
69
+ UniValue obj (UniValue::VOBJ);
70
+ obj.pushKV (" isscript" , true );
71
+ obj.pushKV (" iswitness" , true );
72
+ obj.pushKV (" witness_version" , 0 );
73
+ obj.pushKV (" witness_program" , HexStr (id.begin (), id.end ()));
74
+ return obj;
75
+ }
41
76
42
- explicit DescribeAddressVisitor (CWallet *_pwallet) : pwallet(_pwallet) {}
77
+ UniValue operator ()(const WitnessUnknown& id) const
78
+ {
79
+ UniValue obj (UniValue::VOBJ);
80
+ obj.pushKV (" iswitness" , true );
81
+ obj.pushKV (" witness_version" , (int )id.version );
82
+ obj.pushKV (" witness_program" , HexStr (id.program , id.program + id.length ));
83
+ return obj;
84
+ }
85
+ };
86
+
87
+ #ifdef ENABLE_WALLET
88
+ class DescribeWalletAddressVisitor : public boost ::static_visitor<UniValue>
89
+ {
90
+ public:
91
+ CWallet * const pwallet;
43
92
44
93
void ProcessSubScript (const CScript& subscript, UniValue& obj, bool include_addresses = false ) const
45
94
{
@@ -54,7 +103,11 @@ class DescribeAddressVisitor : public boost::static_visitor<UniValue>
54
103
UniValue a (UniValue::VARR);
55
104
if (ExtractDestination (subscript, embedded)) {
56
105
// Only when the script corresponds to an address.
57
- UniValue subobj = boost::apply_visitor (*this , embedded);
106
+ UniValue subobj (UniValue::VOBJ);
107
+ UniValue detail = boost::apply_visitor (DescribeAddressVisitor (), embedded);
108
+ subobj.pushKVs (detail);
109
+ UniValue wallet_detail = boost::apply_visitor (*this , embedded);
110
+ subobj.pushKVs (wallet_detail);
58
111
subobj.pushKV (" address" , EncodeDestination (embedded));
59
112
subobj.pushKV (" scriptPubKey" , HexStr (subscript.begin (), subscript.end ()));
60
113
// Always report the pubkey at the top level, so that `getnewaddress()['pubkey']` always works.
@@ -81,13 +134,13 @@ class DescribeAddressVisitor : public boost::static_visitor<UniValue>
81
134
if (include_addresses) obj.pushKV (" addresses" , std::move (a));
82
135
}
83
136
137
+ explicit DescribeWalletAddressVisitor (CWallet *_pwallet) : pwallet(_pwallet) {}
138
+
84
139
UniValue operator ()(const CNoDestination &dest) const { return UniValue (UniValue::VOBJ); }
85
140
86
141
UniValue operator ()(const CKeyID &keyID) const {
87
142
UniValue obj (UniValue::VOBJ);
88
143
CPubKey vchPubKey;
89
- obj.pushKV (" isscript" , false );
90
- obj.pushKV (" iswitness" , false );
91
144
if (pwallet && pwallet->GetPubKey (keyID, vchPubKey)) {
92
145
obj.pushKV (" pubkey" , HexStr (vchPubKey));
93
146
obj.pushKV (" iscompressed" , vchPubKey.IsCompressed ());
@@ -98,8 +151,6 @@ class DescribeAddressVisitor : public boost::static_visitor<UniValue>
98
151
UniValue operator ()(const CScriptID &scriptID) const {
99
152
UniValue obj (UniValue::VOBJ);
100
153
CScript subscript;
101
- obj.pushKV (" isscript" , true );
102
- obj.pushKV (" iswitness" , false );
103
154
if (pwallet && pwallet->GetCScript (scriptID, subscript)) {
104
155
ProcessSubScript (subscript, obj, true );
105
156
}
@@ -110,10 +161,6 @@ class DescribeAddressVisitor : public boost::static_visitor<UniValue>
110
161
{
111
162
UniValue obj (UniValue::VOBJ);
112
163
CPubKey pubkey;
113
- obj.pushKV (" isscript" , false );
114
- obj.pushKV (" iswitness" , true );
115
- obj.pushKV (" witness_version" , 0 );
116
- obj.pushKV (" witness_program" , HexStr (id.begin (), id.end ()));
117
164
if (pwallet && pwallet->GetPubKey (CKeyID (id), pubkey)) {
118
165
obj.pushKV (" pubkey" , HexStr (pubkey));
119
166
}
@@ -124,10 +171,6 @@ class DescribeAddressVisitor : public boost::static_visitor<UniValue>
124
171
{
125
172
UniValue obj (UniValue::VOBJ);
126
173
CScript subscript;
127
- obj.pushKV (" isscript" , true );
128
- obj.pushKV (" iswitness" , true );
129
- obj.pushKV (" witness_version" , 0 );
130
- obj.pushKV (" witness_program" , HexStr (id.begin (), id.end ()));
131
174
CRIPEMD160 hasher;
132
175
uint160 hash;
133
176
hasher.Write (id.begin (), 32 ).Finalize (hash.begin ());
@@ -137,15 +180,7 @@ class DescribeAddressVisitor : public boost::static_visitor<UniValue>
137
180
return obj;
138
181
}
139
182
140
- UniValue operator ()(const WitnessUnknown& id) const
141
- {
142
- UniValue obj (UniValue::VOBJ);
143
- CScript subscript;
144
- obj.pushKV (" iswitness" , true );
145
- obj.pushKV (" witness_version" , (int )id.version );
146
- obj.pushKV (" witness_program" , HexStr (id.program , id.program + id.length ));
147
- return obj;
148
- }
183
+ UniValue operator ()(const WitnessUnknown& id) const { return UniValue (UniValue::VOBJ); }
149
184
};
150
185
#endif
151
186
@@ -219,8 +254,10 @@ UniValue validateaddress(const JSONRPCRequest& request)
219
254
isminetype mine = pwallet ? IsMine (*pwallet, dest) : ISMINE_NO;
220
255
ret.pushKV (" ismine" , bool (mine & ISMINE_SPENDABLE));
221
256
ret.pushKV (" iswatchonly" , bool (mine & ISMINE_WATCH_ONLY));
222
- UniValue detail = boost::apply_visitor (DescribeAddressVisitor (pwallet ), dest);
257
+ UniValue detail = boost::apply_visitor (DescribeAddressVisitor (), dest);
223
258
ret.pushKVs (detail);
259
+ UniValue wallet_detail = boost::apply_visitor (DescribeWalletAddressVisitor (pwallet), dest);
260
+ ret.pushKVs (wallet_detail);
224
261
if (pwallet && pwallet->mapAddressBook .count (dest)) {
225
262
ret.pushKV (" account" , pwallet->mapAddressBook [dest].name );
226
263
}
0 commit comments