From: CryptoManiac Date: Tue, 29 Mar 2016 01:23:11 +0000 (+0300) Subject: Merge branch 'master' of github.com:novacoin-project/novacoin X-Git-Tag: nvc-v0.5.8~25 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=34694c603fa90378d59d70804a5862df3845b2b8;hp=-c Merge branch 'master' of github.com:novacoin-project/novacoin --- 34694c603fa90378d59d70804a5862df3845b2b8 diff --combined src/bitcoinrpc.cpp index bd1c1f4,0ac7652..56ac4ef --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@@ -173,7 -173,7 +173,7 @@@ string CRPCTable::help(string strComman // We already filter duplicates, but these deprecated screw up the sort order if (strMethod.find("label") != string::npos) continue; - if (strCommand != "" && strMethod != strCommand) + if (!strCommand.empty() && strMethod != strCommand) continue; try { @@@ -186,13 -186,13 +186,13 @@@ { // Help text is returned in an exception string strHelp = string(e.what()); - if (strCommand == "") + if (strCommand.empty()) if (strHelp.find('\n') != string::npos) strHelp = strHelp.substr(0, strHelp.find('\n')); strRet += strHelp + "\n"; } } - if (strRet == "") + if (strRet.empty()) strRet = strprintf("help: unknown command: %s\n", strCommand.c_str()); strRet = strRet.substr(0,strRet.size()-1); return strRet; @@@ -297,7 -297,6 +297,7 @@@ static const CRPCCommand vRPCCommands[ { "submitblock", &submitblock, false, false }, { "listsinceblock", &listsinceblock, false, false }, { "dumpprivkey", &dumpprivkey, false, false }, + { "dumppem", &dumppem, true, false }, { "dumpwallet", &dumpwallet, true, false }, { "importwallet", &importwallet, false, false }, { "importprivkey", &importprivkey, false, false }, @@@ -467,7 -466,7 +467,7 @@@ int ReadHTTPHeader(std::basic_istream& stream, map& mapHeadersRet, string& strMessageRet) { mapHeadersRet.clear(); - strMessageRet = ""; + strMessageRet.clear(); // Read status int nProto = 0; @@@ -783,7 -782,7 +783,7 @@@ void ThreadRPCServer2(void* parg printf("ThreadRPCServer started\n"); strRPCUserColonPass = mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"]; - if (mapArgs["-rpcpassword"] == "") + if (mapArgs["-rpcpassword"].empty()) { unsigned char rand_pwd[32]; RAND_bytes(rand_pwd, 32); @@@ -1086,7 -1085,7 +1086,7 @@@ json_spirit::Value CRPCTable::execute(c // Observe safe mode string strWarning = GetWarnings("rpc"); - if (strWarning != "" && !GetBoolArg("-disablesafemode") && + if (!strWarning.empty() && !GetBoolArg("-disablesafemode") && !pcmd->okSafeMode) throw JSONRPCError(RPC_FORBIDDEN_BY_SAFE_MODE, string("Safe mode: ") + strWarning); @@@ -1113,7 -1112,7 +1113,7 @@@ Object CallRPC(const string& strMethod, const Array& params) { - if (mapArgs["-rpcuser"] == "" && mapArgs["-rpcpassword"] == "") + if (mapArgs["-rpcuser"].empty() && mapArgs["-rpcpassword"].empty()) throw runtime_error(strprintf( _("You must set rpcpassword= in the configuration file:\n%s\n" "If the file does not exist, create it with owner-readable-only file permissions."), @@@ -1300,7 -1299,7 +1300,7 @@@ int CommandLineRPC(int argc, char *argv { // Result if (result.type() == null_type) - strPrint = ""; + strPrint.clear(); else if (result.type() == str_type) strPrint = result.get_str(); else @@@ -1317,7 -1316,7 +1317,7 @@@ PrintException(NULL, "CommandLineRPC()"); } - if (strPrint != "") + if (!strPrint.empty()) { fprintf((nRet == 0 ? stdout : stderr), "%s\n", strPrint.c_str()); } diff --combined src/main.cpp index 65001a3,64c988a..660bb41 --- a/src/main.cpp +++ b/src/main.cpp @@@ -2508,7 -2508,7 +2508,7 @@@ bool static ReserealizeBlockSignature(C return true; } - return CKey::ReserealizeSignature(pblock->vchBlockSig); + return CPubKey::ReserealizeSignature(pblock->vchBlockSig); } bool static IsCanonicalBlockSignature(CBlock* pblock) @@@ -2667,8 -2667,8 +2667,8 @@@ bool CBlock::CheckBlockSignature() cons if (whichType == TX_PUBKEY) { valtype& vchPubKey = vSolutions[0]; - CKey key; - if (!key.SetPubKey(vchPubKey)) + CPubKey key(vchPubKey); + if (!key.IsValid()) return false; return key.Verify(GetHash(), vchBlockSig); } @@@ -3037,7 -3037,7 +3037,7 @@@ string GetWarnings(string strFor strRPC = "test"; // Misc warnings like out of disk space and clock is wrong - if (strMiscWarning != "") + if (!strMiscWarning.empty()) { nPriority = 1000; strStatusBar = strMiscWarning; diff --combined src/rpcwallet.cpp index 09bacfc,371fb34..aa91f7f --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@@ -350,7 -350,7 +350,7 @@@ Value sendtoaddress(const Array& params throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx); - if (strError != "") + if (!strError.empty()) throw JSONRPCError(RPC_WALLET_ERROR, strError); return wtx.GetHash().GetHex(); @@@ -451,11 -451,11 +451,11 @@@ Value verifymessage(const Array& params ss << strMessageMagic; ss << strMessage; - CKey key; + CPubKey key; if (!key.SetCompactSignature(Hash(ss.begin(), ss.end()), vchSig)) return false; - return (key.GetPubKey().GetID() == keyID); + return (key.GetID() == keyID); } @@@ -738,7 -738,7 +738,7 @@@ Value sendfrom(const Array& params, boo // Send string strError = pwalletMain->SendMoney(scriptPubKey, nAmount, wtx); - if (strError != "") + if (!strError.empty()) throw JSONRPCError(RPC_WALLET_ERROR, strError); return wtx.GetHash().GetHex(); @@@ -843,7 -843,7 +843,7 @@@ Value addmultisigaddress(const Array& p "(got %" PRIszu " keys, but need at least %d to redeem)", keys.size(), nRequired)); if (keys.size() > 16) throw runtime_error("Number of addresses involved in the multisignature address creation > 16\nReduce the number"); - std::vector pubkeys; + std::vector pubkeys; pubkeys.resize(keys.size()); for (unsigned int i = 0; i < keys.size(); i++) { @@@ -861,18 -861,16 +861,18 @@@ if (!pwalletMain->GetPubKey(keyID, vchPubKey)) throw runtime_error( strprintf("no full public key for address %s",ks.c_str())); - if (!vchPubKey.IsValid() || !pubkeys[i].SetPubKey(vchPubKey)) + if (!vchPubKey.IsValid()) throw runtime_error(" Invalid public key: "+ks); + pubkeys[i] = vchPubKey; } // Case 2: hex public key else if (IsHex(ks)) { CPubKey vchPubKey(ParseHex(ks)); - if (!vchPubKey.IsValid() || !pubkeys[i].SetPubKey(vchPubKey)) + if (!vchPubKey.IsValid()) throw runtime_error(" Invalid public key: "+ks); + pubkeys[i] = vchPubKey; } else { @@@ -1069,7 -1067,7 +1069,7 @@@ void ListTransactions(const CWalletTx& bool involvesWatchonly = wtx.IsFromMe(MINE_WATCH_ONLY); // Generated blocks assigned to account "" - if ((nGeneratedMature+nGeneratedImmature) != 0 && (fAllAccounts || strAccount == "")) + if ((nGeneratedMature+nGeneratedImmature) != 0 && (fAllAccounts || strAccount.empty())) { Object entry; entry.push_back(Pair("account", string(""))); @@@ -1692,7 -1690,7 +1692,7 @@@ public obj.push_back(Pair("isscript", false)); if (mine == MINE_SPENDABLE) { pwalletMain->GetPubKey(keyID, vchPubKey); - obj.push_back(Pair("pubkey", HexStr(vchPubKey.Raw()))); + obj.push_back(Pair("pubkey", HexStr(vchPubKey.begin(), vchPubKey.end()))); obj.push_back(Pair("iscompressed", vchPubKey.IsCompressed())); } return obj; @@@ -1888,9 -1886,8 +1888,9 @@@ Value makekeypair(const Array& params, bool fCompressed; CSecret vchSecret = key.GetSecret(fCompressed); + CPubKey vchPubKey = key.GetPubKey(); result.push_back(Pair("Secret", HexStr(vchSecret.begin(), vchSecret.end()))); - result.push_back(Pair("PublicKey", HexStr(key.GetPubKey().Raw()))); + result.push_back(Pair("PublicKey", HexStr(vchPubKey.begin(), vchPubKey.end()))); return result; } @@@ -1973,8 -1970,8 +1973,8 @@@ Value adjustmalleablepubkey(const Array malleablePubKey.GetVariant(R, vchPubKeyVariant); Object result; - result.push_back(Pair("R", HexStr(R.Raw()))); - result.push_back(Pair("PubkeyVariant", HexStr(vchPubKeyVariant.Raw()))); + result.push_back(Pair("R", HexStr(R.begin(), R.end()))); + result.push_back(Pair("PubkeyVariant", HexStr(vchPubKeyVariant.begin(), vchPubKeyVariant.end()))); result.push_back(Pair("KeyVariantID", CBitcoinAddress(vchPubKeyVariant.GetID()).ToString())); return result; diff --combined src/wallet.cpp index a1fe81d,c9db321..2f4803f --- a/src/wallet.cpp +++ b/src/wallet.cpp @@@ -12,7 -12,6 +12,7 @@@ #include "kernel.h" #include "coincontrol.h" #include +#include #include "main.h" @@@ -517,19 -516,6 +517,19 @@@ bool CWallet::DecryptWallet(const Secur return true; } +bool CWallet::GetPEM(const CKeyID &keyID, const std::string &fileName, const SecureString &strPassKey) const +{ + BIO *pemOut = BIO_new_file(fileName.c_str(), "w"); + if (pemOut == NULL) + return error("GetPEM() : failed to create file %s\n", fileName.c_str()); + CKey key; + if (!GetKey(keyID, key)) + return error("GetPEM() : failed to get key for address=%s\n", CBitcoinAddress(keyID).ToString().c_str()); + bool result = key.WritePEM(pemOut, strPassKey); + BIO_free(pemOut); + return result; +} + int64_t CWallet::IncOrderPosNext(CWalletDB *pwalletdb) { int64_t nRet = nOrderPosNext++; @@@ -956,7 -942,7 +956,7 @@@ void CWalletTx::GetAccountAmounts(cons list > listSent; GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount, filter); - if (strAccount == "") + if (strAccount.empty()) nGenerated = allGeneratedMature; if (strAccount == strSentAccount) {