3333
3434#include < univalue.h>
3535
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-
8736#ifdef ENABLE_WALLET
8837class DescribeWalletAddressVisitor : public boost ::static_visitor<UniValue>
8938{
@@ -182,6 +131,15 @@ class DescribeWalletAddressVisitor : public boost::static_visitor<UniValue>
182131
183132 UniValue operator ()(const WitnessUnknown& id) const { return UniValue (UniValue::VOBJ); }
184133};
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+ }
185143#endif
186144
187145UniValue validateaddress (const JSONRPCRequest& request)
@@ -254,10 +212,8 @@ UniValue validateaddress(const JSONRPCRequest& request)
254212 isminetype mine = pwallet ? IsMine (*pwallet, dest) : ISMINE_NO;
255213 ret.pushKV (" ismine" , bool (mine & ISMINE_SPENDABLE));
256214 ret.pushKV (" iswatchonly" , bool (mine & ISMINE_WATCH_ONLY));
257- UniValue detail = boost::apply_visitor ( DescribeAddressVisitor () , dest);
215+ UniValue detail = DescribeWalletAddress (pwallet , dest);
258216 ret.pushKVs (detail);
259- UniValue wallet_detail = boost::apply_visitor (DescribeWalletAddressVisitor (pwallet), dest);
260- ret.pushKVs (wallet_detail);
261217 if (pwallet && pwallet->mapAddressBook .count (dest)) {
262218 ret.pushKV (" account" , pwallet->mapAddressBook [dest].name );
263219 }
@@ -284,6 +240,8 @@ UniValue validateaddress(const JSONRPCRequest& request)
284240 }
285241 }
286242 }
243+ #else
244+ ret.pushKvs = DescribeAddress (dest);
287245#endif
288246 }
289247 return ret;
0 commit comments