Skip to content

Commit 2f15c2b

Browse files
committed
Add disable privatekeys option to createwallet
1 parent cebefba commit 2f15c2b

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/rpc/client.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
155155
{ "echojson", 9, "arg9" },
156156
{ "rescanblockchain", 0, "start_height"},
157157
{ "rescanblockchain", 1, "stop_height"},
158+
{ "createwallet", 1, "disable_private_keys"},
158159
};
159160

160161
class CRPCConvertTable

src/wallet/rpcwallet.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3135,12 +3135,13 @@ static UniValue loadwallet(const JSONRPCRequest& request)
31353135

31363136
static UniValue createwallet(const JSONRPCRequest& request)
31373137
{
3138-
if (request.fHelp || request.params.size() != 1) {
3138+
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) {
31393139
throw std::runtime_error(
3140-
"createwallet \"wallet_name\"\n"
3140+
"createwallet \"wallet_name\" ( disable_private_keys )\n"
31413141
"\nCreates and loads a new wallet.\n"
31423142
"\nArguments:\n"
3143-
"1. \"wallet_name\" (string, required) The name for the new wallet. If this is a path, the wallet will be created at the path location.\n"
3143+
"1. \"wallet_name\" (string, required) The name for the new wallet. If this is a path, the wallet will be created at the path location.\n"
3144+
"2. disable_private_keys (boolean, optional, default: false) Disable the possibility of private keys (only watchonlys are possible in this mode).\n"
31443145
"\nResult:\n"
31453146
"{\n"
31463147
" \"name\" : <wallet_name>, (string) The wallet name if created successfully. If the wallet was created using a full path, the wallet_name will be the full path.\n"
@@ -3155,6 +3156,11 @@ static UniValue createwallet(const JSONRPCRequest& request)
31553156
std::string error;
31563157
std::string warning;
31573158

3159+
bool disable_privatekeys = false;
3160+
if (!request.params[1].isNull()) {
3161+
disable_privatekeys = request.params[1].get_bool();
3162+
}
3163+
31583164
fs::path wallet_path = fs::absolute(wallet_name, GetWalletDir());
31593165
if (fs::symlink_status(wallet_path).type() != fs::file_not_found) {
31603166
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet " + wallet_name + " already exists.");
@@ -3165,7 +3171,7 @@ static UniValue createwallet(const JSONRPCRequest& request)
31653171
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet file verification failed: " + error);
31663172
}
31673173

3168-
std::shared_ptr<CWallet> const wallet = CWallet::CreateWalletFromFile(wallet_name, fs::absolute(wallet_name, GetWalletDir()));
3174+
std::shared_ptr<CWallet> const wallet = CWallet::CreateWalletFromFile(wallet_name, fs::absolute(wallet_name, GetWalletDir()), (disable_privatekeys ? (uint64_t)WALLET_FLAG_DISABLE_PRIVATE_KEYS : 0));
31693175
if (!wallet) {
31703176
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet creation failed.");
31713177
}
@@ -4430,7 +4436,7 @@ static const CRPCCommand commands[] =
44304436
{ "hidden", "addwitnessaddress", &addwitnessaddress, {"address","p2sh"} },
44314437
{ "wallet", "backupwallet", &backupwallet, {"destination"} },
44324438
{ "wallet", "bumpfee", &bumpfee, {"txid", "options"} },
4433-
{ "wallet", "createwallet", &createwallet, {"wallet_name"} },
4439+
{ "wallet", "createwallet", &createwallet, {"wallet_name", "disable_private_keys"} },
44344440
{ "wallet", "dumpprivkey", &dumpprivkey, {"address"} },
44354441
{ "wallet", "dumpwallet", &dumpwallet, {"filename"} },
44364442
{ "wallet", "encryptwallet", &encryptwallet, {"passphrase"} },

0 commit comments

Comments
 (0)