diff options
author | John Newbery <john@johnnewbery.com> | 2017-12-04 12:49:20 -0500 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2018-02-16 12:09:26 -0500 |
commit | 1598f32304cd55b83ecc623ee0f9e30b4e087b7d (patch) | |
tree | ec538026ed4ed137e19b75ea104f8ba3d71ab8f3 /src/rpc/misc.cpp | |
parent | 39633ecd5c18ca29cb551f701e57e8cec3e609da (diff) |
[rpc] Move DescribeAddressVisitor to rpc/util
Diffstat (limited to 'src/rpc/misc.cpp')
-rw-r--r-- | src/rpc/misc.cpp | 66 |
1 files changed, 12 insertions, 54 deletions
diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index a1e39be64e..f7d62a6326 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -33,57 +33,6 @@ #include <univalue.h> -class DescribeAddressVisitor : public boost::static_visitor<UniValue> -{ -public: - explicit DescribeAddressVisitor() {} - - UniValue operator()(const CNoDestination &dest) const { return UniValue(UniValue::VOBJ); } - - UniValue operator()(const CKeyID &keyID) const { - UniValue obj(UniValue::VOBJ); - obj.pushKV("isscript", false); - obj.pushKV("iswitness", false); - return obj; - } - - UniValue operator()(const CScriptID &scriptID) const { - UniValue obj(UniValue::VOBJ); - obj.pushKV("isscript", true); - obj.pushKV("iswitness", false); - return obj; - } - - UniValue operator()(const WitnessV0KeyHash& id) const - { - UniValue obj(UniValue::VOBJ); - obj.pushKV("isscript", false); - obj.pushKV("iswitness", true); - obj.pushKV("witness_version", 0); - obj.pushKV("witness_program", HexStr(id.begin(), id.end())); - return obj; - } - - UniValue operator()(const WitnessV0ScriptHash& id) const - { - UniValue obj(UniValue::VOBJ); - obj.pushKV("isscript", true); - obj.pushKV("iswitness", true); - obj.pushKV("witness_version", 0); - obj.pushKV("witness_program", HexStr(id.begin(), id.end())); - return obj; - } - - UniValue operator()(const WitnessUnknown& id) const - { - UniValue obj(UniValue::VOBJ); - obj.pushKV("iswitness", true); - obj.pushKV("witness_version", (int)id.version); - obj.pushKV("witness_program", HexStr(id.program, id.program + id.length)); - return obj; - } -}; - #ifdef ENABLE_WALLET class DescribeWalletAddressVisitor : public boost::static_visitor<UniValue> { @@ -182,6 +131,15 @@ public: UniValue operator()(const WitnessUnknown& id) const { return UniValue(UniValue::VOBJ); } }; + +UniValue DescribeWalletAddress(CWallet* pwallet, const CTxDestination& dest) +{ + UniValue ret(UniValue::VOBJ); + UniValue detail = DescribeAddress(dest); + ret.pushKVs(detail); + ret.pushKVs(boost::apply_visitor(DescribeWalletAddressVisitor(pwallet), dest)); + return ret; +} #endif UniValue validateaddress(const JSONRPCRequest& request) @@ -254,10 +212,8 @@ UniValue validateaddress(const JSONRPCRequest& request) isminetype mine = pwallet ? IsMine(*pwallet, dest) : ISMINE_NO; ret.pushKV("ismine", bool(mine & ISMINE_SPENDABLE)); ret.pushKV("iswatchonly", bool(mine & ISMINE_WATCH_ONLY)); - UniValue detail = boost::apply_visitor(DescribeAddressVisitor(), dest); + UniValue detail = DescribeWalletAddress(pwallet, dest); ret.pushKVs(detail); - UniValue wallet_detail = boost::apply_visitor(DescribeWalletAddressVisitor(pwallet), dest); - ret.pushKVs(wallet_detail); if (pwallet && pwallet->mapAddressBook.count(dest)) { ret.pushKV("account", pwallet->mapAddressBook[dest].name); } @@ -284,6 +240,8 @@ UniValue validateaddress(const JSONRPCRequest& request) } } } +#else + ret.pushKvs = DescribeAddress(dest); #endif } return ret; |