Skip to content

Commit

Permalink
Disable PSBT RPCs when not in g_con_elementsmode.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwillen committed Jul 31, 2019
1 parent 2848b52 commit d39925b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,9 @@ static std::string WriteHDKeypath(std::vector<uint32_t>& 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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4372,6 +4372,9 @@ void AddKeypathToMap(const CWallet* pwallet, const CKeyID& keyID, std::map<CPubK

UniValue walletfillpsbtdata(const JSONRPCRequest& request)
{
if (!g_con_elementsmode)
throw std::runtime_error("PSBT operations are disabled when not in elementsmode.\n");

std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();

Expand Down Expand Up @@ -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<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();

Expand Down Expand Up @@ -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<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();

Expand Down Expand Up @@ -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<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
CWallet* const pwallet = wallet.get();

Expand Down

0 comments on commit d39925b

Please sign in to comment.