From d39925b08a5dabda5d24b50a240cc696c13ee0fb Mon Sep 17 00:00:00 2001 From: Glenn Willen Date: Thu, 6 Jun 2019 22:10:52 -0700 Subject: [PATCH] Disable PSBT RPCs when not in g_con_elementsmode. --- src/rpc/rawtransaction.cpp | 18 ++++++++++++++++++ src/wallet/rpcwallet.cpp | 12 ++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 49c2da48c2..bf5bfa460d 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -1312,6 +1312,9 @@ static std::string WriteHDKeypath(std::vector& keypath) UniValue blindpsbt(const JSONRPCRequest& request) { + if (!g_con_elementsmode) + throw std::runtime_error("PSBT operations are disabled when not in elementsmode.\n"); + if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) throw std::runtime_error( RPCHelpMan{"blindpsbt", @@ -1432,6 +1435,9 @@ UniValue blindpsbt(const JSONRPCRequest& request) UniValue decodepsbt(const JSONRPCRequest& request) { + if (!g_con_elementsmode) + throw std::runtime_error("PSBT operations are disabled when not in elementsmode.\n"); + if (request.fHelp || request.params.size() != 1) throw std::runtime_error( RPCHelpMan{"decodepsbt", @@ -1767,6 +1773,9 @@ UniValue decodepsbt(const JSONRPCRequest& request) UniValue combinepsbt(const JSONRPCRequest& request) { + if (!g_con_elementsmode) + throw std::runtime_error("PSBT operations are disabled when not in elementsmode.\n"); + if (request.fHelp || request.params.size() != 1) throw std::runtime_error( RPCHelpMan{"combinepsbt", @@ -1815,6 +1824,9 @@ UniValue combinepsbt(const JSONRPCRequest& request) UniValue finalizepsbt(const JSONRPCRequest& request) { + if (!g_con_elementsmode) + throw std::runtime_error("PSBT operations are disabled when not in elementsmode.\n"); + if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) throw std::runtime_error( RPCHelpMan{"finalizepsbt", @@ -1873,6 +1885,9 @@ UniValue finalizepsbt(const JSONRPCRequest& request) UniValue createpsbt(const JSONRPCRequest& request) { + if (!g_con_elementsmode) + throw std::runtime_error("PSBT operations are disabled when not in elementsmode.\n"); + if (request.fHelp || request.params.size() < 2 || request.params.size() > 4) throw std::runtime_error( RPCHelpMan{"createpsbt", @@ -1948,6 +1963,9 @@ UniValue createpsbt(const JSONRPCRequest& request) UniValue converttopsbt(const JSONRPCRequest& request) { + if (!g_con_elementsmode) + throw std::runtime_error("PSBT operations are disabled when not in elementsmode.\n"); + if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) throw std::runtime_error( RPCHelpMan{"converttopsbt", diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 39cb6aca5b..11c2463b70 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4372,6 +4372,9 @@ void AddKeypathToMap(const CWallet* pwallet, const CKeyID& keyID, std::map const wallet = GetWalletForJSONRPCRequest(request); CWallet* const pwallet = wallet.get(); @@ -4422,6 +4425,9 @@ UniValue walletfillpsbtdata(const JSONRPCRequest& request) UniValue walletsignpsbt(const JSONRPCRequest& request) { + if (!g_con_elementsmode) + throw std::runtime_error("PSBT operations are disabled when not in elementsmode.\n"); + std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); CWallet* const pwallet = wallet.get(); @@ -4486,6 +4492,9 @@ UniValue walletsignpsbt(const JSONRPCRequest& request) UniValue walletprocesspsbt(const JSONRPCRequest& request) { + if (!g_con_elementsmode) + throw std::runtime_error("PSBT operations are disabled when not in elementsmode.\n"); + std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); CWallet* const pwallet = wallet.get(); @@ -4555,6 +4564,9 @@ UniValue walletprocesspsbt(const JSONRPCRequest& request) UniValue walletcreatefundedpsbt(const JSONRPCRequest& request) { + if (!g_con_elementsmode) + throw std::runtime_error("PSBT operations are disabled when not in elementsmode.\n"); + std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); CWallet* const pwallet = wallet.get();