New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamically Loadable Multiple Wallet Support Complete!!! #2124
Changes from 16 commits
71c63e3
4a6b0e2
158ce39
1b640c1
1cdf18b
27fa196
93e6b80
0f815bf
924f088
fa1c808
b0cae87
2b31fdf
1b51a7f
3fd110a
9d201cf
2256d1d
3f5d692
629ca2f
55d301c
ebf85b1
74228a2
ec0cc4b
7348f78
d21a960
f409a6d
6215e53
d8b0cf1
3d15116
aa93b31
e0f3cbe
eba5579
6f3e40b
3944f1d
64a9b45
a240960
41f561c
5bb560f
6c7f86a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,7 +141,7 @@ string CRPCTable::help(string strCommand) const | |
Array params; | ||
rpcfn_type pfn = pcmd->actor; | ||
if (setDone.insert(pfn).second) | ||
(*pfn)(params, true); | ||
(*pfn)(NULL, params, true); | ||
} | ||
catch (std::exception& e) | ||
{ | ||
|
@@ -159,7 +159,7 @@ string CRPCTable::help(string strCommand) const | |
return strRet; | ||
} | ||
|
||
Value help(const Array& params, bool fHelp) | ||
Value help(CWallet* pWallet, const Array& params, bool fHelp) | ||
{ | ||
if (fHelp || params.size() > 1) | ||
throw runtime_error( | ||
|
@@ -174,7 +174,7 @@ Value help(const Array& params, bool fHelp) | |
} | ||
|
||
|
||
Value stop(const Array& params, bool fHelp) | ||
Value stop(CWallet* pWallet, const Array& params, bool fHelp) | ||
{ | ||
// Accept the deprecated and ignored 'detach´ boolean argument | ||
if (fHelp || params.size() > 1) | ||
|
@@ -194,68 +194,72 @@ Value stop(const Array& params, bool fHelp) | |
|
||
|
||
static const CRPCCommand vRPCCommands[] = | ||
{ // name function safemd unlocked | ||
// ------------------------ ----------------------- ------ -------- | ||
{ "help", &help, true, true }, | ||
{ "stop", &stop, true, true }, | ||
{ "getblockcount", &getblockcount, true, false }, | ||
{ "getconnectioncount", &getconnectioncount, true, false }, | ||
{ "getpeerinfo", &getpeerinfo, true, false }, | ||
{ "getdifficulty", &getdifficulty, true, false }, | ||
{ "getgenerate", &getgenerate, true, false }, | ||
{ "setgenerate", &setgenerate, true, false }, | ||
{ "gethashespersec", &gethashespersec, true, false }, | ||
{ "getinfo", &getinfo, true, false }, | ||
{ "getmininginfo", &getmininginfo, true, false }, | ||
{ "getnewaddress", &getnewaddress, true, false }, | ||
{ "getaccountaddress", &getaccountaddress, true, false }, | ||
{ "setaccount", &setaccount, true, false }, | ||
{ "getaccount", &getaccount, false, false }, | ||
{ "getaddressesbyaccount", &getaddressesbyaccount, true, false }, | ||
{ "sendtoaddress", &sendtoaddress, false, false }, | ||
{ "getreceivedbyaddress", &getreceivedbyaddress, false, false }, | ||
{ "getreceivedbyaccount", &getreceivedbyaccount, false, false }, | ||
{ "listreceivedbyaddress", &listreceivedbyaddress, false, false }, | ||
{ "listreceivedbyaccount", &listreceivedbyaccount, false, false }, | ||
{ "backupwallet", &backupwallet, true, false }, | ||
{ "keypoolrefill", &keypoolrefill, true, false }, | ||
{ "walletpassphrase", &walletpassphrase, true, false }, | ||
{ "walletpassphrasechange", &walletpassphrasechange, false, false }, | ||
{ "walletlock", &walletlock, true, false }, | ||
{ "encryptwallet", &encryptwallet, false, false }, | ||
{ "validateaddress", &validateaddress, true, false }, | ||
{ "getbalance", &getbalance, false, false }, | ||
{ "move", &movecmd, false, false }, | ||
{ "sendfrom", &sendfrom, false, false }, | ||
{ "sendmany", &sendmany, false, false }, | ||
{ "addmultisigaddress", &addmultisigaddress, false, false }, | ||
{ "createmultisig", &createmultisig, true, true }, | ||
{ "getrawmempool", &getrawmempool, true, false }, | ||
{ "getblock", &getblock, false, false }, | ||
{ "getblockhash", &getblockhash, false, false }, | ||
{ "gettransaction", &gettransaction, false, false }, | ||
{ "listtransactions", &listtransactions, false, false }, | ||
{ "listaddressgroupings", &listaddressgroupings, false, false }, | ||
{ "signmessage", &signmessage, false, false }, | ||
{ "verifymessage", &verifymessage, false, false }, | ||
{ "getwork", &getwork, true, false }, | ||
{ "listaccounts", &listaccounts, false, false }, | ||
{ "settxfee", &settxfee, false, false }, | ||
{ "getblocktemplate", &getblocktemplate, true, false }, | ||
{ "submitblock", &submitblock, false, false }, | ||
{ "listsinceblock", &listsinceblock, false, false }, | ||
{ "dumpprivkey", &dumpprivkey, false, false }, | ||
{ "importprivkey", &importprivkey, false, false }, | ||
{ "listunspent", &listunspent, false, false }, | ||
{ "getrawtransaction", &getrawtransaction, false, false }, | ||
{ "createrawtransaction", &createrawtransaction, false, false }, | ||
{ "decoderawtransaction", &decoderawtransaction, false, false }, | ||
{ "signrawtransaction", &signrawtransaction, false, false }, | ||
{ "sendrawtransaction", &sendrawtransaction, false, false }, | ||
{ "gettxoutsetinfo", &gettxoutsetinfo, true, false }, | ||
{ "gettxout", &gettxout, true, false }, | ||
{ "lockunspent", &lockunspent, false, false }, | ||
{ "listlockunspent", &listlockunspent, false, false }, | ||
{ // name function safemd unlocked isWalletFn | ||
// ------------------------ ----------------------- ------ -------- ---------- | ||
{ "help", &help, true, true, false }, | ||
{ "stop", &stop, true, true, false }, | ||
{ "getblockcount", &getblockcount, true, false, false }, | ||
{ "getconnectioncount", &getconnectioncount, true, false, false }, | ||
{ "getpeerinfo", &getpeerinfo, true, false, false }, | ||
{ "getdifficulty", &getdifficulty, true, false, false }, | ||
{ "getgenerate", &getgenerate, true, false, false }, | ||
{ "setgenerate", &setgenerate, true, false, false }, | ||
{ "gethashespersec", &gethashespersec, true, false, false }, | ||
{ "getinfo", &getinfo, true, false, false }, | ||
{ "getmininginfo", &getmininginfo, true, false, false }, | ||
{ "getnewaddress", &getnewaddress, true, false, true }, | ||
{ "getaccountaddress", &getaccountaddress, true, false, true }, | ||
{ "setaccount", &setaccount, true, false, true }, | ||
{ "getaccount", &getaccount, false, false, true }, | ||
{ "getaddressesbyaccount", &getaddressesbyaccount, true, false, true }, | ||
{ "sendtoaddress", &sendtoaddress, false, false, true }, | ||
{ "getreceivedbyaddress", &getreceivedbyaddress, false, false, true }, | ||
{ "getreceivedbyaccount", &getreceivedbyaccount, false, false, true }, | ||
{ "listreceivedbyaddress", &listreceivedbyaddress, false, false, true }, | ||
{ "listreceivedbyaccount", &listreceivedbyaccount, false, false, true }, | ||
{ "backupwallet", &backupwallet, true, false, true }, | ||
{ "keypoolrefill", &keypoolrefill, true, false, true }, | ||
{ "walletpassphrase", &walletpassphrase, true, false, true }, | ||
{ "walletpassphrasechange", &walletpassphrasechange, false, false, true }, | ||
{ "walletlock", &walletlock, true, false, true }, | ||
{ "encryptwallet", &encryptwallet, false, false, true }, | ||
{ "validateaddress", &validateaddress, true, false, true }, | ||
{ "getbalance", &getbalance, false, false, true }, | ||
{ "move", &movecmd, false, false, true }, | ||
{ "sendfrom", &sendfrom, false, false, true }, | ||
{ "sendmany", &sendmany, false, false, true }, | ||
{ "addmultisigaddress", &addmultisigaddress, false, false, true }, | ||
{ "createmultisig", &createmultisig, true, true, true }, | ||
{ "getrawmempool", &getrawmempool, true, false, false }, | ||
{ "getblock", &getblock, false, false, false }, | ||
{ "getblockhash", &getblockhash, false, false, false }, | ||
{ "gettransaction", &gettransaction, false, false, true }, | ||
{ "listtransactions", &listtransactions, false, false, true }, | ||
{ "listaddressgroupings", &listaddressgroupings, false, false, true }, | ||
{ "signmessage", &signmessage, false, false, true }, | ||
{ "verifymessage", &verifymessage, false, false, false }, | ||
{ "getwork", &getwork, true, false, false }, | ||
{ "listaccounts", &listaccounts, false, false, true }, | ||
{ "settxfee", &settxfee, false, false, false }, | ||
{ "getblocktemplate", &getblocktemplate, true, false, false }, | ||
{ "submitblock", &submitblock, false, false, false }, | ||
{ "listsinceblock", &listsinceblock, false, false, true }, | ||
{ "dumpprivkey", &dumpprivkey, false, false, true }, | ||
{ "importprivkey", &importprivkey, false, false, true }, | ||
{ "listunspent", &listunspent, false, false, true }, | ||
{ "getrawtransaction", &getrawtransaction, false, false, false }, | ||
{ "createrawtransaction", &createrawtransaction, false, false, false }, | ||
{ "decoderawtransaction", &decoderawtransaction, false, false, false }, | ||
{ "signrawtransaction", &signrawtransaction, false, false, true }, | ||
{ "sendrawtransaction", &sendrawtransaction, false, false, false }, | ||
{ "gettxoutsetinfo", &gettxoutsetinfo, true, false, false }, | ||
{ "gettxout", &gettxout, true, false, true }, | ||
{ "lockunspent", &lockunspent, false, false, true }, | ||
{ "listlockunspent", &listlockunspent, false, false, true }, | ||
{ "listwallets", &listwallets, true, true, false }, | ||
{ "usewallet", &usewallet, false, true, false }, | ||
{ "loadwallet", &loadwallet, false, true, false }, | ||
{ "unloadwallet", &unloadwallet, false, true, false } | ||
}; | ||
|
||
CRPCTable::CRPCTable() | ||
|
@@ -1052,7 +1056,7 @@ void ThreadRPCServer3(void* parg) | |
} | ||
} | ||
|
||
json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_spirit::Array ¶ms) const | ||
json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_spirit::Array ¶ms, CWallet* pWallet) const | ||
{ | ||
// Find method | ||
const CRPCCommand *pcmd = tableRPC[strMethod]; | ||
|
@@ -1065,16 +1069,20 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s | |
!pcmd->okSafeMode) | ||
throw JSONRPCError(RPC_FORBIDDEN_BY_SAFE_MODE, string("Safe mode: ") + strWarning); | ||
|
||
if (!pWallet) pWallet = pwalletMain; | ||
|
||
try | ||
{ | ||
// Execute | ||
Value result; | ||
{ | ||
if (pcmd->unlocked) | ||
result = pcmd->actor(params, false); | ||
LOCK(pWalletMap->cs_WalletMap); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you want to keep the walletmap locked during the actual RPC execution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Totally agreed - this was just me being extra cautious until the locking issues can be further looked into. |
||
if (pcmd->unlocked) { | ||
result = pcmd->actor(pWallet, params, false); | ||
} | ||
else { | ||
LOCK2(cs_main, pwalletMain->cs_wallet); | ||
result = pcmd->actor(params, false); | ||
LOCK2(cs_main, pWallet->cs_wallet); | ||
result = pcmd->actor(pWallet, params, false); | ||
} | ||
} | ||
return result; | ||
|
@@ -1220,6 +1228,9 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri | |
if (strMethod == "lockunspent" && n > 0) ConvertTo<bool>(params[0]); | ||
if (strMethod == "lockunspent" && n > 1) ConvertTo<Array>(params[1]); | ||
if (strMethod == "importprivkey" && n > 2) ConvertTo<bool>(params[2]); | ||
if (strMethod == "loadwallet" && n > 1) ConvertTo<bool>(params[1]); | ||
if (strMethod == "loadwallet" && n > 2) ConvertTo<bool>(params[2]); | ||
if (strMethod == "loadwallet" && n > 3) ConvertTo<boost::int64_t>(params[3]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't RPCConvertValues need some magic to deal with usewallet? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. usewallet used to call RPCConvertValues on the parameters and pass it to CRPCTable::execute. Now RPCConvertValues does the magic. |
||
|
||
return params; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should use pWalletMap->GetDefaultWallet() wherever pwalletMain appears anywhere in the application.