added functions to rpc logging

This commit is contained in:
instagibbs 2016-06-06 11:04:53 -04:00 committed by Gregory Sanders
parent a358337b92
commit ea90488a5e
5 changed files with 68 additions and 15 deletions

View file

@ -24,6 +24,7 @@
#include "txmempool.h"
#include "uint256.h"
#include "utilstrencodings.h"
#include "util.h"
#ifdef ENABLE_WALLET
#include "wallet/wallet.h"
#endif
@ -1076,6 +1077,8 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
result.push_back(Pair("errors", vErrors));
}
AuditLogPrintf("%s : signrawtransaction %s\n", getUser(), EncodeHexTx(mergedTx));
return result;
}
@ -1153,6 +1156,7 @@ UniValue sendrawtransaction(const JSONRPCRequest& request)
}
if(!g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
AuditLogPrintf("%s : sendrawtransaction %s\n", getUser(), hashTx.GetHex());
CInv inv(MSG_TX, hashTx);
g_connman->ForEachNode([&inv](CNode* pnode)

View file

@ -119,7 +119,7 @@ bool fLogTimestamps = DEFAULT_LOGTIMESTAMPS;
bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS;
bool fLogIPs = DEFAULT_LOGIPS;
std::atomic<bool> fReopenDebugLog(false);
volatile bool fReopenAuditLog = false;
std::atomic<bool> fReopenAuditLog(false);
CTranslationInterface translationInterface;
/** Init OpenSSL library multithreading support */
@ -232,12 +232,11 @@ void OpenDebugLog()
boost::filesystem::path pathDebug = GetDataDir() / "debug.log";
fileout_debug = fopen(pathDebug.string().c_str(), "a");
if (fileout_debug) setbuf(fileout_debug, NULL); // unbuffered
setbuf(fileout, NULL); // unbuffered
setbuf(fileout_debug, NULL); // unbuffered
// dump buffered messages from before we opened the log
while (!vMsgsBeforeOpenDebugLog->empty()) {
FileWriteStr(vMsgsBeforeOpenDebugLog->front(), fileout_debug);
vMsgsBeforeOpenDebugLog->pop_front();
}
}
delete vMsgsBeforeOpenDebugLog;
@ -370,7 +369,7 @@ int DebugLogPrintStr(const std::string &str)
int AuditLogPrintStr(const std::string &str)
{
int ret = 0; // Returns total number of characters written
static bool fStartedNewLine = true;
static std::atomic_bool fStartedNewLine(true);
string strTimestamped = LogTimestampStr(str, &fStartedNewLine);
@ -929,4 +928,4 @@ std::string CopyrightHolders(const std::string& strPrefix)
strCopyrightHolders += "\n" + strPrefix + "The Bitcoin Core developers";
}
return strCopyrightHolders;
}
}

View file

@ -77,25 +77,28 @@ int AuditLogPrintStr(const std::string &str);
#define LogPrint(category, ...) do { \
if (LogAcceptCategory((category))) { \
LogPrintStr(tfm::format(__VA_ARGS__)); \
DebugLogPrintStr(tfm::format(__VA_ARGS__)); \
} \
} while(0)
#define LogPrintf(...) do { \
LogPrintStr(tfm::format(__VA_ARGS__)); \
DebugLogPrintStr(tfm::format(__VA_ARGS__)); \
} while(0)
template<typename T1, typename... Args>
static inline int AuditLogPrint(const char* category, const char* fmt, const T1& v1, const Args&... args)
{
if(!LogAcceptCategory(category)) return 0; \
return AuditLogPrintStr(tfm::format(fmt, v1, args...));
}
#define AuditLogPrint(category, ...) do { \
if (LogAcceptCategory((category))) { \
AuditLogPrintStr(tfm::format(__VA_ARGS__)); \
} \
} while(0)
#define AuditLogPrintf(...) do { \
AuditLogPrintStr(tfm::format(__VA_ARGS__)); \
} while(0)
template<typename... Args>
bool error(const char* fmt, const Args&... args)
{
LogPrintStr("ERROR: " + tfm::format(fmt, args...) + "\n");
DebugLogPrintStr("ERROR: " + tfm::format(fmt, args...) + "\n");
return false;
}

View file

@ -152,6 +152,8 @@ UniValue importprivkey(const JSONRPCRequest& request)
}
}
AuditLogPrintf("%s : importprivkey %s\n", getUser(), pubkey.GetHash().GetHex());
return NullUniValue;
}
@ -252,6 +254,8 @@ UniValue importaddress(const JSONRPCRequest& request)
pwalletMain->ReacceptWalletTransactions();
}
AuditLogPrintf("%s : importaddress %s\n", getUser(), request.params[0].get_str());
return NullUniValue;
}
@ -404,6 +408,8 @@ UniValue importpubkey(const JSONRPCRequest& request)
pwalletMain->ReacceptWalletTransactions();
}
AuditLogPrintf("%s : importpubkey %s\n", getUser(), request.params[0].get_str());
return NullUniValue;
}
@ -511,6 +517,8 @@ UniValue importwallet(const JSONRPCRequest& request)
if (!fGood)
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding some keys to wallet");
AuditLogPrintf("%s : importwallet %s\n", getUser(), request.params[0].get_str());
return NullUniValue;
}
@ -548,6 +556,9 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
CKey vchSecret;
if (!pwalletMain->GetKey(keyID, vchSecret))
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");
AuditLogPrintf("%s : dumpprivkey %s\n", getUser(), strAddress);
return CBitcoinSecret(vchSecret).ToString();
}
@ -639,6 +650,9 @@ UniValue dumpwallet(const JSONRPCRequest& request)
file << "\n";
file << "# End of dump\n";
file.close();
AuditLogPrintf("%s : dumpwallet %s\n", getUser(), request.params[0].get_str());
return NullUniValue;
}
@ -1138,6 +1152,7 @@ UniValue dumpblindingkey(const JSONRPCRequest& request)
if (key.IsValid()) {
CPubKey pubkey = key.GetPubKey();
if (pubkey == address.GetBlindingKey()) {
AuditLogPrintf("%s : dumpblindingkey %s\n", getUser(), address.ToString());
return HexStr(key.begin(), key.end());
}
}
@ -1146,6 +1161,7 @@ UniValue dumpblindingkey(const JSONRPCRequest& request)
if (key.IsValid()) {
CPubKey pubkey = key.GetPubKey();
if (pubkey == address.GetBlindingKey()) {
AuditLogPrintf("%s : dumpblindingkey %s\n", getUser(), address.ToString());
return HexStr(key.begin(), key.end());
}
}

View file

@ -449,7 +449,7 @@ UniValue sendtoaddress(const JSONRPCRequest& request)
SendMoney(address.Get(), nAmount, fSubtractFeeFromAmount, confidentiality_pubkey, wtx);
AuditLogPrintf("%s : sendtoaddress %s %d", getUser(), wtx.GetHash().GetHex(), nAmount);
AuditLogPrintf("%s : sendtoaddress %s %s txid:%s\n", getUser(), request.params[0].get_str(), request.params[1].getValStr(), wtx.GetHash().GetHex());
return wtx.GetHash().GetHex();
}
@ -898,6 +898,8 @@ UniValue sendfrom(const JSONRPCRequest& request)
SendMoney(address.Get(), nAmount, false, confidentiality_pubkey, wtx);
AuditLogPrintf("%s : sendfrom %s %s %s txid:%s\n", getUser(), request.params[0].get_str(), request.params[1].get_str(), request.params[2].getValStr(), wtx.GetHash().GetHex());
return wtx.GetHash().GetHex();
}
@ -966,6 +968,9 @@ UniValue sendmany(const JSONRPCRequest& request)
set<CBitcoinAddress> setAddress;
vector<CRecipient> vecSend;
std::string strAudit(getUser());
strAudit += " : sendmany \n";
CAmount totalAmount = 0;
vector<string> keys = sendTo.getKeys();
BOOST_FOREACH(const string& name_, keys)
@ -984,6 +989,7 @@ UniValue sendmany(const JSONRPCRequest& request)
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send");
totalAmount += nAmount;
strAudit += name_ + " " + sendTo[name_].getValStr() + "\n";
CPubKey confidentiality_pubkey;
if (address.IsBlinded())
@ -998,6 +1004,7 @@ UniValue sendmany(const JSONRPCRequest& request)
CRecipient recipient = {scriptPubKey, nAmount, confidentiality_pubkey, fSubtractFeeFromAmount};
vecSend.push_back(recipient);
}
EnsureWalletIsUnlocked();
@ -1021,6 +1028,8 @@ UniValue sendmany(const JSONRPCRequest& request)
throw JSONRPCError(RPC_WALLET_ERROR, strFailReason);
}
AuditLogPrintf("%s", strAudit);
return wtx.GetHash().GetHex();
}
@ -1072,6 +1081,9 @@ UniValue addmultisigaddress(const JSONRPCRequest& request)
pwalletMain->AddCScript(inner);
pwalletMain->SetAddressBook(innerID, strAccount, "send");
AuditLogPrintf("%s : addmultisigaddress %s\n", getUser(), CBitcoinAddress(innerID).ToString());
return CBitcoinAddress(innerID).ToString();
}
@ -1161,6 +1173,8 @@ UniValue addwitnessaddress(const JSONRPCRequest& request)
pwalletMain->SetAddressBook(w.result, "", "receive");
AuditLogPrintf("%s : addwitnessaddress %s\n", getUser(), CBitcoinAddress(w.result).ToString());
return CBitcoinAddress(w.result).ToString();
}
@ -1944,6 +1958,8 @@ UniValue backupwallet(const JSONRPCRequest& request)
if (!pwalletMain->BackupWallet(strDest))
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!");
AuditLogPrintf("%s : backupwallet %s\n", getUser(), strDest);
return NullUniValue;
}
@ -2048,6 +2064,8 @@ UniValue walletpassphrase(const JSONRPCRequest& request)
nWalletUnlockTime = GetTime() + nSleepTime;
RPCRunLater("lockwallet", boost::bind(LockWallet, pwalletMain), nSleepTime);
AuditLogPrintf("%s : walletpassphrase\n", getUser());
return NullUniValue;
}
@ -2094,6 +2112,8 @@ UniValue walletpassphrasechange(const JSONRPCRequest& request)
if (!pwalletMain->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass))
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
AuditLogPrintf("%s : walletpassphrasechange\n", getUser());
return NullUniValue;
}
@ -2187,6 +2207,8 @@ UniValue encryptwallet(const JSONRPCRequest& request)
if (!pwalletMain->EncryptWallet(strWalletPass))
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Failed to encrypt the wallet.");
AuditLogPrintf("%s : encryptwallet\n", getUser());
// BDB seems to have a bad habit of writing old data into
// slack space in .dat files; that is bad if the old data is
// unencrypted private keys. So:
@ -2356,6 +2378,9 @@ UniValue settxfee(const JSONRPCRequest& request)
CAmount nAmount = AmountFromValue(request.params[0]);
payTxFee = CFeeRate(nAmount, 1000);
AuditLogPrintf("%s : settxfee %s\n", getUser(), request.params[0].getValStr());
return true;
}
@ -3183,6 +3208,8 @@ UniValue getpeginaddress(const JSONRPCRequest& request)
UniValue fundinginfo(UniValue::VOBJ);
AuditLogPrintf("%s : getpeginaddress mainaddress: %s address: %s\n", getUser(), destAddr.ToString(), address.ToString());
fundinginfo.pushKV("mainaddress", destAddr.ToString());
fundinginfo.pushKV("address", address.ToString());
return fundinginfo;
@ -3256,6 +3283,8 @@ UniValue sendtomainchain(const JSONRPCRequest& request)
CWalletTx wtxNew;
SendMoney(scriptPubKey, nAmount, false, CPubKey(), wtxNew);
AuditLogPrintf("%s : sendtomainchain %s\n", getUser(), wtxNew.tx->GetHash().GetHex());
return wtxNew.GetHash().GetHex();
}
@ -3400,6 +3429,8 @@ UniValue claimpegin(const JSONRPCRequest& request)
{
pnode->PushInventory(inv);
});
AuditLogPrintf("%s : claimpegin %s\n", getUser(), finalTxn.ToString());
return finalTxn.GetHash().GetHex();
}