Introduce user getter to avoid null pointers

This commit is contained in:
instagibbs 2016-04-28 14:47:07 -04:00 committed by Gregory Sanders
parent b7ff69dfa8
commit a358337b92
3 changed files with 7 additions and 1 deletions

View file

@ -31,6 +31,10 @@
//Thread local rpc user name for logging purposes
boost::thread_specific_ptr<std::string> userInstance;
std::string getUser() {
return (userInstance.get() ? *userInstance.get() : "UNDEFINED_USER");
}
using namespace RPCServer;
using namespace std;

View file

@ -203,6 +203,8 @@ extern std::string HelpRequiringPassphrase();
extern std::string HelpExampleCli(const std::string& methodname, const std::string& args);
extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);
extern std::string getUser();
extern void EnsureWalletIsUnlocked();
bool StartRPC();

View file

@ -449,7 +449,7 @@ UniValue sendtoaddress(const JSONRPCRequest& request)
SendMoney(address.Get(), nAmount, fSubtractFeeFromAmount, confidentiality_pubkey, wtx);
AuditLogPrintf("%s : sendtoaddress %s %d", *userInstance.get(), wtx.GetHash().GetHex(), nAmount);
AuditLogPrintf("%s : sendtoaddress %s %d", getUser(), wtx.GetHash().GetHex(), nAmount);
return wtx.GetHash().GetHex();
}