33
33
34
34
#include < univalue.h>
35
35
36
- class DescribeAddressVisitor : public boost ::static_visitor<UniValue>
37
- {
38
- public:
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
- }
76
-
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
36
#ifdef ENABLE_WALLET
88
37
class DescribeWalletAddressVisitor : public boost ::static_visitor<UniValue>
89
38
{
@@ -182,6 +131,15 @@ class DescribeWalletAddressVisitor : public boost::static_visitor<UniValue>
182
131
183
132
UniValue operator ()(const WitnessUnknown& id) const { return UniValue (UniValue::VOBJ); }
184
133
};
134
+
135
+ UniValue DescribeWalletAddress (CWallet* pwallet, const CTxDestination& dest)
136
+ {
137
+ UniValue ret (UniValue::VOBJ);
138
+ UniValue detail = DescribeAddress (dest);
139
+ ret.pushKVs (detail);
140
+ ret.pushKVs (boost::apply_visitor (DescribeWalletAddressVisitor (pwallet), dest));
141
+ return ret;
142
+ }
185
143
#endif
186
144
187
145
UniValue validateaddress (const JSONRPCRequest& request)
@@ -254,10 +212,8 @@ UniValue validateaddress(const JSONRPCRequest& request)
254
212
isminetype mine = pwallet ? IsMine (*pwallet, dest) : ISMINE_NO;
255
213
ret.pushKV (" ismine" , bool (mine & ISMINE_SPENDABLE));
256
214
ret.pushKV (" iswatchonly" , bool (mine & ISMINE_WATCH_ONLY));
257
- UniValue detail = boost::apply_visitor ( DescribeAddressVisitor () , dest);
215
+ UniValue detail = DescribeWalletAddress (pwallet , dest);
258
216
ret.pushKVs (detail);
259
- UniValue wallet_detail = boost::apply_visitor (DescribeWalletAddressVisitor (pwallet), dest);
260
- ret.pushKVs (wallet_detail);
261
217
if (pwallet && pwallet->mapAddressBook .count (dest)) {
262
218
ret.pushKV (" account" , pwallet->mapAddressBook [dest].name );
263
219
}
@@ -284,6 +240,8 @@ UniValue validateaddress(const JSONRPCRequest& request)
284
240
}
285
241
}
286
242
}
243
+ #else
244
+ ret.pushKvs = DescribeAddress (dest);
287
245
#endif
288
246
}
289
247
return ret;
0 commit comments