Extract wallet RPC utility file

This commit is contained in:
chromatic 2022-06-17 17:57:16 -07:00
parent c0e27fc825
commit 5f5d6a381c
5 changed files with 41 additions and 18 deletions

View File

@ -162,6 +162,7 @@ BITCOIN_CORE_H = \
wallet/coincontrol.h \
wallet/crypter.h \
wallet/db.h \
wallet/rpcutil.h \
wallet/rpcwallet.h \
wallet/wallet.h \
wallet/walletdb.h \
@ -237,6 +238,7 @@ libdogecoin_wallet_a_SOURCES = \
wallet/crypter.cpp \
wallet/db.cpp \
wallet/rpcdump.cpp \
wallet/rpcutil.cpp \
wallet/rpcwallet.cpp \
wallet/wallet.cpp \
wallet/walletdb.cpp \

View File

@ -13,6 +13,7 @@
#include "util.h"
#include "utiltime.h"
#include "wallet.h"
#include "wallet/rpcutil.h"
#include "merkleblock.h"
#include "core_io.h"
@ -574,15 +575,7 @@ UniValue dumpwallet(const JSONRPCRequest& request)
ofstream file;
string userFilename = request.params[0].get_str();
boost::filesystem::path path;
if (userFilename != "") {
boost::filesystem::path p(userFilename);
boost::filesystem::path filename = p.filename();
if (!filename.empty()) {
path = GetBackupDir() / filename;
}
}
boost::filesystem::path path = GetBackupDirFromInput(userFilename);
if (boost::filesystem::exists(path))
throw JSONRPCError(RPC_INVALID_PARAMETER, "Wallet dump file already exists; not overwriting");

20
src/wallet/rpcutil.cpp Normal file
View File

@ -0,0 +1,20 @@
// Copyright (c) 2022 The Dogecoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "wallet/rpcutil.h"
boost::filesystem::path GetBackupDirFromInput(std::string strUserFilename)
{
const boost::filesystem::path backupDir = GetBackupDir();
if (strUserFilename != "") {
boost::filesystem::path p(strUserFilename);
boost::filesystem::path filename = p.filename();
if (!filename.empty())
return backupDir / filename;
}
return backupDir;
}

15
src/wallet/rpcutil.h Normal file
View File

@ -0,0 +1,15 @@
// Copyright (c) 2022 The Dogecoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
/**
* Utility functions for RPC commands
*/
#ifndef DOGECOIN_WALLET_UTIL_H
#define DOGECOIN_WALLET_UTIL_H
#include <boost/filesystem/path.hpp>
#include "util.h"
boost::filesystem::path GetBackupDirFromInput(std::string strUserFilename);
#endif // DOGECOIN_WALLET_UTIL_H

View File

@ -19,6 +19,7 @@
#include "util.h"
#include "utilmoneystr.h"
#include "wallet.h"
#include "wallet/rpcutil.h"
#include "walletdb.h"
#include <stdint.h>
@ -1896,15 +1897,7 @@ UniValue backupwallet(const JSONRPCRequest& request)
LOCK2(cs_main, pwalletMain->cs_wallet);
string userFilename = request.params[0].get_str();
boost::filesystem::path path;
if (userFilename != "") {
boost::filesystem::path p(userFilename);
boost::filesystem::path filename = p.filename();
if (!filename.empty()) {
path = GetBackupDir() / filename;
}
}
boost::filesystem::path path = GetBackupDirFromInput(userFilename);
if (boost::filesystem::exists(path))
throw JSONRPCError(RPC_INVALID_PARAMETER, "Wallet dump file already exists; not overwriting");