aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/rpc/misc.cpp66
-rw-r--r--src/rpc/util.cpp61
-rw-r--r--src/rpc/util.h9
4 files changed, 83 insertions, 54 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 4fbd605d9e..aa1647a63a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -215,6 +215,7 @@ libbitcoin_server_a_SOURCES = \
rpc/rawtransaction.cpp \
rpc/safemode.cpp \
rpc/server.cpp \
+ rpc/util.cpp \
script/sigcache.cpp \
script/ismine.cpp \
timedata.cpp \
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;
diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp
index 09ded4e46e..cdcb68d15f 100644
--- a/src/rpc/util.cpp
+++ b/src/rpc/util.cpp
@@ -66,3 +66,64 @@ CScript CreateMultisigRedeemscript(const int required, const std::vector<CPubKey
return result;
}
+
+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;
+ }
+};
+
+UniValue DescribeAddress(const CTxDestination& dest)
+{
+ return boost::apply_visitor(DescribeAddressVisitor(), dest);
+}
diff --git a/src/rpc/util.h b/src/rpc/util.h
index 568a4260ba..5380d45a83 100644
--- a/src/rpc/util.h
+++ b/src/rpc/util.h
@@ -5,6 +5,13 @@
#ifndef BITCOIN_RPC_UTIL_H
#define BITCOIN_RPC_UTIL_H
+#include <pubkey.h>
+#include <script/standard.h>
+#include <univalue.h>
+#include <utilstrencodings.h>
+
+#include <boost/variant/static_visitor.hpp>
+
#include <string>
#include <vector>
@@ -16,4 +23,6 @@ CPubKey HexToPubKey(const std::string& hex_in);
CPubKey AddrToPubKey(CKeyStore* const keystore, const std::string& addr_in);
CScript CreateMultisigRedeemscript(const int required, const std::vector<CPubKey>& pubkeys);
+UniValue DescribeAddress(const CTxDestination& dest);
+
#endif // BITCOIN_RPC_UTIL_H