From da46408ad1543826a6c671d8d68691c0619130aa Mon Sep 17 00:00:00 2001 From: Paul Jensen Date: Wed, 14 Feb 2018 14:37:41 -0800 Subject: [PATCH 01/28] remove extra space from error message --- src/backup.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backup.cpp b/src/backup.cpp index 3f7494dd50..ef2a2281bb 100644 --- a/src/backup.cpp +++ b/src/backup.cpp @@ -109,7 +109,7 @@ bool BackupPrivateKeys(const CWallet& wallet, std::string& sTarget, std::string& { if (wallet.IsLocked() || fWalletUnlockStakingOnly) { - sErrors = "Wallet needs to be fully unlocked to backup private keys. "; + sErrors = "Wallet needs to be fully unlocked to backup private keys."; return false; } filesystem::path PrivateKeysTarget = GetBackupFilename("keys.dat"); From bcdbd10614e717949727e0b585ef79f8b1919fc1 Mon Sep 17 00:00:00 2001 From: Paul Jensen Date: Wed, 14 Feb 2018 14:38:18 -0800 Subject: [PATCH 02/28] bitcoinrpc changes and testing complete --- src/bitcoinrpc.cpp | 271 ++++++++++++++------------------------------- src/bitcoinrpc.h | 24 +++- 2 files changed, 105 insertions(+), 190 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 7c4ef2ed2c..a3474a163a 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -150,7 +150,7 @@ vector ParseHexO(const Object& o, string strKey) /// Note: This interface may still be subject to change. /// -string CRPCTable::help(string strCommand) const +string CRPCTable::help(string strCommand, rpccategory category) const { string strRet; set setDone; @@ -167,7 +167,7 @@ string CRPCTable::help(string strCommand) const { Array params; rpcfn_type pfn = pcmd->actor; - if (setDone.insert(pfn).second) + if (setDone.insert(pfn).second && (pcmd->category == category || category == cat_null)) (*pfn)(params, true); } catch (std::exception& e) @@ -188,23 +188,52 @@ string CRPCTable::help(string strCommand) const Value help(const Array& params, bool fHelp) { - if (fHelp || params.size() > 1) + if (fHelp || params.size() == 0 || params.size() > 1) throw runtime_error( - "help [command]\n" - "List commands, or get help for a command."); - + "help\n" + "Returns list of subcategories for extended help\n" + "\n" + "help [command] Returns help for a specific requested command\n" + "\n" + "help wallet Returns help for blockchain related commands\n" + "help neuralnetwork Returns help for neural network/cpid/beacon related commands\n" + "help developer Returns help for developer commands\n" + "help network Returns help for network related commands\n"); + + // Allow to process through if params size is > 0 string strCommand; + if (params.size() > 0) strCommand = params[0].get_str(); - return tableRPC.help(strCommand); -} + // Subcategory help area + // Blockchain related commands + rpccategory category = cat_null; + + if (strCommand == "wallet") + category = cat_wallet; + + else if (strCommand == "neuralnetwork") + category = cat_neuralnetwork; + + else if (strCommand == "developer") + category = cat_neuralnetwork; + else if (strCommand == "network") + category = cat_network; + + else + category = cat_null; + + if (category != cat_null) + strCommand = ""; + + return tableRPC.help(strCommand, category); +} Value stop(const Array& params, bool fHelp) { - // Accept the deprecated and ignored 'detach´ boolean argument - if (fHelp || params.size() > 1) + if (fHelp || params.size() > 0) throw runtime_error( "stop\n" "Stop Gridcoin server."); @@ -220,88 +249,54 @@ Value stop(const Array& params, bool fHelp) // Call Table // - static const CRPCCommand vRPCCommands[] = -{ // name function safemd unlocked - // ------------------------ ----------------------- ------ -------- - { "help", &help, true, true }, - { "stop", &stop, true, true }, - { "addnode", &addnode, true, true }, - { "getaddednodeinfo", &getaddednodeinfo, true, true }, - { "getbestblockhash", &getbestblockhash, true, false }, - { "getblockcount", &getblockcount, true, false }, - { "getconnectioncount", &getconnectioncount, true, false }, - { "getpeerinfo", &getpeerinfo, true, false }, - { "ping", &ping, true, false }, - { "getnettotals", &getnettotals, true, true }, - { "getdifficulty", &getdifficulty, true, false }, - { "getinfo", &getinfo, true, false }, - { "getmininginfo", &getmininginfo, true, false }, - { "getstakinginfo", &getmininginfo, true, false }, - { "getnewaddress", &getnewaddress, true, false }, - { "getnewpubkey", &getnewpubkey, 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 }, - { "validatepubkey", &validatepubkey, true, false }, - { "getbalance", &getbalance, false, false }, - { "move", &movecmd, false, false }, - { "sendfrom", &sendfrom, false, false }, - { "sendmany", &sendmany, false, false }, - { "addmultisigaddress", &addmultisigaddress, false, false }, - { "addredeemscript", &addredeemscript, false, false }, - { "getrawmempool", &getrawmempool, true, false }, - { "getblock", &getblock, false, false }, - { "getblockbynumber", &getblockbynumber, false, false }, - { "getblockhash", &getblockhash, false, false }, - { "gettransaction", &gettransaction, false, false }, - { "listtransactions", &listtransactions, false, false }, - { "listaddressgroupings", &listaddressgroupings, false, false }, - { "signmessage", &signmessage, false, false }, - { "showblock", &showblock, false, false }, - { "verifymessage", &verifymessage, false, false }, - { "listaccounts", &listaccounts, false, false }, - { "settxfee", &settxfee, false, false }, - { "listsinceblock", &listsinceblock, false, false }, - { "dumpprivkey", &dumpprivkey, false, false }, - { "dumpwallet", &dumpwallet, true, false }, - { "importwallet", &importwallet, false, false }, - { "importprivkey", &importprivkey, false, false }, - { "listunspent", &listunspent, false, false }, - { "list", &listitem, false, false }, - { "execute", &execute, false, false }, - { "getrawtransaction", &getrawtransaction, false, false }, - { "createrawtransaction", &createrawtransaction, false, false }, - { "decoderawtransaction", &decoderawtransaction, false, false }, - { "decodescript", &decodescript, false, false }, - { "signrawtransaction", &signrawtransaction, false, false }, - { "sendrawtransaction", &sendrawtransaction, false, false }, - {"burn", &burn, false, false }, - { "getcheckpoint", &getcheckpoint, true, false }, - { "reservebalance", &reservebalance, false, true}, - { "checkwallet", &checkwallet, false, true}, - { "repairwallet", &repairwallet, false, true}, - { "resendtx", &resendtx, false, true}, - { "makekeypair", &makekeypair, false, true}, - { "sendalert", &sendalert, false, false}, - { "reorganize", &rpc_reorganize, false, false}, - { "getblockstats", &rpc_getblockstats, false, false}, - { "sendalert2", &sendalert2, false, false}, +{ // name function safemd unlocked category + // ------------------------ ----------------------- ------ -------- -------- + { "help", &help, true, true, cat_null }, + { "addmultisigaddress", &addmultisigaddress, false, false, cat_wallet }, + { "addredeemscript", &addredeemscript, false, false, cat_wallet }, + { "backupprivatekeys", &backupprivatekeys, false, true, cat_wallet }, }; +template +void ConvertTo(Value& value, bool fAllowNull=false) +{ + if (fAllowNull && value.type() == null_type) + return; + if (value.type() == str_type) + { + // reinterpret string as unquoted json value + Value value2; + string strJSON = value.get_str(); + if (!read_string(strJSON, value2)) + throw runtime_error(string("Error parsing JSON:")+strJSON); + ConvertTo(value2, fAllowNull); + value = value2; + } + else + { + value = value.get_value(); + } +} + +// Convert strings to command-specific RPC representation +Array RPCConvertValues(const std::string &strMethod, const std::vector &strParams) +{ + Array params; + for (auto const& param : strParams) + params.push_back(param); + + int n = params.size(); + + // + // Special case non-string parameter types + // + if (strMethod == "addmultisigaddress" && n > 0) ConvertTo(params[0]); + if (strMethod == "addmultisigaddress" && n > 1) ConvertTo(params[1]); + + return params; +} + CRPCTable::CRPCTable() { unsigned int vcidx; @@ -1132,104 +1127,6 @@ Object CallRPC(const string& strMethod, const Array& params) return reply; } - - - -template -void ConvertTo(Value& value, bool fAllowNull=false) -{ - if (fAllowNull && value.type() == null_type) - return; - if (value.type() == str_type) - { - // reinterpret string as unquoted json value - Value value2; - string strJSON = value.get_str(); - if (!read_string(strJSON, value2)) - throw runtime_error(string("Error parsing JSON:")+strJSON); - ConvertTo(value2, fAllowNull); - value = value2; - } - else - { - value = value.get_value(); - } -} - -// Convert strings to command-specific RPC representation -Array RPCConvertValues(const std::string &strMethod, const std::vector &strParams) -{ - Array params; - for (auto const& param : strParams) - params.push_back(param); - - int n = params.size(); - - // - // Special case non-string parameter types - // - //if (strMethod == "importprivkey" && n > 1) ConvertTo(params[1]); - if (strMethod == "stop" && n > 0) ConvertTo(params[0]); - if (strMethod == "sendtoaddress" && n > 1) ConvertTo(params[1]); - if (strMethod == "settxfee" && n > 0) ConvertTo(params[0]); - if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo(params[1]); - if (strMethod == "getreceivedbyaccount" && n > 1) ConvertTo(params[1]); - if (strMethod == "listreceivedbyaddress" && n > 0) ConvertTo(params[0]); - if (strMethod == "listreceivedbyaddress" && n > 1) ConvertTo(params[1]); - if (strMethod == "listreceivedbyaccount" && n > 0) ConvertTo(params[0]); - if (strMethod == "listreceivedbyaccount" && n > 1) ConvertTo(params[1]); - if (strMethod == "getbalance" && n > 1) ConvertTo(params[1]); - if (strMethod == "getblock" && n > 1) ConvertTo(params[1]); - if (strMethod == "getblockbynumber" && n > 0) ConvertTo(params[0]); - if (strMethod == "getblockbynumber" && n > 1) ConvertTo(params[1]); - if (strMethod == "getblockhash" && n > 0) ConvertTo(params[0]); - if (strMethod == "getaddednodeinfo" && n > 0) ConvertTo(params[0]); - if (strMethod == "showblock" && n > 0) ConvertTo(params[0]); - if (strMethod == "move" && n > 2) ConvertTo(params[2]); - if (strMethod == "move" && n > 3) ConvertTo(params[3]); - if (strMethod == "sendfrom" && n > 2) ConvertTo(params[2]); - if (strMethod == "sendfrom" && n > 3) ConvertTo(params[3]); - if (strMethod == "listtransactions" && n > 1) ConvertTo(params[1]); - if (strMethod == "listtransactions" && n > 2) ConvertTo(params[2]); - if (strMethod == "listtransactions" && n > 3) ConvertTo(params[3]); - if (strMethod == "listaccounts" && n > 0) ConvertTo(params[0]); - if (strMethod == "walletpassphrase" && n > 1) ConvertTo(params[1]); - if (strMethod == "walletpassphrase" && n > 2) ConvertTo(params[2]); - if (strMethod == "getblocktemplate" && n > 0) ConvertTo(params[0]); - if (strMethod == "listsinceblock" && n > 1) ConvertTo(params[1]); - if (strMethod == "listsinceblock" && n > 2) ConvertTo(params[2]); - - if (strMethod == "sendalert" && n > 2) ConvertTo(params[2]); - if (strMethod == "sendalert" && n > 3) ConvertTo(params[3]); - if (strMethod == "sendalert" && n > 4) ConvertTo(params[4]); - if (strMethod == "sendalert" && n > 5) ConvertTo(params[5]); - if (strMethod == "sendalert" && n > 6) ConvertTo(params[6]); - - if (strMethod == "sendalert2" && n > 5) ConvertTo(params[5]); - if (strMethod == "sendalert2" && n > 1) ConvertTo(params[1]); - if (strMethod == "sendalert2" && n > 4) ConvertTo(params[4]); - - if (strMethod == "sendmany" && n > 1) ConvertTo(params[1]); - if (strMethod == "sendmany" && n > 2) ConvertTo(params[2]); - if (strMethod == "reservebalance" && n > 0) ConvertTo(params[0]); - if (strMethod == "reservebalance" && n > 1) ConvertTo(params[1]); - if (strMethod == "addmultisigaddress" && n > 0) ConvertTo(params[0]); - if (strMethod == "addmultisigaddress" && n > 1) ConvertTo(params[1]); - if (strMethod == "listunspent" && n > 0) ConvertTo(params[0]); - if (strMethod == "upgrade" && n > 0) ConvertTo(params[0]); - if (strMethod == "listunspent" && n > 1) ConvertTo(params[1]); - if (strMethod == "listunspent" && n > 2) ConvertTo(params[2]); - if (strMethod == "getrawtransaction" && n > 1) ConvertTo(params[1]); - if (strMethod == "createrawtransaction" && n > 0) ConvertTo(params[0]); - if (strMethod == "createrawtransaction" && n > 1) ConvertTo(params[1]); - if (strMethod == "signrawtransaction" && n > 1) ConvertTo(params[1], true); - if (strMethod == "signrawtransaction" && n > 2) ConvertTo(params[2], true); - if (strMethod == "keypoolrefill" && n > 0) ConvertTo(params[0]); - if (strMethod == "burn" && n > 0) ConvertTo(params[0]); - - return params; -} - int CommandLineRPC(int argc, char *argv[]) { string strPrint; diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index c2362fee07..ef3a397faf 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -92,6 +92,15 @@ void RPCTypeCheck(const json_spirit::Object& o, typedef json_spirit::Value(*rpcfn_type)(const json_spirit::Array& params, bool fHelp); +enum rpccategory +{ + cat_null, + cat_wallet, + cat_neuralnetwork, + cat_developer, + cat_network +}; + class CRPCCommand { public: @@ -99,6 +108,7 @@ class CRPCCommand rpcfn_type actor; bool okSafeMode; bool unlocked; + rpccategory category; }; /** @@ -111,7 +121,7 @@ class CRPCTable public: CRPCTable(); const CRPCCommand* operator[](std::string name) const; - std::string help(std::string name) const; + std::string help(std::string name, rpccategory category) const; /** * Execute a method. @@ -141,6 +151,13 @@ extern uint256 ParseHashV(const json_spirit::Value& v, std::string strName); extern uint256 ParseHashO(const json_spirit::Object& o, std::string strKey); extern std::vector ParseHexV(const json_spirit::Value& v, std::string strName); +// Rpc reordered by category + +// Wallet +extern json_spirit::Value addmultisigaddress(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value addredeemscript(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value backupprivatekeys(const json_spirit::Array& params, bool fHelp); + extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value ping(const json_spirit::Array& params, bool fHelp); @@ -169,8 +186,6 @@ extern json_spirit::Value getbalance(const json_spirit::Array& params, bool fHel extern json_spirit::Value movecmd(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value sendfrom(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value sendmany(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value addmultisigaddress(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value addredeemscript(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value listreceivedbyaddress(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value listreceivedbyaccount(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value listtransactions(const json_spirit::Array& params, bool fHelp); @@ -225,4 +240,7 @@ extern json_spirit::Value rpc_reorganize(const json_spirit::Array& params, bool extern json_spirit::Value rpc_getblockstats(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value sendalert2(const json_spirit::Array& params, bool fHelp); +// iFoggz +//extern json_spirit::Value blockchain(const json_spirit::Array& params, bool fHelp); + #endif From 0e058a359ba86d473e32d6f624410d6472d42bdf Mon Sep 17 00:00:00 2001 From: Paul Jensen Date: Wed, 14 Feb 2018 14:38:39 -0800 Subject: [PATCH 03/28] initial changes for last of testing --- src/rpcblockchain.cpp | 51 +++++++++++++++++++++++++++---------------- src/rpcwallet.cpp | 3 +++ 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index e2a177edfc..84350f8852 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1063,6 +1063,31 @@ int64_t AmountFromDouble(double dAmount) return nAmount; } +// Rpc + +Value backupprivatekeys(const Array& params, bool fHelp) +{ + if (fHelp || params.size() > 0) + throw runtime_error( + "backupprivatekeys\n" + "\n" + "Backup wallet private keys to file\n" + "Wallet must be fully unlocked!\n"); + + string sErrors; + string sTarget; + Object entry; + bool bBackupPrivateKeys = BackupPrivateKeys(*pwalletMain, sTarget, sErrors); + + if (!bBackupPrivateKeys) + entry.push_back(Pair("error", sErrors)); + + else + entry.push_back(Pair("location", sTarget)); + + entry.push_back(Pair("result", bBackupPrivateKeys)); + return entry; +} Value execute(const Array& params, bool fHelp) { @@ -2377,19 +2402,7 @@ Value execute(const Array& params, bool fHelp) entry.push_back(Pair("execute writedata ", "Write data to a key with value")); results.push_back(entry); } - else if (sItem == "backupprivatekeys") - { - string sErrors; - string sTarget; - bool bBackupPrivateKeys = BackupPrivateKeys(*pwalletMain, sTarget, sErrors); - if (!bBackupPrivateKeys) - entry.push_back(Pair("error", sErrors)); - else - entry.push_back(Pair("location", sTarget)); - entry.push_back(Pair("result", bBackupPrivateKeys)); - results.push_back(entry); - } - else +else { entry.push_back(Pair("Command " + sItem + " not found.",-1)); results.push_back(entry); @@ -4082,13 +4095,13 @@ static bool compare_second(const pair &p1, const pair p2.second; } -json_spirit::Value rpc_getblockstats(const json_spirit::Array& params, bool fHelp) +Value rpc_getblockstats(const json_spirit::Array& params, bool fHelp) { if(fHelp || params.size() < 1 || params.size() > 3 ) throw runtime_error( "getblockstats mode [startheight [endheight]]\n" "Show stats on what wallets and cpids staked recent blocks.\n"); - long mode= RoundFromString(params[0].get_str(),0); + long mode= params[0].get_int(); (void)mode; //TODO long lowheight= 0; long highheight= INT_MAX; @@ -4097,20 +4110,20 @@ json_spirit::Value rpc_getblockstats(const json_spirit::Array& params, bool fHel { if(params.size()>=2) { - lowheight= RoundFromString(params[1].get_str(),0); + lowheight= params[1].get_int(); maxblocks= INT_MAX; } if(params.size()>=3) - highheight= RoundFromString(params[2].get_str(),0); + highheight= params[2].get_int(); } else if(mode==1) { /* count highheight */ maxblocks= 30000; if(params.size()>=2) - maxblocks= RoundFromString(params[1].get_str(),0); + maxblocks= params[1].get_int(); if(params.size()>=3) - highheight= RoundFromString(params[2].get_str(),0); + highheight= params[2].get_int(); } else throw runtime_error("getblockstats: Invalid mode specified"); CBlockIndex* cur; diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index ba9e075c8e..c472d8e7e8 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -848,6 +848,7 @@ Value addmultisigaddress(const Array& params, bool fHelp) if (fHelp || params.size() < 2 || params.size() > 3) { string msg = "addmultisigaddress <'[\"key\",\"key\"]'> [account]\n" + "\n" "Add a nrequired-to-sign multisignature address to the wallet\n" "each key is a Gridcoin address or hex-encoded public key\n" "If [account] is specified, assign address to [account]."; @@ -922,6 +923,7 @@ Value addredeemscript(const Array& params, bool fHelp) if (fHelp || params.size() < 1 || params.size() > 2) { string msg = "addredeemscript [account]\n" + "\n" "Add a P2SH address with a specified redeemScript to the wallet.\n" "If [account] is specified, assign address to [account]."; throw runtime_error(msg); @@ -1694,6 +1696,7 @@ Value backupwallet(const Array& params, bool fHelp) if (fHelp || params.size() > 0) throw runtime_error( "backupwallet\n" + "\n" "Backup your wallet and config files."); bool bWalletBackupResults = BackupWallet(*pwalletMain, GetBackupFilename("wallet.dat")); From 4fa945d643b21ffdbc1cab56c1c283f60c480c02 Mon Sep 17 00:00:00 2001 From: Paul Jensen Date: Thu, 15 Feb 2018 23:28:33 -0800 Subject: [PATCH 04/28] Remove unlocked feature no longer used by bitcoin; Move locks into rpc calls beyond runtime return for rpc help or missing parameters; modified some locks to meet how bitcoin does it for the same task; reduced the scope sizes in the end; --- src/bitcoinrpc.cpp | 126 ++++++++++++++++++++++++++++++----- src/bitcoinrpc.h | 106 +++++++++++++++-------------- src/rpcdump.cpp | 23 ++++--- src/rpcrawtransaction.cpp | 38 +++++++---- src/rpcwallet.cpp | 137 ++++++++++++++++++++++++++++---------- 5 files changed, 306 insertions(+), 124 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index a3474a163a..54a7f6b745 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -236,7 +236,7 @@ Value stop(const Array& params, bool fHelp) if (fHelp || params.size() > 0) throw runtime_error( "stop\n" - "Stop Gridcoin server."); + "Stop Gridcoin server.\n"); // Shutdown will take long enough that the response should get back LogPrintf("Stopping...\n"); StartShutdown(); @@ -248,14 +248,71 @@ Value stop(const Array& params, bool fHelp) // // Call Table // +// We no longer use the unlocked feature here. +// Bitcoin has removed this option and placed the locks inside the rpc calls to reduce the scope +// Also removes the un needed locking when the end result is a rpc run time error reply over params! +// This also has improved the performance of rpc outputs. static const CRPCCommand vRPCCommands[] = -{ // name function safemd unlocked category - // ------------------------ ----------------------- ------ -------- -------- - { "help", &help, true, true, cat_null }, - { "addmultisigaddress", &addmultisigaddress, false, false, cat_wallet }, - { "addredeemscript", &addredeemscript, false, false, cat_wallet }, - { "backupprivatekeys", &backupprivatekeys, false, true, cat_wallet }, +{ // name function safemd category + // ------------------------ ----------------------- ------ ----------------- + { "help", &help, true, cat_null }, + { "addmultisigaddress", &addmultisigaddress, false, cat_wallet }, + { "addredeemscript", &addredeemscript, false, cat_wallet }, + { "backupprivatekeys", &backupprivatekeys, false, cat_wallet }, + { "backupwallet", &backupwallet, true, cat_wallet }, + { "burn", &burn, false, cat_wallet }, + { "burn2", &burn2, false, cat_wallet }, + { "checkwallet", &checkwallet, false, cat_wallet }, + { "createrawtransaction", &createrawtransaction, false, cat_wallet }, + { "decoderawtransaction", &decoderawtransaction, false, cat_wallet }, + { "decodescript", &decodescript, false, cat_wallet }, + { "dumpprivkey", &dumpprivkey, false, cat_wallet }, + { "dumpwallet", &dumpwallet, true, cat_wallet }, + { "encrypt", &encrypt, true, cat_wallet }, + { "encryptwallet", &encryptwallet, false, cat_wallet }, + { "getaccount", &getaccount, false, cat_wallet }, + { "getaccountaddress", &getaccountaddress, true, cat_wallet }, + { "getaddressesbyaccount", &getaddressesbyaccount, true, cat_wallet }, + { "getbalance", &getbalance, false, cat_wallet }, + { "getnewaddress", &getnewaddress, true, cat_wallet }, + { "getnewpubkey", &getnewpubkey, true, cat_wallet }, + { "getrawtransaction", &getrawtransaction, false, cat_wallet }, + { "getreceivedbyaccount", &getreceivedbyaccount, false, cat_wallet }, + { "getreceivedbyaddress", &getreceivedbyaddress, false, cat_wallet }, + { "gettransaction", &gettransaction, false, cat_wallet }, + { "importprivkey", &importprivkey, false, cat_wallet }, + { "importwallet", &importwallet, false, cat_wallet }, + { "keypoolrefill", &keypoolrefill, true, cat_wallet }, + { "listaccounts", &listaccounts, false, cat_wallet }, + { "listaddressgroupings", &listaddressgroupings, false, cat_wallet }, + { "listreceivedbyaccount", &listreceivedbyaccount, false, cat_wallet }, + { "listreceivedbyaddress", &listreceivedbyaddress, false, cat_wallet }, + { "listsinceblock", &listsinceblock, false, cat_wallet }, + { "listtransactions", &listtransactions, false, cat_wallet }, + { "listunspent", &listunspent, false, cat_wallet }, + { "makekeypair", &makekeypair, false, cat_wallet }, + { "move", &movecmd, false, cat_wallet }, + { "newburnaddress", &newburnaddress, false, cat_wallet }, + { "rain", &rain, false, cat_wallet }, + { "repairewallet", &repairwallet, false, cat_wallet }, + { "resendtx", &resendtx, false, cat_wallet }, + { "reservebalance", &reservebalance, false, cat_wallet }, + { "sendfrom", &sendfrom, false, cat_wallet }, + { "sendrawtransaction", &sendrawtransaction, false, cat_wallet }, + { "sendtoaddress", &sendtoaddress, false, cat_wallet }, + { "setaccount", &setaccount, true, cat_wallet }, + { "settxfee", &settxfee, false, cat_wallet }, + { "signmessage", &signmessage, false, cat_wallet }, + { "signrawtransaction", &signrawtransaction, false, cat_wallet }, + { "unspentreport", &unspentreport, false, cat_wallet }, + { "validateaddress", &validateaddress, true, cat_wallet }, + { "validatepubkey", &validatepubkey, true, cat_wallet }, + { "verifymessage", &verifymessage, false, cat_wallet }, + { "walletlock", &walletlock, true, cat_wallet }, + { "walletpassphrase", &walletpassphrase, true, cat_wallet }, + { "walletpassphrasechange", &walletpassphrasechange, false, cat_wallet }, + }; template @@ -291,8 +348,51 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 0) ConvertTo(params[0]); if (strMethod == "addmultisigaddress" && n > 1) ConvertTo(params[1]); + if (strMethod == "burn" && n > 0) ConvertTo(params[0]); + if (strMethod == "burn2" && n > 1) ConvertTo(params[1]); + if (strMethod == "createrawtransaction" && n > 0) ConvertTo(params[0]); + if (strMethod == "createrawtransaction" && n > 1) ConvertTo(params[1]); + if (strMethod == "getbalance" && n > 1) ConvertTo(params[1]); + if (strMethod == "getbalance" && n > 2) ConvertTo(params[2]); + if (strMethod == "getrawtransaction" && n > 1) ConvertTo(params[1]); + if (strMethod == "getreceivedbyaccount" && n > 1) ConvertTo(params[1]); + if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo(params[1]); + if (strMethod == "gettransaction" && n > 1) ConvertTo(params[1]); + if (strMethod == "importprivkey" && n > 2) ConvertTo(params[2]); + if (strMethod == "keypoolrefill" && n > 0) ConvertTo(params[0]); + if (strMethod == "listaccounts" && n > 0) ConvertTo(params[0]); + if (strMethod == "listaccounts" && n > 1) ConvertTo(params[1]); + if (strMethod == "listreceivedbyaccount" && n > 0) ConvertTo(params[0]); + if (strMethod == "listreceivedbyaccount" && n > 1) ConvertTo(params[1]); + if (strMethod == "listreceivedbyaccount" && n > 2) ConvertTo(params[2]); + if (strMethod == "listreceivedbyaddress" && n > 0) ConvertTo(params[0]); + if (strMethod == "listreceivedbyaddress" && n > 1) ConvertTo(params[1]); + if (strMethod == "listreceivedbyaddress" && n > 2) ConvertTo(params[2]); + if (strMethod == "listsinceblock" && n > 1) ConvertTo(params[1]); + if (strMethod == "listsinceblock" && n > 2) ConvertTo(params[2]); + if (strMethod == "listtransactions" && n > 1) ConvertTo(params[1]); + if (strMethod == "listtransactions" && n > 2) ConvertTo(params[2]); + if (strMethod == "listtransactions" && n > 3) ConvertTo(params[3]); + if (strMethod == "listunspent" && n > 0) ConvertTo(params[0]); + if (strMethod == "listunspent" && n > 1) ConvertTo(params[1]); + if (strMethod == "listunspent" && n > 2) ConvertTo(params[2]); + if (strMethod == "move" && n > 2) ConvertTo(params[2]); + if (strMethod == "move" && n > 3) ConvertTo(params[3]); + if (strMethod == "reservebalance" && n > 0) ConvertTo(params[0]); + if (strMethod == "reservebalance" && n > 1) ConvertTo(params[1]); + if (strMethod == "sendfrom" && n > 2) ConvertTo(params[2]); + if (strMethod == "sendfrom" && n > 3) ConvertTo(params[3]); + if (strMethod == "sendmany" && n > 1) ConvertTo(params[1]); + if (strMethod == "sendmany" && n > 2) ConvertTo(params[2]); + if (strMethod == "sendtoaddress" && n > 1) ConvertTo(params[1]); + if (strMethod == "settxfee" && n > 0) ConvertTo(params[0]); + if (strMethod == "signrawtransaction" && n > 1) ConvertTo(params[1], true); + if (strMethod == "signrawtransaction" && n > 2) ConvertTo(params[2], true); + if (strMethod == "walletpassphrase" && n > 1) ConvertTo(params[1]); + if (strMethod == "walletpassphrase" && n > 2) ConvertTo(params[2]); return params; } @@ -1058,15 +1158,8 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s try { // Execute - Value result; - { - if (pcmd->unlocked) - result = pcmd->actor(params, false); - else { - LOCK2(cs_main, pwalletMain->cs_wallet); - result = pcmd->actor(params, false); - } - } + Value result = pcmd->actor(params, false); + return result; } catch (std::exception& e) @@ -1075,7 +1168,6 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s } } - Object CallRPC(const string& strMethod, const Array& params) { if (mapArgs["-rpcuser"] == "" && mapArgs["-rpcpassword"] == "") diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index ef3a397faf..d901cfa7fa 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -107,7 +107,6 @@ class CRPCCommand std::string name; rpcfn_type actor; bool okSafeMode; - bool unlocked; rpccategory category; }; @@ -157,14 +156,64 @@ extern std::vector ParseHexV(const json_spirit::Value& v, std::st extern json_spirit::Value addmultisigaddress(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value addredeemscript(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value backupprivatekeys(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value backupwallet(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value burn(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value burn2(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value checkwallet(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value createrawtransaction(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value decoderawtransaction(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value decodescript(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value dumpwallet(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value encrypt(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value encryptwallet(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getaccount(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getaccountaddress(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getaddressesbyaccount(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getbalance(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getnewaddress(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getnewpubkey(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getreceivedbyaccount(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getreceivedbyaddress(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value gettransaction(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value importwallet(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value keypoolrefill(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value listaccounts(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value listaddressgroupings(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value listreceivedbyaccount(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value listreceivedbyaddress(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value listsinceblock(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value listtransactions(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value makekeypair(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value movecmd(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value newburnaddress(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value rain(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value repairwallet(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value resendtx(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value reservebalance(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value sendfrom(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value sendmany(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value sendrawtransaction(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value sendtoaddress(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value setaccount(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value settxfee(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value signmessage(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value signrawtransaction(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value unspentreport(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value validateaddress(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value validatepubkey(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value verifymessage(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value walletlock(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value walletpassphrase(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value walletpassphrasechange(const json_spirit::Array& params, bool fHelp); + extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value ping(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value dumpwallet(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value importwallet(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp -extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value sendalert(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp); @@ -172,57 +221,12 @@ extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool f extern json_spirit::Value getnettotals(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getnewaddress(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp -extern json_spirit::Value getaccountaddress(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value setaccount(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getaccount(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getaddressesbyaccount(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value sendtoaddress(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value signmessage(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value verifymessage(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getreceivedbyaddress(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getreceivedbyaccount(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getbalance(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value movecmd(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value sendfrom(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value sendmany(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value listreceivedbyaddress(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value listreceivedbyaccount(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value listtransactions(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value listaddressgroupings(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value listaccounts(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value listsinceblock(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value gettransaction(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value backupwallet(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value keypoolrefill(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value walletpassphrase(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value walletpassphrasechange(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value walletlock(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value encryptwallet(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value validateaddress(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getinfo(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value reservebalance(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value checkwallet(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value repairwallet(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value resendtx(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value makekeypair(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value validatepubkey(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getnewpubkey(const json_spirit::Array& params, bool fHelp); - -extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bool fHelp); // in rcprawtransaction.cpp -extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value createrawtransaction(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value decoderawtransaction(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value decodescript(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value signrawtransaction(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value sendrawtransaction(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value burn(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getbestblockhash(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp extern json_spirit::Value getdifficulty(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value settxfee(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getrawmempool(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getblockhash(const json_spirit::Array& params, bool fHelp); diff --git a/src/rpcdump.cpp b/src/rpcdump.cpp index fe6e802b08..8aaf8a29cd 100644 --- a/src/rpcdump.cpp +++ b/src/rpcdump.cpp @@ -108,7 +108,7 @@ Value importprivkey(const Array& params, bool fHelp) if (fHelp || params.size() < 1 || params.size() > 3) throw runtime_error( "importprivkey [label] [rescan=true]\n" - "Adds a private key (as returned by dumpprivkey) to your wallet."); + "Adds a private key (as returned by dumpprivkey) to your wallet.\n"); string strSecret = params[0].get_str(); string strLabel = ""; @@ -118,11 +118,7 @@ Value importprivkey(const Array& params, bool fHelp) // Whether to perform rescan after import bool fRescan = true; if (params.size() > 2) - { - string strRescan = params[2].get_str(); - fRescan = (strRescan=="true") ? true : false; - } - + fRescan = params[2].get_bool(); CBitcoinSecret vchSecret; bool fGood = vchSecret.SetString(strSecret); @@ -169,15 +165,17 @@ Value importwallet(const Array& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "importwallet \n" - "Imports keys from a wallet dump file (see dumpwallet)."); - - EnsureWalletIsUnlocked(); + "Imports keys from a wallet dump file (see dumpwallet).\n"); ifstream file; file.open(params[0].get_str().c_str()); if (!file.is_open()) throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file"); + LOCK2(cs_main, pwalletMain->cs_wallet); + + EnsureWalletIsUnlocked(); + int64_t nTimeBegin = pindexBest->nTime; bool fGood = true; @@ -267,6 +265,9 @@ Value dumpprivkey(const Array& params, bool fHelp) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Gridcoin address"); if (fWalletUnlockStakingOnly) throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Wallet is unlocked for staking only."); + + LOCK2(cs_main, pwalletMain->cs_wallet); + CKeyID keyID; if (!address.GetKeyID(keyID)) throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key"); @@ -282,7 +283,7 @@ Value dumpwallet(const Array& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "dumpwallet \n" - "Dumps all wallet keys in a human-readable format."); + "Dumps all wallet keys in a human-readable format.\n"); EnsureWalletIsUnlocked(); @@ -295,6 +296,8 @@ Value dumpwallet(const Array& params, bool fHelp) std::set setKeyPool; + LOCK2(cs_main, pwalletMain->cs_wallet); + pwalletMain->GetKeyBirthTimes(mapKeyBirth); pwalletMain->GetAllReserveKeys(setKeyPool); diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 7b76301d81..ff496b22bf 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -484,18 +484,20 @@ Value getrawtransaction(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( - "getrawtransaction [verbose=0]\n" - "If verbose=0, returns a string that is\n" + "getrawtransaction [verbose=bool]\n" + "If verbose is false, returns a string that is\n" "serialized, hex-encoded data for .\n" - "If verbose is non-zero, returns an Object\n" - "with information about ."); + "If verbose is true, returns an Object\n" + "with information about .\n"); uint256 hash; hash.SetHex(params[0].get_str()); bool fVerbose = false; if (params.size() > 1) - fVerbose = (params[1].get_int() != 0); + fVerbose = (params[1].get_bool()); + + LOCK(cs_main); CTransaction tx; uint256 hashBlock = 0; @@ -524,7 +526,7 @@ Value listunspent(const Array& params, bool fHelp) "with between minconf and maxconf (inclusive) confirmations.\n" "Optionally filtered to only include txouts paid to specified addresses.\n" "Results are an array of Objects, each of which has:\n" - "{txid, vout, scriptPubKey, amount, confirmations}"); + "{txid, vout, scriptPubKey, amount, confirmations}\n"); RPCTypeCheck(params, list_of(int_type)(int_type)(array_type)); @@ -552,7 +554,11 @@ Value listunspent(const Array& params, bool fHelp) } Array results; + vector vecOutputs; + + LOCK2(cs_main, pwalletMain->cs_wallet); + pwalletMain->AvailableCoins(vecOutputs, false,NULL,false); for (auto const& out : vecOutputs) { @@ -623,14 +629,15 @@ Value createrawtransaction(const Array& params, bool fHelp) "createrawtransaction \"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"{\\\"address\\\":0.01} " "createrawtransaction \"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"{\\\"data\\\":\\\"00010203\\\"} " "createrawtransaction \"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"address\\\":0.01} " - "createrawtransaction \"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"data\\\":\\\"00010203\\\"} " + "createrawtransaction \"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"data\\\":\\\"00010203\\\"} \n" ); - LOCK(cs_main); RPCTypeCheck(params, list_of(array_type)(obj_type)); Array inputs = params[0].get_array(); Object sendTo = params[1].get_obj(); + LOCK2(cs_main, pwalletMain->cs_wallet); + CTransaction rawTx; for (auto const& input : inputs) @@ -694,11 +701,14 @@ Value decoderawtransaction(const Array& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "decoderawtransaction \n" - "Return a JSON object representing the serialized, hex-encoded transaction."); + "Return a JSON object representing the serialized, hex-encoded transaction.\n"); RPCTypeCheck(params, list_of(str_type)); vector txData(ParseHex(params[0].get_str())); + + LOCK(cs_main); + CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION); CTransaction tx; try { @@ -719,7 +729,7 @@ Value decodescript(const Array& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "decodescript \n" - "Decode a hex-encoded script."); + "Decode a hex-encoded script.\n"); RPCTypeCheck(params, list_of(str_type)); @@ -751,11 +761,13 @@ Value signrawtransaction(const Array& params, bool fHelp) "ALL|ANYONECANPAY, NONE|ANYONECANPAY, SINGLE|ANYONECANPAY.\n" "Returns json object with keys:\n" " hex : raw transaction with signature(s) (hex-encoded string)\n" - " complete : 1 if transaction has a complete set of signature (0 if not)" + " complete : 1 if transaction has a complete set of signature (0 if not)\n" + HelpRequiringPassphrase()); RPCTypeCheck(params, list_of(str_type)(array_type)(array_type)(str_type), true); + LOCK2(cs_main, pwalletMain->cs_wallet); + vector txData(ParseHex(params[0].get_str())); CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION); vector txVariants; @@ -932,10 +944,12 @@ Value sendrawtransaction(const Array& params, bool fHelp) if (fHelp || params.size() < 1 || params.size() > 1) throw runtime_error( "sendrawtransaction \n" - "Submits raw transaction (serialized, hex-encoded) to local node and network."); + "Submits raw transaction (serialized, hex-encoded) to local node and network.\n"); RPCTypeCheck(params, list_of(str_type)); + LOCK(cs_main); + // parse hex string from parameter vector txData(ParseHex(params[0].get_str())); CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION); diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index c472d8e7e8..33f13dc289 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -144,13 +144,15 @@ Value getnewpubkey(const Array& params, bool fHelp) if (fHelp || params.size() > 1) throw runtime_error( "getnewpubkey [account]\n" - "Returns new public key for coinbase generation."); + "Returns new public key for coinbase generation.\n"); // Parse the account first so we don't generate a key if there's an error string strAccount; if (params.size() > 0) strAccount = AccountFromValue(params[0]); + LOCK2(cs_main, pwalletMain->cs_wallet); + if (!pwalletMain->IsLocked()) pwalletMain->TopUpKeyPool(); @@ -174,13 +176,15 @@ Value getnewaddress(const Array& params, bool fHelp) "getnewaddress [account]\n" "Returns a new Gridcoin address for receiving payments. " "If [account] is specified, it is added to the address book " - "so payments received with the address will be credited to [account]."); + "so payments received with the address will be credited to [account].\n"); // Parse the account first so we don't generate a key if there's an error string strAccount; if (params.size() > 0) strAccount = AccountFromValue(params[0]); + LOCK2(cs_main, pwalletMain->cs_wallet); + if (!pwalletMain->IsLocked()) pwalletMain->TopUpKeyPool(); @@ -239,13 +243,15 @@ Value getaccountaddress(const Array& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "getaccountaddress \n" - "Returns the current Gridcoin address for receiving payments to this account."); + "Returns the current Gridcoin address for receiving payments to this account.\n"); // Parse the account first so we don't generate a key if there's an error string strAccount = AccountFromValue(params[0]); Value ret; + LOCK2(cs_main, pwalletMain->cs_wallet); + ret = GetAccountAddress(strAccount).ToString(); return ret; @@ -258,13 +264,14 @@ Value setaccount(const Array& params, bool fHelp) if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( "setaccount \n" - "Sets the account associated with the given address."); + "Sets the account associated with the given address.\n"); + + LOCK2(cs_main, pwalletMain->cs_wallet); CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Gridcoin address"); - string strAccount; if (params.size() > 1) strAccount = AccountFromValue(params[1]); @@ -288,13 +295,16 @@ Value getaccount(const Array& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "getaccount \n" - "Returns the account associated with the given address."); + "Returns the account associated with the given address.\n"); + + LOCK2(cs_main, pwalletMain->cs_wallet); CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Gridcoin address"); string strAccount; + map::iterator mi = pwalletMain->mapAddressBook.find(address.Get()); if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.empty()) strAccount = (*mi).second; @@ -307,12 +317,15 @@ Value getaddressesbyaccount(const Array& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "getaddressesbyaccount \n" - "Returns the list of addresses for the given account."); + "Returns the list of addresses for the given account.\n"); string strAccount = AccountFromValue(params[0]); // Find all addresses that have the given account Array ret; + + LOCK2(cs_main, pwalletMain->cs_wallet); + for (auto const& item : pwalletMain->mapAddressBook) { const CBitcoinAddress& address = item.first; @@ -328,9 +341,11 @@ Value sendtoaddress(const Array& params, bool fHelp) if (fHelp || params.size() < 2 || params.size() > 4) throw runtime_error( "sendtoaddress [comment] [comment-to]\n" - " is a real and is rounded to the nearest 0.000001" + " is a real and is rounded to the nearest 0.000001\n" + HelpRequiringPassphrase()); + LOCK2(cs_main, pwalletMain->cs_wallet); + CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Gridcoin address"); @@ -362,7 +377,9 @@ Value listaddressgroupings(const Array& params, bool fHelp) "listaddressgroupings\n" "Lists groups of addresses which have had their common ownership\n" "made public by common use as inputs or as the resulting change\n" - "in past transactions"); + "in past transactions\n"); + + LOCK2(cs_main, pwalletMain->cs_wallet); Array jsonGroupings; map balances = pwalletMain->GetAddressBalances(); @@ -375,7 +392,6 @@ Value listaddressgroupings(const Array& params, bool fHelp) addressInfo.push_back(CBitcoinAddress(address).ToString()); addressInfo.push_back(ValueFromAmount(balances[address])); { - LOCK(pwalletMain->cs_wallet); if (pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get()) != pwalletMain->mapAddressBook.end()) addressInfo.push_back(pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get())->second); } @@ -391,7 +407,9 @@ Value signmessage(const Array& params, bool fHelp) if (fHelp || params.size() != 2) throw runtime_error( "signmessage \n" - "Sign a message with the private key of an address"); + "Sign a message with the private key of an address\n"); + + LOCK2(cs_main, pwalletMain->cs_wallet); EnsureWalletIsUnlocked(); @@ -426,12 +444,14 @@ Value verifymessage(const Array& params, bool fHelp) if (fHelp || params.size() != 3) throw runtime_error( "verifymessage \n" - "Verify a signed message"); + "Verify a signed message\n"); string strAddress = params[0].get_str(); string strSign = params[1].get_str(); string strMessage = params[2].get_str(); + LOCK(cs_main); + CBitcoinAddress addr(strAddress); if (!addr.IsValid()) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address"); @@ -463,7 +483,9 @@ Value getreceivedbyaddress(const Array& params, bool fHelp) if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( "getreceivedbyaddress [minconf=1]\n" - "Returns the total amount received by in transactions with at least [minconf] confirmations."); + "Returns the total amount received by in transactions with at least [minconf] confirmations.\n"); + + LOCK2(cs_main, pwalletMain->cs_wallet); // Bitcoin address CBitcoinAddress address = CBitcoinAddress(params[0].get_str()); @@ -513,7 +535,7 @@ Value getreceivedbyaccount(const Array& params, bool fHelp) if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( "getreceivedbyaccount [minconf=1]\n" - "Returns the total amount received by addresses with in transactions with at least [minconf] confirmations."); + "Returns the total amount received by addresses with in transactions with at least [minconf] confirmations.\n"); accountingDeprecationCheck(); @@ -522,6 +544,8 @@ Value getreceivedbyaccount(const Array& params, bool fHelp) if (params.size() > 1) nMinDepth = params[1].get_int(); + LOCK2(cs_main, pwalletMain->cs_wallet); + // Get the set of pub keys assigned to account string strAccount = AccountFromValue(params[0]); set setAddress; @@ -630,6 +654,7 @@ Value getbalance(const Array& params, bool fHelp) "\nAs a json rpc call\n" ); + LOCK2(cs_main, pwalletMain->cs_wallet); if (params.size() == 0) return ValueFromAmount(pwalletMain->GetBalance()); @@ -689,7 +714,7 @@ Value movecmd(const Array& params, bool fHelp) if (fHelp || params.size() < 3 || params.size() > 5) throw runtime_error( "move [minconf=1] [comment]\n" - "Move from one account in your wallet to another."); + "Move from one account in your wallet to another.\n"); accountingDeprecationCheck(); @@ -704,6 +729,8 @@ Value movecmd(const Array& params, bool fHelp) if (params.size() > 4) strComment = params[4].get_str(); + LOCK2(cs_main, pwalletMain->cs_wallet); + CWalletDB walletdb(pwalletMain->strWalletFile); if (!walletdb.TxnBegin()) throw JSONRPCError(RPC_DATABASE_ERROR, "database error"); @@ -742,10 +769,13 @@ Value sendfrom(const Array& params, bool fHelp) if (fHelp || params.size() < 3 || params.size() > 6) throw runtime_error( "sendfrom [minconf=1] [comment] [comment-to]\n" - " is a real and is rounded to the nearest 0.000001" + " is a real and is rounded to the nearest 0.000001\n" + HelpRequiringPassphrase()); string strAccount = AccountFromValue(params[0]); + + LOCK2(cs_main, pwalletMain->cs_wallet); + CBitcoinAddress address(params[1].get_str()); if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Gridcoin address"); @@ -783,7 +813,7 @@ Value sendmany(const Array& params, bool fHelp) if (fHelp || params.size() < 2 || params.size() > 4) throw runtime_error( "sendmany {address:amount,...} [minconf=1] [comment]\n" - "amounts are double-precision floating point numbers" + "amounts are double-precision floating point numbers\n" + HelpRequiringPassphrase()); string strAccount = AccountFromValue(params[0]); @@ -792,6 +822,8 @@ Value sendmany(const Array& params, bool fHelp) if (params.size() > 2) nMinDepth = params[2].get_int(); + LOCK2(cs_main, pwalletMain->cs_wallet); + CWalletTx wtx; wtx.strFromAccount = strAccount; if (params.size() > 3 && params[3].type() != null_type && !params[3].get_str().empty()) @@ -851,7 +883,7 @@ Value addmultisigaddress(const Array& params, bool fHelp) "\n" "Add a nrequired-to-sign multisignature address to the wallet\n" "each key is a Gridcoin address or hex-encoded public key\n" - "If [account] is specified, assign address to [account]."; + "If [account] is specified, assign address to [account].\n"; throw runtime_error(msg); } @@ -871,9 +903,11 @@ Value addmultisigaddress(const Array& params, bool fHelp) if (keys.size() > 16) throw runtime_error("Number of addresses involved in the multisignature address creation > 16\nReduce the number"); - std::vector pubkeys; pubkeys.resize(keys.size()); + + LOCK2(cs_main, pwalletMain->cs_wallet); + for (unsigned int i = 0; i < keys.size(); i++) { const std::string& ks = keys[i].get_str(); @@ -925,7 +959,7 @@ Value addredeemscript(const Array& params, bool fHelp) string msg = "addredeemscript [account]\n" "\n" "Add a P2SH address with a specified redeemScript to the wallet.\n" - "If [account] is specified, assign address to [account]."; + "If [account] is specified, assign address to [account].\n"; throw runtime_error(msg); } @@ -933,6 +967,8 @@ Value addredeemscript(const Array& params, bool fHelp) if (params.size() > 1) strAccount = AccountFromValue(params[1]); + LOCK2(cs_main, pwalletMain->cs_wallet); + // Construct using pay-to-script-hash: vector innerData = ParseHexV(params[0], "redeemScript"); CScript inner(innerData.begin(), innerData.end()); @@ -1129,6 +1165,8 @@ Value listreceivedbyaddress(const Array& params, bool fHelp) "\nExamples:\n" ); + LOCK2(cs_main, pwalletMain->cs_wallet); + return ListReceived(params, false); } @@ -1151,6 +1189,8 @@ Value listreceivedbyaccount(const Array& params, bool fHelp) " \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n" ); + LOCK2(cs_main, pwalletMain->cs_wallet); + accountingDeprecationCheck(); return ListReceived(params, true); @@ -1419,6 +1459,7 @@ Value listtransactions(const Array& params, bool fHelp) "\nList transactions 100 to 120 from the tabby account\n" "\nAs a json rpc call\n" ); + string strAccount = "*"; int nCount = 10; int nFrom = 0; @@ -1447,6 +1488,7 @@ Value listtransactions(const Array& params, bool fHelp) Array ret; + LOCK2(cs_main, pwalletMain->cs_wallet); std::list acentries; CWallet::TxItems txOrdered = pwalletMain->OrderedTxItems(acentries, strAccount); @@ -1507,6 +1549,9 @@ Value listaccounts(const Array& params, bool fHelp) if(params[1].get_bool()) includeWatchonly = includeWatchonly | MINE_WATCH_ONLY; } + + LOCK2(cs_main, pwalletMain->cs_wallet); + map mapAccountBalances; for (auto const& entry : pwalletMain->mapAddressBook) { if (IsMine(*pwalletMain, entry.first) & includeWatchonly) // This address belongs to me @@ -1564,6 +1609,8 @@ Value listsinceblock(const Array& params, bool fHelp) " \"transactions\": [\n" ); + LOCK2(cs_main, pwalletMain->cs_wallet); + CBlockIndex *pindex = NULL; int target_confirms = 1; isminefilter filter = MINE_SPENDABLE; @@ -1628,7 +1675,7 @@ Value gettransaction(const Array& params, bool fHelp) "2. \"includeWatchonly\" (bool, optional, default=false) Whether to include watchonly addresses in balance calculation and details[]\n" "\nResult:\n" "{\n" - " \"amount\" : x.xxx, (numeric) The transaction amount in btc\n" + " \"amount\" : x.xxx, (numeric) The transaction amount in grc\n" ); uint256 hash; @@ -1639,6 +1686,8 @@ Value gettransaction(const Array& params, bool fHelp) filter = filter | MINE_WATCH_ONLY; Object entry; + LOCK2(cs_main, pwalletMain->cs_wallet); + if (pwalletMain->mapWallet.count(hash)) { const CWalletTx& wtx = pwalletMain->mapWallet[hash]; @@ -1697,7 +1746,9 @@ Value backupwallet(const Array& params, bool fHelp) throw runtime_error( "backupwallet\n" "\n" - "Backup your wallet and config files."); + "Backup your wallet and config files.\n"); + + LOCK2(cs_main, pwalletMain->cs_wallet); bool bWalletBackupResults = BackupWallet(*pwalletMain, GetBackupFilename("wallet.dat")); bool bConfigBackupResults = BackupConfigFile(GetBackupFilename("gridcoinresearch.conf")); @@ -1713,7 +1764,7 @@ Value keypoolrefill(const Array& params, bool fHelp) if (fHelp || params.size() > 1) throw runtime_error( "keypoolrefill [new-size]\n" - "Fills the keypool." + "Fills the keypool.\n" + HelpRequiringPassphrase()); unsigned int nSize = max(GetArg("-keypool", 100), (int64_t)0); @@ -1723,6 +1774,8 @@ Value keypoolrefill(const Array& params, bool fHelp) nSize = (unsigned int) params[0].get_int(); } + LOCK2(cs_main, pwalletMain->cs_wallet); + EnsureWalletIsUnlocked(); pwalletMain->TopUpKeyPool(nSize); @@ -1792,9 +1845,10 @@ Value walletpassphrase(const Array& params, bool fHelp) throw runtime_error( "walletpassphrase [stakingonly]\n" "Stores the wallet decryption key in memory for seconds.\n" - "if [stakingonly] is true sending functions are disabled."); + "if [stakingonly] is true sending functions are disabled.\n"); if (fHelp) return true; + if (!pwalletMain->IsCrypted()) throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrase was called."); @@ -1814,6 +1868,8 @@ Value walletpassphrase(const Array& params, bool fHelp) if (strWalletPass.length() > 0) { + LOCK2(cs_main, pwalletMain->cs_wallet); + if (!pwalletMain->Unlock(strWalletPass)) throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect."); } @@ -1841,9 +1897,10 @@ Value walletpassphrasechange(const Array& params, bool fHelp) if (pwalletMain->IsCrypted() && (fHelp || params.size() != 2)) throw runtime_error( "walletpassphrasechange \n" - "Changes the wallet passphrase from to ."); + "Changes the wallet passphrase from to .\n"); if (fHelp) return true; + if (!pwalletMain->IsCrypted()) throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrasechange was called."); @@ -1860,7 +1917,9 @@ Value walletpassphrasechange(const Array& params, bool fHelp) if (strOldWalletPass.length() < 1 || strNewWalletPass.length() < 1) throw runtime_error( "walletpassphrasechange \n" - "Changes the wallet passphrase from to ."); + "Changes the wallet passphrase from to \n."); + + LOCK2(cs_main, pwalletMain->cs_wallet); if (!pwalletMain->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect."); @@ -1876,12 +1935,15 @@ Value walletlock(const Array& params, bool fHelp) "walletlock\n" "Removes the wallet encryption key from memory, locking the wallet.\n" "After calling this method, you will need to call walletpassphrase again\n" - "before being able to call any methods which require the wallet to be unlocked."); + "before being able to call any methods which require the wallet to be unlocked.\n"); if (fHelp) return true; + if (!pwalletMain->IsCrypted()) throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called."); + LOCK2(cs_main, pwalletMain->cs_wallet); + { LOCK(cs_nWalletUnlockTime); pwalletMain->Lock(); @@ -1897,9 +1959,8 @@ Value encryptwallet(const Array& params, bool fHelp) if (!pwalletMain->IsCrypted() && (fHelp || params.size() != 1)) throw runtime_error( "encryptwallet \n" - "Encrypts the wallet with ."); - if (fHelp) - return true; + "Encrypts the wallet with .\n"); + if (pwalletMain->IsCrypted()) throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an encrypted wallet, but encryptwallet was called."); @@ -1912,7 +1973,9 @@ Value encryptwallet(const Array& params, bool fHelp) if (strWalletPass.length() < 1) throw runtime_error( "encryptwallet \n" - "Encrypts the wallet with ."); + "Encrypts the wallet with .\n"); + + LOCK2(cs_main, pwalletMain->cs_wallet); if (!pwalletMain->EncryptWallet(strWalletPass)) throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Failed to encrypt the wallet."); @@ -1965,7 +2028,9 @@ Value validateaddress(const Array& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "validateaddress \n" - "Return information about ."); + "Return information about .\n"); + + LOCK2(cs_main, pwalletMain->cs_wallet); CBitcoinAddress address(params[0].get_str()); bool isValid = address.IsValid(); @@ -1994,9 +2059,12 @@ Value validatepubkey(const Array& params, bool fHelp) if (fHelp || !params.size() || params.size() > 2) throw runtime_error( "validatepubkey \n" - "Return information about ."); + "Return information about .\n"); + + LOCK2(cs_main, pwalletMain->cs_wallet); std::vector vchPubKey = ParseHex(params[0].get_str()); + CPubKey pubKey(vchPubKey); bool isValid = pubKey.IsValid(); @@ -2152,7 +2220,8 @@ Value burn(const Array& params, bool fHelp) if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( "burn [hex string]\n" - " is a real and is rounded to the nearest 0.00000001" + "\n" + " is a real and is rounded to the nearest 0.00000001\n" + HelpRequiringPassphrase()); if (pwalletMain->IsLocked()) From ac5e077a5b7ed04180eb9f69f0472df6c61323c0 Mon Sep 17 00:00:00 2001 From: Paul Jensen Date: Thu, 15 Feb 2018 23:29:52 -0800 Subject: [PATCH 05/28] move some of the execute rpc calls into straight rpc calls. move execute burn to execute burn2. removed resendwallettx as it functions identically to resendtx rpc calls --- src/rpcblockchain.cpp | 1476 ++++++----------------------------------- 1 file changed, 185 insertions(+), 1291 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 84350f8852..c8cc9c53fe 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -424,7 +424,9 @@ Value settxfee(const Array& params, bool fHelp) if (fHelp || params.size() < 1 || params.size() > 1 || AmountFromValue(params[0]) < MIN_TX_FEE) throw runtime_error( "settxfee \n" - " is a real and is rounded to the nearest 0.01"); + " is a real and is rounded to the nearest 0.01\n"); + + LOCK2(cs_main, pwalletMain->cs_wallet); nTransactionFee = AmountFromValue(params[0]); nTransactionFee = (nTransactionFee / CENT) * CENT; // round to cent @@ -1076,1342 +1078,234 @@ Value backupprivatekeys(const Array& params, bool fHelp) string sErrors; string sTarget; - Object entry; + Object res; + bool bBackupPrivateKeys = BackupPrivateKeys(*pwalletMain, sTarget, sErrors); if (!bBackupPrivateKeys) - entry.push_back(Pair("error", sErrors)); + res.push_back(Pair("error", sErrors)); else - entry.push_back(Pair("location", sTarget)); + res.push_back(Pair("location", sTarget)); + + res.push_back(Pair("result", bBackupPrivateKeys)); - entry.push_back(Pair("result", bBackupPrivateKeys)); - return entry; + return res; } -Value execute(const Array& params, bool fHelp) +Value burn2(const Array& params, bool fHelp) { - if (fHelp || (params.size() != 1 && params.size() != 2 && params.size() != 3 && params.size() != 4 && params.size() != 5 && params.size() != 6 && params.size() != 7)) + if (fHelp || params.size() < 4) throw runtime_error( - "execute \n" - "Executes an arbitrary command by name.\n" - "execute help\n" - "Displays help on various available execute commands.\n"); - - std::string sItem = params[0].get_str(); - - if (sItem=="") throw runtime_error("Item invalid."); - - Array results; - Object oOut; - oOut.push_back(Pair("Command",sItem)); - results.push_back(oOut); - Object entry; + "burn2 \n" + "\n" + " Address where the coins will be burned\n" + " Amount of coins to be burned\n" + " Burn key to be used\n" + " Details of the burn\n"); + + Object res; + std::string sAddress = params[0].get_str(); + double dAmount = Round(params[1].get_real(), 6); + std::string sKey = params[2].get_str(); + std::string sDetail = params[3].get_str(); + CBitcoinAddress address(sAddress); + bool isValid = address.IsValid(); - if (sItem == "restorepoint") + if (!isValid) { - int r= Restarter::CreateGridcoinRestorePoint(); - //We must stop the node before we can do this - //RestartGridcoin(); - entry.push_back(Pair("Restore Point",r)); - results.push_back(entry); + res.push_back(Pair("Error","Invalid GRC Burn Address.")); + return res; } - else if (sItem == "restart") - { - LogPrintf("Restarting Gridcoin..."); - int iResult = Restarter::RestartGridcoin(); - entry.push_back(Pair("RebootClient", iResult)); - results.push_back(entry); - } - else if (sItem == "sendblock") + if (dAmount == 0 || dAmount < 0) { - if (params.size() != 2) - { - entry.push_back(Pair("Error","You must specify the block hash to send.")); - results.push_back(entry); - } - std::string sHash = params[1].get_str(); - uint256 hash = uint256(sHash); - bool fResult = AskForOutstandingBlocks(hash); - entry.push_back(Pair("Requesting",hash.ToString())); - entry.push_back(Pair("Result",fResult)); - results.push_back(entry); + res.push_back(Pair("Error","Burn amount must be > 0.")); + return res; } - else if (sItem=="burn") - { - if (params.size() < 5) - { - entry.push_back(Pair("Error","You must specify Burn Address, Amount, Burn_Key and Burn_Message")); - entry.push_back(Pair("execute burn ", "Burn coins for contract")); - entry.push_back(Pair("", "Address of the coins will be burned to")); - entry.push_back(Pair("", "Amount of coins to be burned")); - entry.push_back(Pair("", "Burn key to be used")); - entry.push_back(Pair("", "Details of the burn")); - results.push_back(entry); - } - else - { - std::string sAddress = params[1].get_str(); - std::string sAmount = params[2].get_str(); - std::string sKey = params[3].get_str(); - std::string sDetail = params[4].get_str(); - CBitcoinAddress address(sAddress); - bool isValid = address.IsValid(); - if (!isValid) - { - entry.push_back(Pair("Error","Invalid GRC Burn Address.")); - results.push_back(entry); - return results; - } - - double dAmount = RoundFromString(sAmount,6); - - if (dAmount == 0 || dAmount < 0) - { - entry.push_back(Pair("Error","Burn amount must be > 0.")); - results.push_back(entry); - return results; - } - - if (sKey.empty() || sDetail.empty()) - { - entry.push_back(Pair("Error","Burn Key and Burn Detail must be populated.")); - results.push_back(entry); - return results; - } - std::string sContract = "" + sKey + "" + sDetail + ""; - std::string sResult = BurnCoinsWithNewContract(true,"burn",sKey,sContract,AmountFromValue(1),dAmount,"",sAddress); - - //std::string BurnCoinsWithNewContract(bool bAdd, std::string sType, std::string sPrimaryKey, std::string sValue, int64_t MinimumBalance, double dFees, std::string strPublicKey, std::string sBurnAddress) - - entry.push_back(Pair("Burn_Response",sResult)); - results.push_back(entry); - } - } - else if (sItem == "newburnaddress") + if (sKey.empty() || sDetail.empty()) { - //3-12-2016 - R Halford - Allow the user to make vanity GRC Burn Addresses that have no corresponding private key - std::string sBurnTemplate = "GRCBurnAddressGRCBurnAddressGRCBurnAddress"; - if (params.size() > 1) - { - sBurnTemplate = params[1].get_str(); - } - // Address must start with the correct base58 network flag and address type for GRC - std::string sPrefix = (fTestNet) ? "mp" : "Rx"; - std::string t34 = sPrefix + sBurnTemplate + "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; - t34 = t34.substr(0,34); // Template must be 34 characters - std::vector vchDecoded34; - DecodeBase58(t34, vchDecoded34); - //Now we have the 34 digit address decoded from base58 to binary - std::string sDecoded34(vchDecoded34.begin(), vchDecoded34.end()); - //Now we have a binary string - Chop off all but last 4 bytes (save space for the checksum) - std::string sDecoded30 = sDecoded34.substr(0,sDecoded34.length()-4); - //Convert to Hex first - vector vchDecoded30(sDecoded30.begin(), sDecoded30.end()); - std::string sDecodedHex = ConvertBinToHex(sDecoded30); - // Get sha256 Checksum of DecodedHex - uint256 hash = Hash(vchDecoded30.begin(), vchDecoded30.end()); - // The BTC address spec calls for double SHA256 hashing - uint256 DoubleHash = Hash(hash.begin(),hash.end()); - std::string sSha256 = DoubleHash.GetHex(); - // Only use the first 8 hex bytes to retrieve the checksum - sSha256 = sSha256.substr(0,8); - // Combine the Hex Address prefix and the Sha256 Checksum to form the Hex version of the address (Note: There is no private key) - std::string combined = sDecodedHex + sSha256; - std::string sBinary = ConvertHexToBin(combined); - vector v(sBinary.begin(), sBinary.end()); - //Make the new address so that it passes base 58 Checks - std::string encoded1 = EncodeBase58(v); - entry.push_back(Pair("CombinedHex",combined)); - std::string encoded2 = EncodeBase58Check(vchDecoded30); - if (encoded2.length() != 34) - { - entry.push_back(Pair("Burn Address Creation failed","NOTE: the input phrase must not include zeroes, or nonbase58 characters.")); - results.push_back(entry); - return results; - } - // Give the user the new vanity burn address - entry.push_back(Pair("Burn Address",encoded2)); - results.push_back(entry); + res.push_back(Pair("Error","Burn Key and Burn Detail must be populated.")); + return res; } - else if (sItem=="proveownership") - { - HarvestCPIDs(true); - GetNextProject(true); - std::string email = GetArgument("email", "NA"); - boost::to_lower(email); - entry.push_back(Pair("Boinc E-Mail",email)); - entry.push_back(Pair("Boinc Public Key",GlobalCPUMiningCPID.boincruntimepublickey)); - entry.push_back(Pair("CPID",GlobalCPUMiningCPID.cpid)); - std::string sLongCPID = ComputeCPIDv2(email,GlobalCPUMiningCPID.boincruntimepublickey,1); - std::string sShortCPID = RetrieveMd5(GlobalCPUMiningCPID.boincruntimepublickey + email); - std::string sEmailMD5 = RetrieveMd5(email); - std::string sBPKMD5 = RetrieveMd5(GlobalCPUMiningCPID.boincruntimepublickey); - entry.push_back(Pair("Computed Email Hash",sEmailMD5)); - entry.push_back(Pair("Computed BPK",sBPKMD5)); - - entry.push_back(Pair("Computed CPID",sLongCPID)); - entry.push_back(Pair("Computed Short CPID", sShortCPID)); - bool fResult = CPID_IsCPIDValid(sShortCPID,sLongCPID,1); - if (GlobalCPUMiningCPID.boincruntimepublickey.empty()) - { - fResult=false; - entry.push_back(Pair("Error","Boinc Public Key empty. Try mounting your boinc project first, and ensure the gridcoin datadir setting is set if boinc is not in the default location.")); - } - entry.push_back(Pair("CPID Valid",fResult)); - results.push_back(entry); - } - else if (sItem=="beaconstatus") - { - // Search for beacon, and report on beacon status. - std::string sCPID = msPrimaryCPID; - if (params.size()==2) - { - sCPID = params[1].get_str(); - } - - entry.push_back(Pair("CPID", sCPID)); - std::string sPubKey = GetBeaconPublicKey(sCPID, false); - std::string sPrivKey = GetStoredBeaconPrivateKey(sCPID); - int64_t iBeaconTimestamp = BeaconTimeStamp(sCPID, false); - std::string timestamp = TimestampToHRDate(iBeaconTimestamp); + std::string sContract = "" + sKey + "" + sDetail + ""; - bool hasBeacon = HasActiveBeacon(sCPID); - entry.push_back(Pair("Beacon Exists",YesNo(hasBeacon))); - entry.push_back(Pair("Beacon Timestamp",timestamp.c_str())); + std::string sResult = BurnCoinsWithNewContract(true,"burn",sKey,sContract,AmountFromValue(1),dAmount,"",sAddress); - entry.push_back(Pair("Public Key", sPubKey.c_str())); - entry.push_back(Pair("Private Key", sPrivKey.c_str())); + res.push_back(Pair("Burn_Response",sResult)); - std::string sErr = ""; - if (sPubKey.empty()) - { - sErr += "Public Key Missing. "; - } - if (sPrivKey.empty()) - { - sErr += "Private Key Missing. "; - } - // Verify the users Local Public Key matches the Beacon Public Key - std::string sLocalPubKey = GetStoredBeaconPublicKey(sCPID); - entry.push_back(Pair("Local Configuration Public Key", sLocalPubKey.c_str())); - - if (sLocalPubKey.empty()) - { - sErr += "Local configuration file Public Key missing. "; - } - - if (sLocalPubKey != sPubKey && !sPubKey.empty()) - { - sErr += "Local configuration public key does not match beacon public key. This can happen if you copied the wrong public key into your configuration file. Please request that your beacon is deleted, or look into walletbackups for the correct keypair. "; - } + return res; +} - // Prior superblock Magnitude - double dMagnitude = GetMagnitudeByCpidFromLastSuperblock(sCPID); - entry.push_back(Pair("Magnitude (As of last superblock)", dMagnitude)); - if (dMagnitude==0) - { - entry.push_back(Pair("Warning","Your magnitude is 0 as of the last superblock: this may keep you from staking POR blocks.")); - } +Value encrypt(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "encrypt \n" + "\n" + " The password of your encrypted wallet\n"); - // Staking Test 10-15-2016 - Simulate signing an actual block to verify this CPID keypair will work. - uint256 hashBlock = GetRandHash(); - if (!sPubKey.empty()) - { - bool bResult; - std::string sSignature; - std::string sError; - bResult = SignBlockWithCPID(sCPID, hashBlock.GetHex(), sSignature, sError); - if (!bResult) - { - sErr += "Failed to sign block with cpid "; - sErr += sError; - sErr += ";"; - } - bool fResult = VerifyCPIDSignature(sCPID, hashBlock.GetHex(), sSignature); - entry.push_back(Pair("Block Signing Test Results", fResult)); - if (!fResult) - { - sErr += "Failed to sign POR block. This can happen if your keypair is invalid. Check walletbackups for the correct keypair, or request that your beacon is deleted. "; - } - } + Object res; + //Encrypt a phrase + std::string sParam = params[0].get_str(); + std::string encrypted = AdvancedCryptWithHWID(sParam); + res.push_back(Pair("Passphrase",encrypted)); + res.push_back(Pair("[Specify in config file] autounlock=",encrypted)); + return res; +} - if (!sErr.empty()) - { - entry.push_back(Pair("Errors", sErr)); - entry.push_back(Pair("Help", "Note: If your beacon is missing its public key, or is not in the chain, you may try: execute advertisebeacon.")); - entry.push_back(Pair("Configuration Status","FAIL")); - } - else - { - entry.push_back(Pair("Configuration Status", "SUCCESSFUL")); - } - results.push_back(entry); +Value newburnaddress(const Array& params, bool fHelp) +{ + if (fHelp || params.size() > 1) + throw runtime_error( + "newburnaddress [burntemplate]\n" + "\n" + "[burntemplate] Allow a vanity burn address\n"); + + Object res; + + //3-12-2016 - R Halford - Allow the user to make vanity GRC Burn Addresses that have no corresponding private key + std::string sBurnTemplate = "GRCBurnAddressGRCBurnAddressGRCBurnAddress"; + if (params.size() > 0) + { + sBurnTemplate = params[0].get_str(); + } + // Address must start with the correct base58 network flag and address type for GRC + std::string sPrefix = (fTestNet) ? "mp" : "Rx"; + std::string t34 = sPrefix + sBurnTemplate + "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + t34 = t34.substr(0,34); // Template must be 34 characters + std::vector vchDecoded34; + DecodeBase58(t34, vchDecoded34); + //Now we have the 34 digit address decoded from base58 to binary + std::string sDecoded34(vchDecoded34.begin(), vchDecoded34.end()); + //Now we have a binary string - Chop off all but last 4 bytes (save space for the checksum) + std::string sDecoded30 = sDecoded34.substr(0,sDecoded34.length()-4); + //Convert to Hex first + vector vchDecoded30(sDecoded30.begin(), sDecoded30.end()); + std::string sDecodedHex = ConvertBinToHex(sDecoded30); + // Get sha256 Checksum of DecodedHex + uint256 hash = Hash(vchDecoded30.begin(), vchDecoded30.end()); + // The BTC address spec calls for double SHA256 hashing + uint256 DoubleHash = Hash(hash.begin(),hash.end()); + std::string sSha256 = DoubleHash.GetHex(); + // Only use the first 8 hex bytes to retrieve the checksum + sSha256 = sSha256.substr(0,8); + // Combine the Hex Address prefix and the Sha256 Checksum to form the Hex version of the address (Note: There is no private key) + std::string combined = sDecodedHex + sSha256; + std::string sBinary = ConvertHexToBin(combined); + vector v(sBinary.begin(), sBinary.end()); + //Make the new address so that it passes base 58 Checks + std::string encoded1 = EncodeBase58(v); + res.push_back(Pair("CombinedHex",combined)); + std::string encoded2 = EncodeBase58Check(vchDecoded30); + if (encoded2.length() != 34) + { + res.push_back(Pair("Burn Address Creation failed","NOTE: the input phrase must not include zeroes, or nonbase58 characters.")); + return res; + } + // Give the user the new vanity burn address + res.push_back(Pair("Burn Address",encoded2)); + return res; +} + +Value rain(const json_spirit::Array& params, bool fHelp) +{ + if (fHelp || params.size() < 1 || params.size() > 1) + throw runtime_error( + "rain AddressAmount...\n" + "\n"); - } - else if (sItem=="rain") - { - if (params.size() < 2) - { - entry.push_back(Pair("Error","You must specify Rain Recipients in format: AddressAmount...")); - results.push_back(entry); - } - else - { - CWalletTx wtx; - wtx.mapValue["comment"] = "Rain"; - set setAddress; - vector > vecSend; - std::string sRecipients = params[1].get_str(); - std::string sRainCommand = ExtractXML(sRecipients,"",""); - std::string sRainMessage = MakeSafeMessage(ExtractXML(sRecipients,"","")); - std::string sRain = "Project Rain: " + sRainMessage + ""; - if (!sRainCommand.empty()) sRecipients = sRainCommand; - wtx.hashBoinc = sRain; - int64_t totalAmount = 0; - double dTotalToSend = 0; - std::vector vRecipients = split(sRecipients.c_str(),""); - LogPrintf("Creating Rain transaction with %f recipients. ",(double)vRecipients.size()); - for (unsigned int i = 0; i < vRecipients.size(); i++) - { - std::string sRow = vRecipients[i]; - std::vector vReward = split(sRow.c_str(),""); - if (vReward.size() > 1) - { - std::string sAddress = vReward[0]; - std::string sAmount = vReward[1]; - if (sAddress.length() > 10 && sAmount.length() > 0) - { - double dAmount = RoundFromString(sAmount,4); - if (dAmount > 0) - { - CBitcoinAddress address(sAddress); - if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Gridcoin address: ")+sAddress); - if (setAddress.count(address)) - throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+sAddress); - setAddress.insert(address); - dTotalToSend += dAmount; - int64_t nAmount = AmountFromDouble(dAmount); - CScript scriptPubKey; - scriptPubKey.SetDestination(address.Get()); - totalAmount += nAmount; - vecSend.push_back(make_pair(scriptPubKey, nAmount)); - } - } - } - } + Object res; - EnsureWalletIsUnlocked(); - // Check funds - double dBalance = GetTotalBalance(); - if (dTotalToSend > dBalance) - throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); - // Send - CReserveKey keyChange(pwalletMain); - int64_t nFeeRequired = 0; - bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired); - LogPrintf("Transaction Created."); - if (!fCreated) - { - if (totalAmount + nFeeRequired > pwalletMain->GetBalance()) - throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds"); - throw JSONRPCError(RPC_WALLET_ERROR, "Transaction creation failed"); - } - LogPrintf("Committing."); - // Rain the recipients - if (!pwalletMain->CommitTransaction(wtx, keyChange)) + CWalletTx wtx; + wtx.mapValue["comment"] = "Rain"; + set setAddress; + vector > vecSend; + std::string sRecipients = params[0].get_str(); + std::string sRainCommand = ExtractXML(sRecipients,"",""); + std::string sRainMessage = MakeSafeMessage(ExtractXML(sRecipients,"","")); + std::string sRain = "Project Rain: " + sRainMessage + ""; + if (!sRainCommand.empty()) sRecipients = sRainCommand; + wtx.hashBoinc = sRain; + int64_t totalAmount = 0; + double dTotalToSend = 0; + std::vector vRecipients = split(sRecipients.c_str(),""); + printf("Creating Rain transaction with %f recipients. ",(double)vRecipients.size()); + for (unsigned int i = 0; i < vRecipients.size(); i++) + { + std::string sRow = vRecipients[i]; + std::vector vReward = split(sRow.c_str(),""); + if (vReward.size() > 1) + { + std::string sAddress = vReward[0]; + std::string sAmount = vReward[1]; + if (sAddress.length() > 10 && sAmount.length() > 0) { - LogPrintf("Commit failed."); - throw JSONRPCError(RPC_WALLET_ERROR, "Transaction commit failed"); - } - std::string sNarr = "Rain successful: Sent " + wtx.GetHash().GetHex() + "."; - LogPrintf("Success %s",sNarr); - entry.push_back(Pair("Response", sNarr)); - results.push_back(entry); - } - } - else if (sItem == "neuralrequest") - { - - std::string response = NeuralRequest("REQUEST"); - entry.push_back(Pair("Response", response)); - results.push_back(entry); - - } - else if (sItem == "advertisebeacon") - { - std::string sOutPubKey = ""; - std::string sOutPrivKey = ""; - std::string sError = ""; - std::string sMessage = ""; - - bool fResult = AdvertiseBeacon(sOutPrivKey,sOutPubKey,sError,sMessage); - entry.push_back(Pair("Result",SuccessFail(fResult))); - entry.push_back(Pair("CPID",GlobalCPUMiningCPID.cpid.c_str())); - entry.push_back(Pair("Message",sMessage.c_str())); - - if (!sError.empty()) entry.push_back(Pair("Errors",sError)); - - if (!fResult) - { - entry.push_back(Pair("FAILURE","Note: if your wallet is locked this command will fail; to solve that unlock the wallet: 'walletpassphrase <240>'.")); - } - if (fResult) - { - entry.push_back(Pair("Public Key",sOutPubKey.c_str())); - entry.push_back(Pair("Warning!","Your public and private research keys have been stored in gridcoinresearch.conf. Do not lose your private key (It is non-recoverable). It is recommended that you back up your gridcoinresearch.conf file on a regular basis.")); - } - results.push_back(entry); - - } - else if (sItem == "syncdpor2") - { - std::string sOut = ""; - bool bFull = GetCountOf("beacon") < 50 ? true : false; - LoadAdminMessages(bFull,sOut); - FullSyncWithDPORNodes(); - entry.push_back(Pair("Syncing",1)); - results.push_back(entry); - } - else if(sItem=="gatherneuralhashes") - { - GatherNeuralHashes(); - entry.push_back(Pair("Sent",".")); - results.push_back(entry); - - } - else if (sItem == "beaconreport") - { - Array myBeaconJSONReport = GetJSONBeaconReport(); - results.push_back(myBeaconJSONReport); - } - else if (sItem == "unspentreport") - { - Array aUnspentReport = GetJsonUnspentReport(); - results.push_back(aUnspentReport); - } - else if (sItem == "upgradedbeaconreport") - { - Array aUpgBR = GetUpgradedBeaconReport(); - results.push_back(aUpgBR); - } - else if (sItem == "neuralreport") - { - Array myNeuralJSON = GetJSONNeuralNetworkReport(); - results.push_back(myNeuralJSON); - } - else if (sItem == "currentneuralreport") - { - Array myNeuralJSON = GetJSONCurrentNeuralNetworkReport(); - results.push_back(myNeuralJSON); - } - else if (sItem == "tallyneural") - { - ComputeNeuralNetworkSupermajorityHashes(); - UpdateNeuralNetworkQuorumData(); - entry.push_back(Pair("Ready",".")); - results.push_back(entry); - } - else if (sItem == "versionreport") - { - Array myNeuralJSON = GetJSONVersionReport(); - results.push_back(myNeuralJSON); - } - else if (sItem=="myneuralhash") - { - std::string myNeuralHash = NN::GetNeuralHash(); - entry.push_back(Pair("My Neural Hash",myNeuralHash.c_str())); - results.push_back(entry); - } - else if (sItem == "superblockinfo") - { - std::string sSbHeight = ReadCache("superblock", "block_number").value; - int nSbHeight; - - try - { - nSbHeight = std::stoi(sSbHeight); - } - catch (const std::exception &ex) - { - entry.push_back(Pair("ERROR", "std::exception occured ->" + std::string(ex.what()))); - results.push_back(entry); - - return results; - } - - CBlockIndex* pblockindex = RPCBlockFinder.FindByHeight(nSbHeight); - - if (pblockindex == NULL) - entry.push_back(Pair("ERROR", "Could not find superblock in blockindex")); - - else - { - CBlock block; - - block.ReadFromDisk(pblockindex); - - MiningCPID sbi = DeserializeBoincBlock(block.vtx[0].hashBoinc, block.nVersion); - - entry.push_back(Pair("age", GetAdjustedTime() - pblockindex->GetBlockTime())); - entry.push_back(Pair("time", pblockindex->GetBlockTime())); - entry.push_back(Pair("height", nSbHeight)); - entry.push_back(Pair("hash", pblockindex->GetBlockHash().ToString())); - entry.push_back(Pair("neural_hash", sbi.NeuralHash)); - entry.push_back(Pair("CPID", sbi.cpid)); - entry.push_back(Pair("client_version", sbi.clientversion)); - } - results.push_back(entry); - } - else if (sItem == "unusual") - { - - UnusualActivityReport(); - entry.push_back(Pair("UAR",1)); - results.push_back(entry); - - - } - else if (sItem == "neuralhash") - { - double popularity = 0; - std::string consensus_hash = GetNeuralNetworkSupermajorityHash(popularity); - entry.push_back(Pair("Popular",consensus_hash)); - results.push_back(entry); - } - else if (sItem == "currentneuralhash") - { - double popularity = 0; - std::string consensus_hash = GetCurrentNeuralNetworkSupermajorityHash(popularity); - entry.push_back(Pair("Popular",consensus_hash)); - results.push_back(entry); - } - else if (sItem=="updatequorumdata") - { - UpdateNeuralNetworkQuorumData(); - entry.push_back(Pair("Updated.","")); - results.push_back(entry); - } - else if (sItem == "askforoutstandingblocks") - { - bool fResult = AskForOutstandingBlocks(uint256(0)); - entry.push_back(Pair("Sent.",fResult)); - results.push_back(entry); - } - else if (sItem == "readconfig") - { - ReadConfigFile(mapArgs, mapMultiArgs); - - } - else if (sItem == "writedata") - { - if (params.size() != 3) - { - entry.push_back(Pair("Error","You must specify the Key and Value. For example execute writedata dog_color black.")); - results.push_back(entry); - } - else - { - std::string sKey = params[1].get_str(); - std::string sValue = params[2].get_str(); - //CTxDB txdb("rw"); - CTxDB txdb; - txdb.TxnBegin(); - std::string result = "Success."; - if (!txdb.WriteGenericData(sKey,sValue)) result = "Unable to write."; - if (!txdb.TxnCommit()) result = "Unable to Commit."; - entry.push_back(Pair("Result",result)); - results.push_back(entry); - } - - } - else if (sItem == "readdata") - { - if (params.size() != 2) - { - entry.push_back(Pair("Error","You must specify the Key. For example execute readdata dog_color.")); - results.push_back(entry); - } - else - { - std::string sKey = params[1].get_str(); - std::string sValue = "?"; - //CTxDB txdb("cr"); - CTxDB txdb; - if (!txdb.ReadGenericData(sKey,sValue)) - { - entry.push_back(Pair("Error",sValue)); - - sValue = "Failed to read from disk."; - } - entry.push_back(Pair("Key",sKey)); - - entry.push_back(Pair("Result",sValue)); - results.push_back(entry); - } - - } - else if (sItem == "refhash") - { - if (params.size() != 2) - { - entry.push_back(Pair("Error","You must specify the Reference Hash.")); - results.push_back(entry); - } - else - { - std::string rh = params[1].get_str(); - bool r1 = StrLessThanReferenceHash(rh); - bool r2 = IsNeuralNodeParticipant(DefaultWalletAddress(), GetAdjustedTime()); - entry.push_back(Pair("nVersion); - std::string GRCAddress = DefaultWalletAddress(); - StructCPID structMag = GetInitializedStructCPID2(GlobalCPUMiningCPID.cpid,mvMagnitudes); - double dmag = structMag.Magnitude; - double poll_duration = PollDuration(Title)*86400; - - // Prevent Double Voting - std::string cpid1 = GlobalCPUMiningCPID.cpid; - std::string GRCAddress1 = DefaultWalletAddress(); - GetEarliestStakeTime(GRCAddress1,cpid1); - double cpid_age = GetAdjustedTime() - ReadCache("global", "nCPIDTime").timestamp; - double stake_age = GetAdjustedTime() - ReadCache("global", "nGRCTime").timestamp; - - StructCPID structGRC = GetInitializedStructCPID2(GRCAddress,mvMagnitudes); - - - LogPrintf("CPIDAge %f,StakeAge %f,Poll Duration %f \n",cpid_age,stake_age,poll_duration); - - double dShareType= RoundFromString(GetPollXMLElementByPollTitle(Title,"",""),0); - - // Share Type 1 == "Magnitude" - // Share Type 2 == "Balance" - // Share Type 3 == "Both" - if (cpid_age < poll_duration) dmag = 0; - if (stake_age < poll_duration) nBalance = 0; - - if ((dShareType == 1) && cpid_age < poll_duration) - { - entry.push_back(Pair("Error","Sorry, When voting in a magnitude poll, your CPID must be older than the poll duration.")); - results.push_back(entry); - } - else if (dShareType == 2 && stake_age < poll_duration) - { - entry.push_back(Pair("Error","Sorry, When voting in a Balance poll, your stake age must be older than the poll duration.")); - results.push_back(entry); - } - else if (dShareType == 3 && stake_age < poll_duration && cpid_age < poll_duration) - { - entry.push_back(Pair("Error","Sorry, When voting in a Both Share Type poll, your stake age Or your CPID age must be older than the poll duration.")); - results.push_back(entry); - } - else - { - std::string voter = ""+GlobalCPUMiningCPID.cpidv2 + "" - + GlobalCPUMiningCPID.cpid + "" + GRCAddress + "" - + hashRand.GetHex() + "" + RoundToString(nBalance,2) - + "" + RoundToString(dmag,0) + ""; - // Add the provable balance and the provable magnitude - this goes into effect July 1 2017 - voter += GetProvableVotingWeightXML(); - std::string pk = Title + ";" + GRCAddress + ";" + GlobalCPUMiningCPID.cpid; - std::string contract = "" + Title + "" + Answer + "" + voter; - std::string result = AddContract("vote",pk,contract); - std::string narr = "Your CPID weight is " + RoundToString(dmag,0) + " and your Balance weight is " + RoundToString(nBalance,0) + "."; - entry.push_back(Pair("Success",narr + " " + "Your vote has been cast for topic " + Title + ": With an Answer of " + Answer + ": " + result.c_str())); - results.push_back(entry); - } - } - } - } - - } - } - - } - else if (sItem == "addpoll") - { - if (params.size() != 7) - { - entry.push_back(Pair("Error","You must specify the Poll Title, Expiration In DAYS from Now, Question, Answers delimited by a semicolon, ShareType (1=Magnitude,2=Balance,3=Both,4=CPIDCount,5=ParticipantCount) and discussion URL (use TinyURL.com to make a small URL). Please use underscores in place of spaces inside a sentence. ")); - entry.push_back(Pair("execute addpoll <days> <question> <answers> <sharetype> <url>", "Add a poll (Requires minimum 100000 GRC balance)")); - entry.push_back(Pair("<title>", "Title for poll with no spaces. Use _ in between words")); - entry.push_back(Pair("<days>", "Number of days the poll will run")); - entry.push_back(Pair("<question>", "The poll question in which you seek input for")); - entry.push_back(Pair("<answers>", "The available answers to which a voter can vote separated by a semicolon")); - entry.push_back(Pair("<sharetype>", "1 = Magnitude 2 = Balance 3 = Magnitude + Balance 4 = CPID count 5 = Participant count")); - entry.push_back(Pair("<url>", "Short url for information about the poll")); - results.push_back(entry); - } - else - { - std::string Title = params[1].get_str(); - std::string Days = params[2].get_str(); - double days = RoundFromString(Days,0); - std::string Question = params[3].get_str(); - std::string Answers = params[4].get_str(); - std::string ShareType = params[5].get_str(); - std::string sURL = params[6].get_str(); - double sharetype = RoundFromString(ShareType,0); - if (Title=="" || Question == "" || Answers == "") - { - entry.push_back(Pair("Error","You must specify a Poll Title, Poll Question and Poll Answers.")); - results.push_back(entry); - } - else + double dAmount = RoundFromString(sAmount,4); + if (dAmount > 0) { - if (days < 7) - { - entry.push_back(Pair("Error","Minimum duration is 7 days; please specify a longer poll duration.")); - results.push_back(entry); + CBitcoinAddress address(sAddress); + if (!address.IsValid()) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Gridcoin address: ")+sAddress); + if (setAddress.count(address)) + throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+sAddress); + setAddress.insert(address); + dTotalToSend += dAmount; + int64_t nAmount = AmountFromDouble(dAmount); + CScript scriptPubKey; + scriptPubKey.SetDestination(address.Get()); + totalAmount += nAmount; + vecSend.push_back(make_pair(scriptPubKey, nAmount)); } - else - { - double nBalance = GetTotalBalance(); - - if (nBalance < 100000) - { - entry.push_back(Pair("Error","You must have a balance > 100,000 GRC to create a poll. Please post the desired poll on https://cryptocurrencytalk.com/forum/464-gridcoin-grc/ or https://github.com/Erkan-Yilmaz/Gridcoin-tasks/issues/45")); - results.push_back(entry); - } - else - { - if (days < 0 || days == 0) - { - entry.push_back(Pair("Error","You must specify a positive value for days for the expiration date.")); - results.push_back(entry); - - } - else - { - if (sharetype != 1 && sharetype != 2 && sharetype != 3 && sharetype !=4 && sharetype !=5) - { - entry.push_back(Pair("Error","You must specify a value of 1, 2, 3, 4 or 5 for the sharetype.")); - results.push_back(entry); - - } - else - { - std::string expiration = RoundToString(GetAdjustedTime() + (days*86400),0); - std::string contract = "<TITLE>" + Title + "" + RoundToString(days,0) + "" + Question + "" + Answers + "" + RoundToString(sharetype,0) + "" + sURL + "" + expiration + ""; - std::string result = AddContract("poll",Title,contract); - entry.push_back(Pair("Success","Your poll has been added: " + result)); - results.push_back(entry); - } - - } - } - } } } - } - else if (sItem == "votedetails") - { - if (params.size() != 2) - { - entry.push_back(Pair("Error","You must specify the Poll Title.")); - results.push_back(entry); - } - else - { - std::string Title1 = params[1].get_str(); - - if (!PollExists(Title1)) - { - entry.push_back(Pair("Error","Poll does not exist. Please execute listpolls.")); - results.push_back(entry); - } - else - { - std::string Title = params[1].get_str(); - Array myVotes = GetJsonVoteDetailsReport(Title); - results.push_back(myVotes); - } - } - } - else if (sItem == "listpolls") + EnsureWalletIsUnlocked(); + // Check funds + double dBalance = GetTotalBalance(); + if (dTotalToSend > dBalance) + throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); + // Send + CReserveKey keyChange(pwalletMain); + int64_t nFeeRequired = 0; + bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired); + printf("Transaction Created."); + if (!fCreated) { - std::string out1; - Array myPolls = GetJSONPollsReport(false,"",out1,false); - results.push_back(myPolls); + if (totalAmount + nFeeRequired > pwalletMain->GetBalance()) + throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds"); + throw JSONRPCError(RPC_WALLET_ERROR, "Transaction creation failed"); } - else if (sItem == "listallpolls") + printf("Committing."); + // Rain the recipients + if (!pwalletMain->CommitTransaction(wtx, keyChange)) { - std::string out1; - Array myPolls = GetJSONPollsReport(false,"",out1,true); - results.push_back(myPolls); - } - else if (sItem == "listallpolldetails") - { - std::string out1; - Array myPolls = GetJSONPollsReport(true,"",out1,true); - results.push_back(myPolls); - + printf("Commit failed."); + throw JSONRPCError(RPC_WALLET_ERROR, "Transaction commit failed"); } - else if (sItem=="listpolldetails") - { - std::string out1; - Array myPolls = GetJSONPollsReport(true,"",out1,false); - results.push_back(myPolls); - } - else if (sItem=="listpollresults") - { - bool bIncExpired = false; - if (params.size() == 3) - { - std::string include_expired = params[2].get_str(); - if (include_expired=="true") bIncExpired=true; - } - - if (params.size() != 2 && params.size() != 3) - { - entry.push_back(Pair("Error","You must specify the Poll Title. Example: listpollresults pollname. You may also specify execute listpollresults pollname true if you want to see expired polls.")); - results.push_back(entry); - } - else - { - std::string Title1 = params[1].get_str(); - - if (!PollExists(Title1)) - { - entry.push_back(Pair("Error","Poll does not exist. Please execute listpolls.")); - results.push_back(entry); - - } - else - { - std::string Title = params[1].get_str(); - std::string out1 = ""; - Array myPolls = GetJSONPollsReport(true,Title,out1,bIncExpired); - results.push_back(myPolls); - } - } - } - else if (sItem=="staketime") - { - std::string cpid = GlobalCPUMiningCPID.cpid; - std::string GRCAddress = DefaultWalletAddress(); - GetEarliestStakeTime(GRCAddress,cpid); - entry.push_back(Pair("GRCTime", ReadCache("global", "nGRCTime").timestamp)); - entry.push_back(Pair("CPIDTime",ReadCache("global", "nCPIDTime").timestamp)); - results.push_back(entry); - } - else if (sItem=="testnewcontract") - { - std::string contract = NN::GetNeuralContract(); - std::string myNeuralHash = NN::GetNeuralHash(); - entry.push_back(Pair("My Neural Hash",myNeuralHash.c_str())); - results.push_back(entry); - - entry.push_back(Pair("Contract Test",contract)); - // Convert to Binary - std::string sBin = PackBinarySuperblock(contract); - entry.push_back(Pair("Contract Length",(int)contract.length())); - entry.push_back(Pair("Binary Length",(int)sBin.length())); - //entry.push_back(Pair("Binary",sBin.c_str())); - // Hash of current superblock - std::string sUnpacked = UnpackBinarySuperblock(sBin); - entry.push_back(Pair("Unpacked length",(int)sUnpacked.length())); - - entry.push_back(Pair("Unpacked",sUnpacked.c_str())); - std::string neural_hash = GetQuorumHash(contract); - std::string binary_neural_hash = GetQuorumHash(sUnpacked); - - entry.push_back(Pair("Local Core Quorum Hash",neural_hash)); - entry.push_back(Pair("Binary Local Core Quorum Hash",binary_neural_hash)); - - entry.push_back(Pair("Neural Network Live Quorum Hash",myNeuralHash)); - results.push_back(entry); - } - else if (sItem == "forcequorum") - { - AsyncNeuralRequest("quorum","gridcoin",10); - entry.push_back(Pair("Requested a quorum - waiting for resolution.",1)); - results.push_back(entry); - } - else if (sItem == "tally") - { - bNetAveragesLoaded_retired = false; - CBlockIndex* tallyIndex = FindTallyTrigger(pindexBest); - TallyResearchAverages_v9(tallyIndex); - entry.push_back(Pair("Tally Network Averages",1)); - results.push_back(entry); - } - else if (sItem == "encrypt") - { - //Encrypt a phrase - if (params.size() != 2) - { - entry.push_back(Pair("Error","You must also specify a wallet passphrase.")); - results.push_back(entry); - } - else - { - std::string sParam = params[1].get_str(); - std::string encrypted = AdvancedCryptWithHWID(sParam); - entry.push_back(Pair("Passphrase",encrypted)); - entry.push_back(Pair("[Specify in config file] autounlock=",encrypted)); - results.push_back(entry); - } - - } - else if (sItem == "genboinckey") - { - //Gridcoin - R Halford - Generate Boinc Mining Key - 2-6-2015 - GetNextProject(false); - std::string email = GetArgument("email", "NA"); - boost::to_lower(email); - GlobalCPUMiningCPID.email=email; - GlobalCPUMiningCPID.cpidv2 = ComputeCPIDv2(GlobalCPUMiningCPID.email, GlobalCPUMiningCPID.boincruntimepublickey, 0); - //Store the BPK in the aesskein, and the cpid in version - GlobalCPUMiningCPID.aesskein = email; //Good - GlobalCPUMiningCPID.lastblockhash = GlobalCPUMiningCPID.cpidhash; - - //block version not needed for keys for now - std::string sParam = SerializeBoincBlock(GlobalCPUMiningCPID,7); - if (fDebug3) LogPrintf("GenBoincKey: Utilizing email %s with %s for %s \n",GlobalCPUMiningCPID.email, GlobalCPUMiningCPID.boincruntimepublickey, sParam); - std::string sBase = EncodeBase64(sParam); - entry.push_back(Pair("[Specify in config file without quotes] boinckey=",sBase)); - results.push_back(entry); - } - else if (sItem == "encryptphrase") - { - if (params.size() != 2) - { - entry.push_back(Pair("Error","You must specify a phrase")); - results.push_back(entry); - } - else - { - std::string sParam1 = params[1].get_str(); - entry.push_back(Pair("Param1",sParam1)); - std::string test = AdvancedCrypt(sParam1); - entry.push_back(Pair("EncPhrase",test)); - results.push_back(entry); - - } - - } - - else if (sItem == "decryptphrase") - { - if (params.size() != 2) - { - entry.push_back(Pair("Error","You must specify a phrase")); - results.push_back(entry); - } - else - { - std::string sParam1 = params[1].get_str(); - entry.push_back(Pair("Param1",sParam1)); - std::string test = AdvancedDecrypt(sParam1); - entry.push_back(Pair("DecPhrase",test)); - results.push_back(entry); - - } - - } - else if (sItem == "dportally") - { - TallyMagnitudesInSuperblock(); - entry.push_back(Pair("Done","Done")); - results.push_back(entry); - - } - else if (sItem == "addkey") - { - //To whitelist a project: - //execute addkey add project projectname 1 - //To blacklist a project: - //execute addkey delete project projectname 1 - //Key examples: - - //execute addkey add project milky 1 - //execute addkey delete project milky 1 - //execute addkey add project milky 2 - //execute addkey add price grc .0000046 - //execute addkey add price grc .0000045 - //execute addkey delete price grc .0000045 - //GRC will only memorize the *last* value it finds for a key in the highest block - - //execute memorizekeys - //execute listdata project - //execute listdata price - - if (params.size() != 5) - { - entry.push_back(Pair("Error","You must specify an action, message type, message name and value.")); - entry.push_back(Pair("Example","execute addkey add_or_delete keytype projectname value.")); - results.push_back(entry); - } - else - { - //execute addkey add project grid20 - std::string sAction = params[1].get_str(); - entry.push_back(Pair("Action",sAction)); - bool bAdd = (sAction=="add") ? true : false; - std::string sType = params[2].get_str(); - entry.push_back(Pair("Type",sType)); - std::string sPass = ""; - sPass = (sType=="project" || sType=="projectmapping") ? GetArgument("masterprojectkey", msMasterMessagePrivateKey) : msMasterMessagePrivateKey; - if (sType=="beacon" && sAction=="delete") sPass = GetArgument("masterprojectkey",""); - entry.push_back(Pair("Passphrase",sPass)); - std::string sName = params[3].get_str(); - entry.push_back(Pair("Name",sName)); - std::string sValue = params[4].get_str(); - entry.push_back(Pair("Value",sValue)); - std::string result = AddMessage(bAdd,sType,sName,sValue,sPass,AmountFromValue(5),.1,""); - entry.push_back(Pair("Results",result)); - results.push_back(entry); - } - } - else if (sItem == "sendrawcontract") - { - if (params.size() != 2) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "You must specify raw contract."); - if (pwalletMain->IsLocked()) - throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); - std::string sAddress = GetBurnAddress(); - CBitcoinAddress address(sAddress); - if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Gridcoin address"); - std::string sContract = params[1].get_str(); - entry.push_back(Pair("Contract",sContract)); - entry.push_back(Pair("Recipient",sAddress)); - int64_t nAmount = CENT; - // Wallet comments - CWalletTx wtx; - wtx.hashBoinc = sContract; - string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx, false); - if (!strError.empty()) - throw JSONRPCError(RPC_WALLET_ERROR, strError); - entry.push_back(Pair("TrxID",wtx.GetHash().GetHex())); - results.push_back(entry); - } - else if (sItem == "memorizekeys") - { - std::string sOut = ""; - LoadAdminMessages(true,sOut); - entry.push_back(Pair("Results",sOut)); - results.push_back(entry); - - } - else if (sItem == "superblockaverage") - { - std::string superblock = ReadCache("superblock","all").value; - double out_beacon_count = 0; - double out_participant_count = 0; - double out_avg = 0; - double avg = GetSuperblockAvgMag(superblock,out_beacon_count,out_participant_count,out_avg,false,nBestHeight); - entry.push_back(Pair("avg",avg)); - entry.push_back(Pair("beacon_count",out_beacon_count)); - entry.push_back(Pair("beacon_participant_count",out_participant_count)); - entry.push_back(Pair("average_magnitude",out_avg)); - entry.push_back(Pair("superblock_valid", VerifySuperblock(superblock, pindexBest))); - int64_t superblock_age = GetAdjustedTime() - ReadCache("superblock", "magnitudes").timestamp; - entry.push_back(Pair("Superblock Age",superblock_age)); - bool bDireNeed = NeedASuperblock(); - entry.push_back(Pair("Dire Need of Superblock",bDireNeed)); - results.push_back(entry); - } - else if (sItem == "currentcontractaverage") - { - std::string contract = NN::GetNeuralContract(); - entry.push_back(Pair("Contract",contract)); - double out_beacon_count = 0; - double out_participant_count = 0; - double out_avg = 0; - double avg = GetSuperblockAvgMag(contract,out_beacon_count,out_participant_count,out_avg,false,nBestHeight); - bool bValid = VerifySuperblock(contract, pindexBest); - entry.push_back(Pair("avg",avg)); - entry.push_back(Pair("beacon_count",out_beacon_count)); - entry.push_back(Pair("avg_mag",out_avg)); - entry.push_back(Pair("beacon_participant_count",out_participant_count)); - entry.push_back(Pair("superblock_valid",bValid)); - //Show current contract neural hash - std::string sNeuralHash = NN::GetNeuralHash(); - entry.push_back(Pair(".NET Neural Hash",sNeuralHash.c_str())); - entry.push_back(Pair("Length",(double)contract.length())); - std::string neural_hash = GetQuorumHash(contract); - entry.push_back(Pair("Wallet Neural Hash",neural_hash)); - - results.push_back(entry); - - } - else if (sItem == "getlistof") - { - if (params.size() != 2) - { - entry.push_back(Pair("Error","You must specify a keytype.")); - results.push_back(entry); - } - else - { - std::string sType = params[1].get_str(); - entry.push_back(Pair("Key Type",sType)); - entry.push_back(Pair("Data", GetListOf(sType))); - results.push_back(entry); - } + std::string sNarr = "Rain successful: Sent " + wtx.GetHash().GetHex() + "."; + printf("Success %s",sNarr.c_str()); + res.push_back(Pair("Response", sNarr)); + return res; +} - } - else if (sItem == "listdata") - { - if (params.size() != 2) - { - entry.push_back(Pair("Error","You must specify a keytype (IE execute dumpkeys project)")); - results.push_back(entry); - } - else - { - std::string sType = params[1].get_str(); - entry.push_back(Pair("Key Type",sType)); - for(const auto& item : ReadCacheSection(sType)) - entry.push_back(Pair(item.first, item.second.value)); +Value unspentreport(const json_spirit::Array& params, bool fHelp) +{ + if (fHelp || params.size() > 0) + throw runtime_error( + "unspentreport\n"); - results.push_back(entry); - } + LOCK2(cs_main, pwalletMain->cs_wallet); - } - else if (sItem == "reindex") - { - int r = Restarter::CreateGridcoinRestorePoint(); - Restarter::ReindexGridcoinWallet(); - entry.push_back(Pair("Reindex Chain",r)); - results.push_back(entry); - } - /*else if (sItem == "downloadblocks") - { - int r=Restarter::DownloadGridcoinBlocks(); - entry.push_back(Pair("Download Blocks",r)); - results.push_back(entry); - }*/ - else if (sItem == "getnextproject") - { - GetNextProject(true); - entry.push_back(Pair("GetNext",1)); - results.push_back(entry); - } - else if (sItem == "resetcpids") - { - //Reload the config file - ReadConfigFile(mapArgs, mapMultiArgs); - HarvestCPIDs(true); - GetNextProject(true); - entry.push_back(Pair("Reset",1)); - results.push_back(entry); - } - else if (sItem == "resendwallettx") - { - ResendWalletTransactions(true); - entry.push_back(Pair("Resending unsent wallet transactions...",1)); - results.push_back(entry); - } - else if (sItem == "encrypt_deprecated") - { - std::string s1 = "1234"; - std::string s1dec = AdvancedCrypt(s1); - std::string s1out = AdvancedDecrypt(s1dec); - entry.push_back(Pair("Execute Encrypt result1",s1)); - entry.push_back(Pair("Execute Encrypt result2",s1dec)); - entry.push_back(Pair("Execute Encrypt result3",s1out)); - results.push_back(entry); - } - else if (sItem == "debug") - { - if (params.size() == 2 && (params[1].get_str() == "true" || params[1].get_str() == "false")) - { - fDebug = (params[1].get_str() == "true") ? true : false; - entry.push_back(Pair("Debug", fDebug ? "Entering debug mode." : "Exiting debug mode.")); - } - else - entry.push_back(Pair("Error","You must specify true or false as an option.")); - results.push_back(entry); - } - else if (sItem == "debugnet") - { - if (params.size() == 2 && (params[1].get_str() == "true" || params[1].get_str() == "false")) - { - fDebugNet = (params[1].get_str() == "true") ? true : false; - entry.push_back(Pair("DebugNet", fDebugNet ? "Entering debug mode." : "Exiting debug mode.")); - } - else - entry.push_back(Pair("Error","You must specify true or false as an option.")); - results.push_back(entry); - } - else if (sItem == "debug2") - { - if (params.size() == 2 && (params[1].get_str() == "true" || params[1].get_str() == "false")) - { - fDebug2 = (params[1].get_str() == "true") ? true : false; - entry.push_back(Pair("Debug2", fDebug2 ? "Entering debug mode." : "Exiting debug mode.")); - } - else - entry.push_back(Pair("Error","You must specify true or false as an option.")); - results.push_back(entry); - } - else if (sItem == "debug3") - { - if (params.size() == 2 && (params[1].get_str() == "true" || params[1].get_str() == "false")) - { - fDebug3 = (params[1].get_str() == "true") ? true : false; - entry.push_back(Pair("Debug3", fDebug3 ? "Entering debug mode." : "Exiting debug mode.")); - } - else - entry.push_back(Pair("Error","You must specify true or false as an option.")); - results.push_back(entry); - } - else if (sItem == "debug10") - { - if (params.size() == 2 && (params[1].get_str() == "true" || params[1].get_str() == "false")) - { - fDebug10 = (params[1].get_str() == "true") ? true : false; - entry.push_back(Pair("Debug10", fDebug10 ? "Entering debug mode." : "Exiting debug mode.")); - } - else - entry.push_back(Pair("Error","You must specify true or false as an option.")); - results.push_back(entry); - } - else if (sItem == "help") - { - entry.push_back(Pair("execute addpoll <days> <question> <answers> <sharetype> <url>", "Add a poll (Requires minimum 100000 GRC balance)")); - entry.push_back(Pair("execute advertisebeacon", "Advertise a beacon (Requires wallet to be fully unlocked)")); - entry.push_back(Pair("execute askforoutstandingblocks", "Asks nodes for outstanding blocks")); - entry.push_back(Pair("execute backupprivatekeys", "Backup private keys (Wallet must be fully unlocked")); - entry.push_back(Pair("execute beaconreport", "Displays information about current active beacons in the network")); - entry.push_back(Pair("execute beaconstatus", "Displays information about your beacon")); - entry.push_back(Pair("execute burn <burnaddress> <burnamount> <burnkey> <burndetail>", "Burn coins for contract")); - entry.push_back(Pair("execute cleanchain", "Cleans current chain and attempts to reorganize")); - entry.push_back(Pair("execute currentneuralhash", "Displays the popular hash in current neural report from all neural nodes")); - entry.push_back(Pair("execute currentneuralreport", "Displays all hashes staked recently by neural nodes")); - entry.push_back(Pair("execute debug <true/false>", "Turn on/off debug messages on the fly")); - entry.push_back(Pair("execute debug2 <true/false>", "Turn on/off debug2 messages on the fly")); - entry.push_back(Pair("execute debug3 <true/false>", "Turn on/off debug3 messages on the fly")); - entry.push_back(Pair("execute debug10 <true/false>", "Turn on/off debug10 messages on the fly")); - entry.push_back(Pair("execute debugnew <true/false>", "Turn on/off debugnet messages on the fly")); - entry.push_back(Pair("execute decryptphrase <phrase>", "Decrypt an encrypted phrase")); - //entry.push_back(Pair("execute downloadblocks", "Download blocks from blockchain")); - entry.push_back(Pair("execute dportally", "Tally magnitudes in superblock")); - entry.push_back(Pair("execute encrypt <phrase>", "Encrypt a wallet pass phrase (autounlock feature)")); - entry.push_back(Pair("execute encryptphrase <phrase>", "Encrypt a phrase or message")); - entry.push_back(Pair("execute listallpolldetails", "Displays all polls past and present with details")); - entry.push_back(Pair("execute listallpolls", "Displays all polls past and present")); - entry.push_back(Pair("execute listpolldetails", "Displays all active polls details")); - entry.push_back(Pair("execute listpollresults <title> <true>", "Displays poll results for specified title. True is optional for expired polls")); - entry.push_back(Pair("execute listpolls", "Displays all active polls")); - entry.push_back(Pair("execute myneuralhash", "Displays your current neural hash from contract")); - entry.push_back(Pair("execute neuralhash", "Displays the network popular hash in neural report (Participating nodes)")); - entry.push_back(Pair("execute neuralreport", "Displays information of recently staked neural votes by participating nodes")); - entry.push_back(Pair("execute neuralresponse", "Requests a response from neural network")); - entry.push_back(Pair("execute rain <raindata>", "Sends rain to specified users. Format Address<COL>Amount<ROW>...")); - entry.push_back(Pair("execute reindex", "Reindex blockchain")); - entry.push_back(Pair("execute resendwallettx", "Resends a wallet tx")); - entry.push_back(Pair("execute resetcpids", "Resets wallet cpids (can be used to correct cpids after a split cpid is fixed)")); - entry.push_back(Pair("execute restart", "Restarts wallet")); - entry.push_back(Pair("execute restorepoint", "Creates a restore point for wallet")); - entry.push_back(Pair("execute staketime", "Displays unix timestamp based on stake gric time and cpid time")); - entry.push_back(Pair("execute superblockinfo", "Displays information and age about current superblock")); - entry.push_back(Pair("execute syncdpor2", "Synchronize with neural network")); - entry.push_back(Pair("execute tally", "Tallys research averages")); - entry.push_back(Pair("execute tallyneural", "Tally neural quorum data")); - entry.push_back(Pair("execute unspentreport", "Displays unspent wallet information")); - entry.push_back(Pair("execute upgradedbeaconreport", "Displays information about upgraded beacons")); - entry.push_back(Pair("execute updatequorumdata", "Updates neural quorum data")); - entry.push_back(Pair("execute versionreport", "Displays information about client versions that staked the last 100 blocks")); - entry.push_back(Pair("execute vote <title> <answer>", "Casts a vote for a specific poll with chosen answer")); - entry.push_back(Pair("execute votedetails <title>", "Displays information on a specified poll's votes")); - results.push_back(entry); - } - else if (sItem == "helpdev") - { - entry.push_back(Pair("execute addkey <add_or_delete> <keytype> <projectname> <value>", "Add or delete key to network")); - entry.push_back(Pair("execute executecode", "Execute .net code")); - entry.push_back(Pair("execute forcequorum", "Force quorum")); - entry.push_back(Pair("execute gatherneuralhashes", "Gather neural hashes")); - entry.push_back(Pair("execute getlistof <keytype>", "Get list of keytype data")); - entry.push_back(Pair("execute listdata <keytype>", "List data in a keytype")); - entry.push_back(Pair("execute memorizekeys", "Memorize keys from admin messages")); - entry.push_back(Pair("execute readdata <key> <value>", "Display value from a keys data")); - entry.push_back(Pair("execute refhash <grcaddress>", "Check if a grc address is a neural node participant as well as you")); - entry.push_back(Pair("execute sendblock <hash>", "Send a block to network")); - entry.push_back(Pair("execute testnewcontract", "Test current neural contract")); - entry.push_back(Pair("execute writedata <key> <value>", "Write data to a key with value")); - results.push_back(entry); - } -else - { - entry.push_back(Pair("Command " + sItem + " not found.",-1)); - results.push_back(entry); - } - return results; + Array aUnspentReport = GetJsonUnspentReport(); + return aUnspentReport; } - Array LifetimeReport(std::string cpid) { Array results; From c5f4fa98fe2bde29b315e8386c0bc554fb3650b9 Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Fri, 16 Feb 2018 16:29:05 -0800 Subject: [PATCH 06/28] fix rpc bug and support for subcategories --- src/bitcoinrpc.cpp | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 54a7f6b745..feceee109f 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -161,26 +161,37 @@ string CRPCTable::help(string strCommand, rpccategory category) const // We already filter duplicates, but these deprecated screw up the sort order if (strMethod.find("label") != string::npos) continue; - if (strCommand != "" && strMethod != strCommand) + // Refactored rules for supporting of subcategories + if ( strCommand.empty() + && ( (pcmd->category != cat_null && pcmd->category != category) + || (category != cat_null && strMethod == "help") + ) + ) + continue; + if ( !strCommand.empty() + && ( pcmd->category == cat_null + || strMethod != strCommand + ) + ) continue; try { Array params; rpcfn_type pfn = pcmd->actor; - if (setDone.insert(pfn).second && (pcmd->category == category || category == cat_null)) + if (setDone.insert(pfn).second) (*pfn)(params, true); } catch (std::exception& e) { // 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); strRet = strRet.substr(0,strRet.size()-1); return strRet; @@ -190,15 +201,16 @@ Value help(const Array& params, bool fHelp) { if (fHelp || params.size() == 0 || params.size() > 1) throw runtime_error( - "help\n" - "Returns list of subcategories for extended help\n" + "help [command/category]\n" + "Returns help on a specific command or category you request\n" "\n" - "help [command] Returns help for a specific requested command\n" + "help command --> Returns help for specified command; ex. help backupwallet\n" "\n" - "help wallet Returns help for blockchain related commands\n" - "help neuralnetwork Returns help for neural network/cpid/beacon related commands\n" - "help developer Returns help for developer commands\n" - "help network Returns help for network related commands\n"); + "Categories:\n" + "wallet --------> Returns help for blockchain related commands\n" + "neuralnetwork -> Returns help for neural network/cpid/beacon related commands\n" + "developer -----> Returns help for developer commands\n" + "network -------> Returns help for network related commands\n"); // Allow to process through if params size is > 0 string strCommand; @@ -208,7 +220,7 @@ Value help(const Array& params, bool fHelp) // Subcategory help area // Blockchain related commands - rpccategory category = cat_null; + rpccategory category; if (strCommand == "wallet") category = cat_wallet; @@ -217,7 +229,7 @@ Value help(const Array& params, bool fHelp) category = cat_neuralnetwork; else if (strCommand == "developer") - category = cat_neuralnetwork; + category = cat_developer; else if (strCommand == "network") category = cat_network; From 072dbc2cf69bfc963e4e87426996d10a2b192046 Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Sun, 18 Feb 2018 11:16:52 -0800 Subject: [PATCH 07/28] latest changes --- src/bitcoinrpc.cpp | 64 +- src/bitcoinrpc.h | 19 +- src/rpcblockchain.cpp | 1644 +++++++++++++++++++++++++++++++++++------ src/rpcmining.cpp | 4 +- src/rpcwallet.cpp | 2 +- 5 files changed, 1513 insertions(+), 220 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index feceee109f..23df913a5c 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -208,7 +208,7 @@ Value help(const Array& params, bool fHelp) "\n" "Categories:\n" "wallet --------> Returns help for blockchain related commands\n" - "neuralnetwork -> Returns help for neural network/cpid/beacon related commands\n" + "mining --------> Returns help for neural network/cpid/beacon related commands\n" "developer -----> Returns help for developer commands\n" "network -------> Returns help for network related commands\n"); @@ -225,8 +225,8 @@ Value help(const Array& params, bool fHelp) if (strCommand == "wallet") category = cat_wallet; - else if (strCommand == "neuralnetwork") - category = cat_neuralnetwork; + else if (strCommand == "mining") + category = cat_mining; else if (strCommand == "developer") category = cat_developer; @@ -269,6 +269,8 @@ static const CRPCCommand vRPCCommands[] = { // name function safemd category // ------------------------ ----------------------- ------ ----------------- { "help", &help, true, cat_null }, + + // Wallet commands { "addmultisigaddress", &addmultisigaddress, false, cat_wallet }, { "addredeemscript", &addredeemscript, false, cat_wallet }, { "backupprivatekeys", &backupprivatekeys, false, cat_wallet }, @@ -307,7 +309,7 @@ static const CRPCCommand vRPCCommands[] = { "move", &movecmd, false, cat_wallet }, { "newburnaddress", &newburnaddress, false, cat_wallet }, { "rain", &rain, false, cat_wallet }, - { "repairewallet", &repairwallet, false, cat_wallet }, + { "repairwallet", &repairwallet, false, cat_wallet }, { "resendtx", &resendtx, false, cat_wallet }, { "reservebalance", &reservebalance, false, cat_wallet }, { "sendfrom", &sendfrom, false, cat_wallet }, @@ -325,6 +327,35 @@ static const CRPCCommand vRPCCommands[] = { "walletpassphrase", &walletpassphrase, true, cat_wallet }, { "walletpassphrasechange", &walletpassphrasechange, false, cat_wallet }, + // Mining commands + { "advertisebeacon", &advertisebeacon, false, cat_mining }, + { "beaconreport", &beaconreport, true, cat_mining }, + { "beaconstatus", &beaconstatus, true, cat_mining }, + { "cpids", &cpids, true, cat_mining }, + { "currentneuralhash", ¤tneuralhash, true, cat_mining }, + { "currentneuralreport", ¤tneuralreport, true, cat_mining }, + { "explainmagnitude", &explainmagnitude, true, cat_mining }, + { "getmininginfo", &getmininginfo, false, cat_mining }, + { "lifetime", &lifetime, true, cat_mining }, + { "magnitude", &magnitude, true, cat_mining }, + { "mymagnitude", &mymagnitude, true, cat_mining }, +#ifdef WIN32 + { "myneuralhash", &myneuralhash, true, cat_mining }, +#endif + { "neuralhash", &neuralhash, true, cat_mining }, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + }; template<typename T> @@ -406,6 +437,8 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri if (strMethod == "walletpassphrase" && n > 1) ConvertTo<int64_t>(params[1]); if (strMethod == "walletpassphrase" && n > 2) ConvertTo<bool>(params[2]); + // Mining + if (strMethod == "explainmagnitude" && n > 0) ConvertTo<bool>(params[0]); return params; } @@ -1167,10 +1200,29 @@ 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); + // Lets add a optional debug4 to display how long it takes the rpc commands to be performed in ms + // We will do this only on successful calls not exceptions try { - // Execute - Value result = pcmd->actor(params, false); + Value result; + + if (fDebug4) + { + int64_t nRPCtimebegin; + int64_t nRPCtimetotal; + + nRPCtimebegin = GetTimeMillis(); + + result = pcmd->actor(params, false); + + nRPCtimetotal = GetTimeMillis() - nRPCtimebegin; + + printf("RPCTime : Command %s -> Totaltime %" PRId64 "ms\n", strMethod.c_str(), nRPCtimetotal); + + return result; + } + + result = pcmd->actor(params, false); return result; } diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index d901cfa7fa..97098d4708 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -96,7 +96,7 @@ enum rpccategory { cat_null, cat_wallet, - cat_neuralnetwork, + cat_mining, cat_developer, cat_network }; @@ -210,6 +210,22 @@ extern json_spirit::Value walletlock(const json_spirit::Array& params, bool fHel extern json_spirit::Value walletpassphrase(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value walletpassphrasechange(const json_spirit::Array& params, bool fHelp); +//Mining +extern json_spirit::Value advertisebeacon(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value beaconreport(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value beaconstatus(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value cpids(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value currentneuralhash(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value currentneuralreport(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value explainmagnitude(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value lifetime(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value magnitude(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value mymagnitude(const json_spirit::Array& params, bool fHelp); +#ifdef WIN32 +extern json_spirit::Value myneuralhash(const json_spirit::Array& params, bool fHelp); +#endif +extern json_spirit::Value neuralhash(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp); @@ -217,7 +233,6 @@ extern json_spirit::Value ping(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value sendalert(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getnettotals(const json_spirit::Array& params, bool fHelp); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index c8cc9c53fe..93b39bc905 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -61,7 +61,6 @@ extern bool VerifyCPIDSignature(std::string sCPID, std::string sBlockHash, std:: std::string GetQuorumHash(const std::string& data); double GetOutstandingAmountOwed(StructCPID &mag, std::string cpid, int64_t locktime, double& total_owed, double block_magnitude); bool UpdateNeuralNetworkQuorumData(); -extern Array LifetimeReport(std::string cpid); extern std::string AddContract(std::string sType, std::string sName, std::string sContract); StructCPID GetLifetimeCPID(const std::string& cpid, const std::string& sFrom); int64_t GetEarliestWalletTransaction(); @@ -1069,7 +1068,7 @@ int64_t AmountFromDouble(double dAmount) Value backupprivatekeys(const Array& params, bool fHelp) { - if (fHelp || params.size() > 0) + if (fHelp || params.size() != 0) throw runtime_error( "backupprivatekeys\n" "\n" @@ -1099,10 +1098,10 @@ Value burn2(const Array& params, bool fHelp) throw runtime_error( "burn2 <burnaddress> <burnamount> <burnkey> <burndetail>\n" "\n" - "<burnaddress> Address where the coins will be burned\n" - "<burnamount> Amount of coins to be burned\n" - "<burnaddress> Burn key to be used\n" - "<burndetails> Details of the burn\n"); + "<burnaddress> -> Address where the coins will be burned\n" + "<burnamount> -> Amount of coins to be burned\n" + "<burnaddress> -> Burn key to be used\n" + "<burndetails> -> Details of the burn\n"); Object res; std::string sAddress = params[0].get_str(); @@ -1145,7 +1144,7 @@ Value encrypt(const Array& params, bool fHelp) throw runtime_error( "encrypt <walletpassphrase>\n" "\n" - "<walletpassphrase> The password of your encrypted wallet\n"); + "<walletpassphrase> -> The password of your encrypted wallet\n"); Object res; //Encrypt a phrase @@ -1162,16 +1161,15 @@ Value newburnaddress(const Array& params, bool fHelp) throw runtime_error( "newburnaddress [burntemplate]\n" "\n" - "[burntemplate] Allow a vanity burn address\n"); + "[burntemplate] -> Allow a vanity burn address\n"); Object res; //3-12-2016 - R Halford - Allow the user to make vanity GRC Burn Addresses that have no corresponding private key std::string sBurnTemplate = "GRCBurnAddressGRCBurnAddressGRCBurnAddress"; if (params.size() > 0) - { sBurnTemplate = params[0].get_str(); - } + // Address must start with the correct base58 network flag and address type for GRC std::string sPrefix = (fTestNet) ? "mp" : "Rx"; std::string t34 = sPrefix + sBurnTemplate + "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; @@ -1212,10 +1210,11 @@ Value newburnaddress(const Array& params, bool fHelp) Value rain(const json_spirit::Array& params, bool fHelp) { - if (fHelp || params.size() < 1 || params.size() > 1) + if (fHelp || params.size() != 1) throw runtime_error( "rain Address<COL>Amount<ROW>...\n" - "\n"); + "\n" + "rains coins on the network\n"); Object res; @@ -1239,101 +1238,1447 @@ Value rain(const json_spirit::Array& params, bool fHelp) std::vector<std::string> vReward = split(sRow.c_str(),"<COL>"); if (vReward.size() > 1) { - std::string sAddress = vReward[0]; - std::string sAmount = vReward[1]; - if (sAddress.length() > 10 && sAmount.length() > 0) - { - double dAmount = RoundFromString(sAmount,4); - if (dAmount > 0) - { - CBitcoinAddress address(sAddress); - if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Gridcoin address: ")+sAddress); - if (setAddress.count(address)) - throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+sAddress); - setAddress.insert(address); - dTotalToSend += dAmount; - int64_t nAmount = AmountFromDouble(dAmount); - CScript scriptPubKey; - scriptPubKey.SetDestination(address.Get()); - totalAmount += nAmount; - vecSend.push_back(make_pair(scriptPubKey, nAmount)); - } - } + std::string sAddress = vReward[0]; + std::string sAmount = vReward[1]; + if (sAddress.length() > 10 && sAmount.length() > 0) + { + double dAmount = RoundFromString(sAmount,4); + if (dAmount > 0) + { + CBitcoinAddress address(sAddress); + if (!address.IsValid()) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Gridcoin address: ")+sAddress); + if (setAddress.count(address)) + throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+sAddress); + setAddress.insert(address); + dTotalToSend += dAmount; + int64_t nAmount = AmountFromDouble(dAmount); + CScript scriptPubKey; + scriptPubKey.SetDestination(address.Get()); + totalAmount += nAmount; + vecSend.push_back(make_pair(scriptPubKey, nAmount)); + } + } + } + } + + EnsureWalletIsUnlocked(); + // Check funds + double dBalance = GetTotalBalance(); + if (dTotalToSend > dBalance) + throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); + // Send + CReserveKey keyChange(pwalletMain); + int64_t nFeeRequired = 0; + bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired); + printf("Transaction Created."); + if (!fCreated) + { + if (totalAmount + nFeeRequired > pwalletMain->GetBalance()) + throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds"); + throw JSONRPCError(RPC_WALLET_ERROR, "Transaction creation failed"); + } + printf("Committing."); + // Rain the recipients + if (!pwalletMain->CommitTransaction(wtx, keyChange)) + { + printf("Commit failed."); + throw JSONRPCError(RPC_WALLET_ERROR, "Transaction commit failed"); + } + std::string sNarr = "Rain successful: Sent " + wtx.GetHash().GetHex() + "."; + printf("Success %s",sNarr.c_str()); + res.push_back(Pair("Response", sNarr)); + + return res; +} + +Value unspentreport(const json_spirit::Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "unspentreport\n" + "\n" + "Displays unspentreport\n"); + + LOCK2(cs_main, pwalletMain->cs_wallet); + + Array aUnspentReport = GetJsonUnspentReport(); + + return aUnspentReport; +} + +Value advertisebeacon(const json_spirit::Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "advertisebeacon\n" + "\n" + "Advertise a beacon\n" + "Requires wallet to be fully unlocked\n"); + + Object res; + + std::string sOutPubKey = ""; + std::string sOutPrivKey = ""; + std::string sError = ""; + std::string sMessage = ""; + + bool fResult = AdvertiseBeacon(sOutPrivKey,sOutPubKey,sError,sMessage); + res.push_back(Pair("Result",SuccessFail(fResult))); + res.push_back(Pair("CPID",GlobalCPUMiningCPID.cpid.c_str())); + res.push_back(Pair("Message",sMessage.c_str())); + + if (!sError.empty()) + res.push_back(Pair("Errors",sError)); + + if (!fResult) + res.push_back(Pair("FAILURE","Note: if your wallet is locked this command will fail; to solve that unlock the wallet: 'walletpassphrase <yourpassword> <240>'.")); + + else + { + res.push_back(Pair("Public Key",sOutPubKey.c_str())); + res.push_back(Pair("Warning!","Your public and private research keys have been stored in gridcoinresearch.conf. Do not lose your private key (It is non-recoverable). It is recommended that you back up your gridcoinresearch.conf file on a regular basis.")); + } + + return res; +} + +Value beaconreport(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "beaconreport\n" + "\n" + "Displays list of valid beacons in the network\n"); + + Object res; + + Array myBeaconJSONReport = GetJSONBeaconReport(); + res.push_back(myBeaconJSONReport); + + return res; +} + +Value beaconstatus(const json_spirit::Array& params, bool fHelp) +{ + if (fHelp || params.size() > 1) + throw runtime_error( + "beaconstatus [cpid]\n" + "\n" + "[beacon] -> Optional parameter of cpid\n" + "Displays status of your beacon or specified beacon on the network\n"); + + Object res; + + // Search for beacon, and report on beacon status. + + std::string sCPID = msPrimaryCPID; + + if (params.size() > 0) + sCPID = params[0].get_str(); + + res.push_back(Pair("CPID", sCPID)); + std::string sPubKey = GetBeaconPublicKey(sCPID, false); + std::string sPrivKey = GetStoredBeaconPrivateKey(sCPID); + int64_t iBeaconTimestamp = BeaconTimeStamp(sCPID, false); + std::string timestamp = TimestampToHRDate(iBeaconTimestamp); + + bool hasBeacon = HasActiveBeacon(sCPID); + res.push_back(Pair("Beacon Exists",YesNo(hasBeacon))); + res.push_back(Pair("Beacon Timestamp",timestamp.c_str())); + + res.push_back(Pair("Public Key", sPubKey.c_str())); + res.push_back(Pair("Private Key", sPrivKey.c_str())); + + std::string sErr = ""; + + if (sPubKey.empty()) + sErr += "Public Key Missing. "; + if (sPrivKey.empty()) + sErr += "Private Key Missing. "; + + // Verify the users Local Public Key matches the Beacon Public Key + std::string sLocalPubKey = GetStoredBeaconPublicKey(sCPID); + res.push_back(Pair("Local Configuration Public Key", sLocalPubKey.c_str())); + + if (sLocalPubKey.empty()) + sErr += "Local configuration file Public Key missing. "; + + if (sLocalPubKey != sPubKey && !sPubKey.empty()) + sErr += "Local configuration public key does not match beacon public key. This can happen if you copied the wrong public key into your configuration file. Please request that your beacon is deleted, or look into walletbackups for the correct keypair. "; + + // Prior superblock Magnitude + double dMagnitude = GetMagnitudeByCpidFromLastSuperblock(sCPID); + res.push_back(Pair("Magnitude (As of last superblock)", dMagnitude)); + + if (dMagnitude==0) + res.push_back(Pair("Warning","Your magnitude is 0 as of the last superblock: this may keep you from staking POR blocks.")); + + // Staking Test 10-15-2016 - Simulate signing an actual block to verify this CPID keypair will work. + uint256 hashBlock = GetRandHash(); + + if (!sPubKey.empty()) + { + std::string sSignature = SignBlockWithCPID(sCPID,hashBlock.GetHex()); + bool fResult = VerifyCPIDSignature(sCPID, hashBlock.GetHex(), sSignature); + res.push_back(Pair("Block Signing Test Results", fResult)); + + if (!fResult) + sErr += "Failed to sign POR block. This can happen if your keypair is invalid. Check walletbackups for the correct keypair, or request that your beacon is deleted. "; + } + + if (!sErr.empty()) + { + res.push_back(Pair("Errors", sErr)); + res.push_back(Pair("Help", "Note: If your beacon is missing its public key, or is not in the chain, you may try: execute advertisebeacon.")); + res.push_back(Pair("Configuration Status","FAIL")); + } + + else + res.push_back(Pair("Configuration Status", "SUCCESSFUL")); + + return res; +} + +Value cpids(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "cpids\n" + "\n" + "Displays information on your cpids\n"); + + Object res; + + //Dump vectors: + + if (mvCPIDs.size() < 1) + HarvestCPIDs(false); + + printf ("generating cpid report %s\n",sitem.c_str()); + + for(map<string,StructCPID>::iterator ii=mvCPIDs.begin(); ii!=mvCPIDs.end(); ++ii) + { + + StructCPID structcpid = mvCPIDs[(*ii).first]; + + if (structcpid.initialized) + { + if ((GlobalCPUMiningCPID.cpid.length() > 3 && + structcpid.cpid == GlobalCPUMiningCPID.cpid) + || !IsResearcher(structcpid.cpid) || !IsResearcher(GlobalCPUMiningCPID.cpid)) + { + res.push_back(Pair("Project",structcpid.projectname)); + res.push_back(Pair("CPID",structcpid.cpid)); + res.push_back(Pair("RAC",structcpid.rac)); + res.push_back(Pair("Team",structcpid.team)); + res.push_back(Pair("CPID Link",structcpid.link)); + res.push_back(Pair("Debug Info",structcpid.errors)); + res.push_back(Pair("Project Settings Valid for Gridcoin",structcpid.Iscpidvalid)); + + } + } + } + + return res; +} + +Value currentneuralhash(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "currentneuralhash\n" + "\n" + "Displays information for the current popular neural hash in network\n"); + + Object res; + + double popularity = 0; + std::string consensus_hash = GetCurrentNeuralNetworkSupermajorityHash(popularity); + res.push_back(Pair("Popular",consensus_hash)); + + return res; +} + +Value currentneuralreport(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "currentneuralreport\n" + "\n" + "Displays information for the current neural hashes in network\n"); + + Object res; + + Array myNeuralJSON = GetJSONCurrentNeuralNetworkReport(); + res.push_back(myNeuralJSON); + + return res; +} + +Value explainmagnitude(const Array& params, bool fHelp) +{ + if (fHelp || params.size() > 1) + throw runtime_error( + "explainmagnitude [bool:force]\n" + "\n" + "[force] -> Optional: Force a response (excessive requests can result in temporary ban from neural reponses)\n" + "Displays information for the current neural hashes in network\n"); + + Object res; + + bool bForce = false; + + if (params.size() > 0) + bForce = params[0].get_bool(); + + if (bForce) + { + if (msNeuralResponse.length() < 25) + { + res.push_back(Pair("Neural Response", "Empty; Requesting a response..")); + res.push_back(Pair("WARNING", "Only force once and try again without force if response is not received. Doing too many force attempts gets a temporary ban from neural node responses")); + + msNeuralResponse = ""; + + AsyncNeuralRequest("explainmag", GlobalCPUMiningCPID.cpid, 10); + } + } + + if (msNeuralResponse.length() > 25) + { + res.push_back(Pair("Neural Response", "true")); + + std::vector<std::string> vMag = split(msNeuralResponse.c_str(),"<ROW>"); + + for (unsigned int i = 0; i < vMag.size(); i++) + res.push_back(Pair(RoundToString(i+1,0),vMag[i].c_str())); + } + + else + res.push_back(Pair("Neural Response", "false; Try again at a later time")); + + res.push_back(entry); + + return res; +} + +Value lifetime(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "lifttime\n" + "\n" + "Displays information for the lifetime of your cpid in the network\n"); + + Array results; + Object c; + Object res; + + std::string cpid = msPrimaryCPID; + std::string Narr = ToString(GetAdjustedTime()); + c.push_back(Pair("Lifetime Payments Report",Narr)); + results.push_back(c); + CBlockIndex* pindex = pindexGenesisBlock; + while (pindex->nHeight < pindexBest->nHeight) + { + pindex = pindex->pnext; + if (pindex==NULL || !pindex->IsInMainChain()) + continue; + if (pindex == pindexBest) + break; + if (pindex->GetCPID() == cpid && (pindex->nResearchSubsidy > 0)) + res.push_back(Pair(pindex->nHeight, RoundToString(pindex->nResearchSubsidy,2))); + } + //8-14-2015 + StructCPID stCPID = GetInitializedStructCPID2(cpid,mvResearchAge); + res.push_back(Pair("Average Magnitude",stCPID.ResearchAverageMagnitude)); + results.push_back(res); + + return results; +} + +Value magnitude(const json_spirit::Array& params, bool fHelp) +{ + if (fHelp || params.size() > 1) + throw runtime_error( + "magnitude <cpid>\n" + "\n" + "<cpid> -> Required to be used on mainnet\n" + "Displays information for the magnitude of all cpids or specified in the network\n"); + + Array results; + + std::string cpid = ""; + + if (params.size() > 1) + cpid = params[0].get_str(); + + results = MagnitudeReport(cpid); + + if (results.size() > 1000) + { + results.clear(); + Object entry; + entry.push_back(Pair("Error","Magnitude report too large; try specifying the cpid : magnitude <cpid>.")); + results.push_back(entry); + } + + return results; +} + +Value mymagnitude(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "mymagnitude\n" + "\n" + "Displays information for your magnitude in the network\n"); + + Array results; + + if (msPrimaryCPID.empty()) + { + Object res; + res.push_back(Pair("Error", "Your CPID appears to be empty")); + results.push_back(res); + } + + else + results = MagnitudeReport(msPrimaryCPID); + + return results; +} + +#ifdef WIN32 +Value myneuralhash(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "myneuralhash\n" + "\n" + "Displays information about your neural networks client current hash\n"); + + Object res; + + std::string myNeuralHash = NN::GetNeuralHash(); + res.push_back(Pair("My Neural Hash",myNeuralHash.c_str())); + + return res; +} +#endif + +Value neuralhash(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "neuralhash\n" + "\n" + "Displays information about the popular\n"); + + Object res; + + std::string myNeuralHash = NN::GetNeuralHash(); + res.push_back(Pair("My Neural Hash",myNeuralHash.c_str())); + + return res; +} + +Value execute(const Array& params, bool fHelp) +{ + if (fHelp || (params.size() != 1 && params.size() != 2 && params.size() != 3 && params.size() != 4 && params.size() != 5 && params.size() != 6 && params.size() != 7)) + throw runtime_error( + "execute <string::itemname> <string::parameter> \r\n" + "Executes an arbitrary command by name.\n" + "execute help\n" + "Displays help on various available execute commands.\n"); + + std::string sItem = params[0].get_str(); + + if (sItem=="") throw runtime_error("Item invalid."); + + Array results; + Object oOut; + oOut.push_back(Pair("Command",sItem)); + results.push_back(oOut); + Object entry; + + if (sItem == "restorepoint") + { + int r= Restarter::CreateGridcoinRestorePoint(); + //We must stop the node before we can do this + //RestartGridcoin(); + entry.push_back(Pair("Restore Point",r)); + results.push_back(entry); + } + else if (sItem == "restart") + { + printf("Restarting Gridcoin..."); + int iResult = Restarter::RestartGridcoin(); + entry.push_back(Pair("RebootClient", iResult)); + results.push_back(entry); + + } + else if (sItem == "sendblock") + { + if (params.size() != 2) + { + entry.push_back(Pair("Error","You must specify the block hash to send.")); + results.push_back(entry); + } + std::string sHash = params[1].get_str(); + uint256 hash = uint256(sHash); + bool fResult = AskForOutstandingBlocks(hash); + entry.push_back(Pair("Requesting",hash.ToString())); + entry.push_back(Pair("Result",fResult)); + results.push_back(entry); + } + else if (sItem=="proveownership") + { + HarvestCPIDs(true); + GetNextProject(true); + std::string email = GetArgument("email", "NA"); + boost::to_lower(email); + entry.push_back(Pair("Boinc E-Mail",email)); + entry.push_back(Pair("Boinc Public Key",GlobalCPUMiningCPID.boincruntimepublickey)); + entry.push_back(Pair("CPID",GlobalCPUMiningCPID.cpid)); + std::string sLongCPID = ComputeCPIDv2(email,GlobalCPUMiningCPID.boincruntimepublickey,1); + std::string sShortCPID = RetrieveMd5(GlobalCPUMiningCPID.boincruntimepublickey + email); + std::string sEmailMD5 = RetrieveMd5(email); + std::string sBPKMD5 = RetrieveMd5(GlobalCPUMiningCPID.boincruntimepublickey); + entry.push_back(Pair("Computed Email Hash",sEmailMD5)); + entry.push_back(Pair("Computed BPK",sBPKMD5)); + + entry.push_back(Pair("Computed CPID",sLongCPID)); + entry.push_back(Pair("Computed Short CPID", sShortCPID)); + bool fResult = CPID_IsCPIDValid(sShortCPID,sLongCPID,1); + if (GlobalCPUMiningCPID.boincruntimepublickey.empty()) + { + fResult=false; + entry.push_back(Pair("Error","Boinc Public Key empty. Try mounting your boinc project first, and ensure the gridcoin datadir setting is set if boinc is not in the default location.")); + } + entry.push_back(Pair("CPID Valid",fResult)); + results.push_back(entry); + } + else if (sItem == "neuralrequest") + { + + std::string response = NeuralRequest("REQUEST"); + entry.push_back(Pair("Response", response)); + results.push_back(entry); + + } + else if (sItem == "syncdpor2") + { + std::string sOut = ""; + bool bFull = GetCountOf("beacon") < 50 ? true : false; + LoadAdminMessages(bFull,sOut); + FullSyncWithDPORNodes(); + entry.push_back(Pair("Syncing",1)); + results.push_back(entry); + } + else if(sItem=="gatherneuralhashes") + { + GatherNeuralHashes(); + entry.push_back(Pair("Sent",".")); + results.push_back(entry); + + } + else if (sItem == "upgradedbeaconreport") + { + Array aUpgBR = GetUpgradedBeaconReport(); + results.push_back(aUpgBR); + } + else if (sItem == "neuralreport") + { + Array myNeuralJSON = GetJSONNeuralNetworkReport(); + results.push_back(myNeuralJSON); + } + else if (sItem == "tallyneural") + { + ComputeNeuralNetworkSupermajorityHashes(); + UpdateNeuralNetworkQuorumData(); + entry.push_back(Pair("Ready",".")); + results.push_back(entry); + } + else if (sItem == "versionreport") + { + Array myNeuralJSON = GetJSONVersionReport(); + results.push_back(myNeuralJSON); + } + } + else if (sItem == "superblockage") + { + int64_t superblock_time = ReadCache("superblock", "magnitudes").timestamp; + int64_t superblock_age = GetAdjustedTime() - superblock_time; + entry.push_back(Pair("Superblock Age", superblock_age)); + entry.push_back(Pair("Superblock Timestamp", TimestampToHRDate(superblock_time))); + entry.push_back(Pair("Superblock Block Number", ReadCache("superblock", "block_number").value)); + entry.push_back(Pair("Pending Superblock Height", ReadCache("neuralsecurity","pending").value)); + results.push_back(entry); + } + else if (sItem == "unusual") + { + + UnusualActivityReport(); + entry.push_back(Pair("UAR",1)); + results.push_back(entry); + + + } + else if (sItem == "neuralhash") + { + double popularity = 0; + std::string consensus_hash = GetNeuralNetworkSupermajorityHash(popularity); + entry.push_back(Pair("Popular",consensus_hash)); + results.push_back(entry); + } + else if (sItem=="updatequorumdata") + { + UpdateNeuralNetworkQuorumData(); + entry.push_back(Pair("Updated.","")); + results.push_back(entry); + } + else if (sItem == "askforoutstandingblocks") + { + bool fResult = AskForOutstandingBlocks(uint256(0)); + entry.push_back(Pair("Sent.",fResult)); + results.push_back(entry); + } + else if (sItem == "readconfig") + { + ReadConfigFile(mapArgs, mapMultiArgs); + + } + else if (sItem == "writedata") + { + if (params.size() != 3) + { + entry.push_back(Pair("Error","You must specify the Key and Value. For example execute writedata dog_color black.")); + results.push_back(entry); + } + else + { + std::string sKey = params[1].get_str(); + std::string sValue = params[2].get_str(); + //CTxDB txdb("rw"); + CTxDB txdb; + txdb.TxnBegin(); + std::string result = "Success."; + if (!txdb.WriteGenericData(sKey,sValue)) result = "Unable to write."; + if (!txdb.TxnCommit()) result = "Unable to Commit."; + entry.push_back(Pair("Result",result)); + results.push_back(entry); + } + + } + else if (sItem == "readdata") + { + if (params.size() != 2) + { + entry.push_back(Pair("Error","You must specify the Key. For example execute readdata dog_color.")); + results.push_back(entry); + } + else + { + std::string sKey = params[1].get_str(); + std::string sValue = "?"; + //CTxDB txdb("cr"); + CTxDB txdb; + if (!txdb.ReadGenericData(sKey,sValue)) + { + entry.push_back(Pair("Error",sValue)); + + sValue = "Failed to read from disk."; + } + entry.push_back(Pair("Key",sKey)); + + entry.push_back(Pair("Result",sValue)); + results.push_back(entry); + } + + } + else if (sItem == "refhash") + { + if (params.size() != 2) + { + entry.push_back(Pair("Error","You must specify the Reference Hash.")); + results.push_back(entry); + } + else + { + std::string rh = params[1].get_str(); + bool r1 = StrLessThanReferenceHash(rh); + bool r2 = IsNeuralNodeParticipant(DefaultWalletAddress(), GetAdjustedTime()); + entry.push_back(Pair("<Ref Hash",r1)); + entry.push_back(Pair("WalletAddress<Ref Hash",r2)); + results.push_back(entry); + + } + + } + else if (sItem == "vote") + { + if (params.size() != 3) + { + entry.push_back(Pair("Error","You must specify the Poll Title, and the Answer. For example: execute vote gender male.")); + results.push_back(entry); + } + else + { + std::string Title = params[1].get_str(); + std::string Answer = params[2].get_str(); + if (Title=="" || Answer == "" ) + { + entry.push_back(Pair("Error","You must specify both the answer and the title.")); + results.push_back(entry); + + } + else + { + //Verify the Existence of the poll, the acceptability of the answer, and the expiration of the poll: (EXIST, EXPIRED, ACCEPTABLE) + //If polltype == 1, use magnitude, if 2 use Balance, if 3 use hybrid: + //6-20-2015 + double nBalance = GetTotalBalance(); + uint256 hashRand = GetRandHash(); + std::string email = GetArgument("email", "NA"); + boost::to_lower(email); + GlobalCPUMiningCPID.email=email; + GlobalCPUMiningCPID.cpidv2 = ComputeCPIDv2(GlobalCPUMiningCPID.email, GlobalCPUMiningCPID.boincruntimepublickey, hashRand); + GlobalCPUMiningCPID.lastblockhash = GlobalCPUMiningCPID.cpidhash; + + if (!PollExists(Title)) + { + entry.push_back(Pair("Error","Poll does not exist.")); + results.push_back(entry); + + } + else + { + if (PollExpired(Title)) + { + entry.push_back(Pair("Error","Sorry, Poll is already expired.")); + results.push_back(entry); + } + else + { + if (!PollAcceptableAnswer(Title,Answer)) + { + std::string acceptable_answers = PollAnswers(Title); + entry.push_back(Pair("Error","Sorry, Answer " + Answer + " is not one of the acceptable answers, allowable answers are: " + acceptable_answers + ". If you are voting multiple choice, please use a semicolon delimited vote string such as : 'dog;cat'.")); + results.push_back(entry); + } + else + { + std::string sParam = SerializeBoincBlock(GlobalCPUMiningCPID,pindexBest->nVersion); + std::string GRCAddress = DefaultWalletAddress(); + StructCPID structMag = GetInitializedStructCPID2(GlobalCPUMiningCPID.cpid,mvMagnitudes); + double dmag = structMag.Magnitude; + double poll_duration = PollDuration(Title)*86400; + + // Prevent Double Voting + std::string cpid1 = GlobalCPUMiningCPID.cpid; + std::string GRCAddress1 = DefaultWalletAddress(); + GetEarliestStakeTime(GRCAddress1,cpid1); + double cpid_age = GetAdjustedTime() - ReadCache("global", "nCPIDTime").timestamp; + double stake_age = GetAdjustedTime() - ReadCache("global", "nGRCTime").timestamp; + + StructCPID structGRC = GetInitializedStructCPID2(GRCAddress,mvMagnitudes); + + + printf("CPIDAge %f,StakeAge %f,Poll Duration %f \r\n",cpid_age,stake_age,poll_duration); + + double dShareType= RoundFromString(GetPollXMLElementByPollTitle(Title,"<SHARETYPE>","</SHARETYPE>"),0); + + // Share Type 1 == "Magnitude" + // Share Type 2 == "Balance" + // Share Type 3 == "Both" + if (cpid_age < poll_duration) dmag = 0; + if (stake_age < poll_duration) nBalance = 0; + + if ((dShareType == 1) && cpid_age < poll_duration) + { + entry.push_back(Pair("Error","Sorry, When voting in a magnitude poll, your CPID must be older than the poll duration.")); + results.push_back(entry); + } + else if (dShareType == 2 && stake_age < poll_duration) + { + entry.push_back(Pair("Error","Sorry, When voting in a Balance poll, your stake age must be older than the poll duration.")); + results.push_back(entry); + } + else if (dShareType == 3 && stake_age < poll_duration && cpid_age < poll_duration) + { + entry.push_back(Pair("Error","Sorry, When voting in a Both Share Type poll, your stake age Or your CPID age must be older than the poll duration.")); + results.push_back(entry); + } + else + { + std::string voter = "<CPIDV2>"+GlobalCPUMiningCPID.cpidv2 + "</CPIDV2><CPID>" + + GlobalCPUMiningCPID.cpid + "</CPID><GRCADDRESS>" + GRCAddress + "</GRCADDRESS><RND>" + + hashRand.GetHex() + "</RND><BALANCE>" + RoundToString(nBalance,2) + + "</BALANCE><MAGNITUDE>" + RoundToString(dmag,0) + "</MAGNITUDE>"; + // Add the provable balance and the provable magnitude - this goes into effect July 1 2017 + voter += GetProvableVotingWeightXML(); + std::string pk = Title + ";" + GRCAddress + ";" + GlobalCPUMiningCPID.cpid; + std::string contract = "<TITLE>" + Title + "" + Answer + "" + voter; + std::string result = AddContract("vote",pk,contract); + std::string narr = "Your CPID weight is " + RoundToString(dmag,0) + " and your Balance weight is " + RoundToString(nBalance,0) + "."; + entry.push_back(Pair("Success",narr + " " + "Your vote has been cast for topic " + Title + ": With an Answer of " + Answer + ": " + result.c_str())); + results.push_back(entry); + } + } + } + } + + } + } + + } + else if (sItem == "addpoll") + { + if (params.size() != 7) + { + entry.push_back(Pair("Error","You must specify the Poll Title, Expiration In DAYS from Now, Question, Answers delimited by a semicolon, ShareType (1=Magnitude,2=Balance,3=Both,4=CPIDCount,5=ParticipantCount) and discussion URL (use TinyURL.com to make a small URL). Please use underscores in place of spaces inside a sentence. ")); + entry.push_back(Pair("execute addpoll <days> <question> <answers> <sharetype> <url>", "Add a poll (Requires minimum 100000 GRC balance)")); + entry.push_back(Pair("<title>", "Title for poll with no spaces. Use _ in between words")); + entry.push_back(Pair("<days>", "Number of days the poll will run")); + entry.push_back(Pair("<question>", "The poll question in which you seek input for")); + entry.push_back(Pair("<answers>", "The available answers to which a voter can vote seperated by a semicolon")); + entry.push_back(Pair("<sharetype>", "1 = Magnitude 2 = Balance 3 = Magnitude + Balance 4 = CPID count 5 = Participant count")); + entry.push_back(Pair("<url>", "Short url for information about the poll")); + results.push_back(entry); + } + else + { + std::string Title = params[1].get_str(); + std::string Days = params[2].get_str(); + double days = RoundFromString(Days,0); + std::string Question = params[3].get_str(); + std::string Answers = params[4].get_str(); + std::string ShareType = params[5].get_str(); + std::string sURL = params[6].get_str(); + double sharetype = RoundFromString(ShareType,0); + if (Title=="" || Question == "" || Answers == "") + { + entry.push_back(Pair("Error","You must specify a Poll Title, Poll Question and Poll Answers.")); + results.push_back(entry); + } + else + { + if (days < 7) + { + entry.push_back(Pair("Error","Minimum duration is 7 days; please specify a longer poll duration.")); + results.push_back(entry); + } + else + { + double nBalance = GetTotalBalance(); + + if (nBalance < 100000) + { + entry.push_back(Pair("Error","You must have a balance > 100,000 GRC to create a poll. Please post the desired poll on https://cryptocurrencytalk.com/forum/464-gridcoin-grc/ or https://github.com/Erkan-Yilmaz/Gridcoin-tasks/issues/45")); + results.push_back(entry); + } + else + { + if (days < 0 || days == 0) + { + entry.push_back(Pair("Error","You must specify a positive value for days for the expiration date.")); + results.push_back(entry); + + } + else + { + if (sharetype != 1 && sharetype != 2 && sharetype != 3 && sharetype !=4 && sharetype !=5) + { + entry.push_back(Pair("Error","You must specify a value of 1, 2, 3, 4 or 5 for the sharetype.")); + results.push_back(entry); + + } + else + { + std::string expiration = RoundToString(GetAdjustedTime() + (days*86400),0); + std::string contract = "<TITLE>" + Title + "" + RoundToString(days,0) + "" + Question + "" + Answers + "" + RoundToString(sharetype,0) + "" + sURL + "" + expiration + ""; + std::string result = AddContract("poll",Title,contract); + entry.push_back(Pair("Success","Your poll has been added: " + result)); + results.push_back(entry); + } + + } + } + } + } + } + + } + else if (sItem == "votedetails") + { + if (params.size() != 2) + { + entry.push_back(Pair("Error","You must specify the Poll Title.")); + results.push_back(entry); + } + else + { + std::string Title1 = params[1].get_str(); + + if (!PollExists(Title1)) + { + entry.push_back(Pair("Error","Poll does not exist. Please execute listpolls.")); + results.push_back(entry); + + } + else + { + std::string Title = params[1].get_str(); + Array myVotes = GetJsonVoteDetailsReport(Title); + results.push_back(myVotes); + } + } + } + else if (sItem == "listpolls") + { + std::string out1; + Array myPolls = GetJSONPollsReport(false,"",out1,false); + results.push_back(myPolls); + } + else if (sItem == "listallpolls") + { + std::string out1; + Array myPolls = GetJSONPollsReport(false,"",out1,true); + results.push_back(myPolls); + } + else if (sItem == "listallpolldetails") + { + std::string out1; + Array myPolls = GetJSONPollsReport(true,"",out1,true); + results.push_back(myPolls); + + } + else if (sItem=="listpolldetails") + { + std::string out1; + Array myPolls = GetJSONPollsReport(true,"",out1,false); + results.push_back(myPolls); + } + else if (sItem=="listpollresults") + { + bool bIncExpired = false; + if (params.size() == 3) + { + std::string include_expired = params[2].get_str(); + if (include_expired=="true") bIncExpired=true; + } + + if (params.size() != 2 && params.size() != 3) + { + entry.push_back(Pair("Error","You must specify the Poll Title. Example: listpollresults pollname. You may also specify execute listpollresults pollname true if you want to see expired polls.")); + results.push_back(entry); + } + else + { + std::string Title1 = params[1].get_str(); + + if (!PollExists(Title1)) + { + entry.push_back(Pair("Error","Poll does not exist. Please execute listpolls.")); + results.push_back(entry); + + } + else + { + std::string Title = params[1].get_str(); + std::string out1 = ""; + Array myPolls = GetJSONPollsReport(true,Title,out1,bIncExpired); + results.push_back(myPolls); + } + } + } + else if (sItem=="staketime") + { + std::string cpid = GlobalCPUMiningCPID.cpid; + std::string GRCAddress = DefaultWalletAddress(); + GetEarliestStakeTime(GRCAddress,cpid); + entry.push_back(Pair("GRCTime", ReadCache("global", "nGRCTime").timestamp)); + entry.push_back(Pair("CPIDTime",ReadCache("global", "nCPIDTime").timestamp)); + results.push_back(entry); + } + else if (sItem=="testnewcontract") + { + std::string contract = NN::GetNeuralContract(); + std::string myNeuralHash = NN::GetNeuralHash(); + entry.push_back(Pair("My Neural Hash",myNeuralHash.c_str())); + results.push_back(entry); + + entry.push_back(Pair("Contract Test",contract)); + // Convert to Binary + std::string sBin = PackBinarySuperblock(contract); + entry.push_back(Pair("Contract Length",(int)contract.length())); + entry.push_back(Pair("Binary Length",(int)sBin.length())); + //entry.push_back(Pair("Binary",sBin.c_str())); + // Hash of current superblock + std::string sUnpacked = UnpackBinarySuperblock(sBin); + entry.push_back(Pair("Unpacked length",(int)sUnpacked.length())); + + entry.push_back(Pair("Unpacked",sUnpacked.c_str())); + std::string neural_hash = GetQuorumHash(contract); + std::string binary_neural_hash = GetQuorumHash(sUnpacked); + + entry.push_back(Pair("Local Core Quorum Hash",neural_hash)); + entry.push_back(Pair("Binary Local Core Quorum Hash",binary_neural_hash)); + + entry.push_back(Pair("Neural Network Live Quorum Hash",myNeuralHash)); + results.push_back(entry); + } + else if (sItem == "forcequorum") + { + AsyncNeuralRequest("quorum","gridcoin",10); + entry.push_back(Pair("Requested a quorum - waiting for resolution.",1)); + results.push_back(entry); + } + else if (sItem == "tally") + { + bNetAveragesLoaded_retired = false; + TallyResearchAverages_v9(); + entry.push_back(Pair("Tally Network Averages",1)); + results.push_back(entry); + } + else if (sItem == "genboinckey") + { + //Gridcoin - R Halford - Generate Boinc Mining Key - 2-6-2015 + GetNextProject(false); + std::string email = GetArgument("email", "NA"); + boost::to_lower(email); + GlobalCPUMiningCPID.email=email; + GlobalCPUMiningCPID.cpidv2 = ComputeCPIDv2(GlobalCPUMiningCPID.email, GlobalCPUMiningCPID.boincruntimepublickey, 0); + //Store the BPK in the aesskein, and the cpid in version + GlobalCPUMiningCPID.aesskein = email; //Good + GlobalCPUMiningCPID.lastblockhash = GlobalCPUMiningCPID.cpidhash; + + //block version not needed for keys for now + std::string sParam = SerializeBoincBlock(GlobalCPUMiningCPID,7); + if (fDebug3) printf("GenBoincKey: Utilizing email %s with %s for %s \r\n",GlobalCPUMiningCPID.email.c_str(),GlobalCPUMiningCPID.boincruntimepublickey.c_str(),sParam.c_str()); + std::string sBase = EncodeBase64(sParam); + entry.push_back(Pair("[Specify in config file without quotes] boinckey=",sBase)); + results.push_back(entry); + } + else if (sItem == "encryptphrase") + { + if (params.size() != 2) + { + entry.push_back(Pair("Error","You must specify a phrase")); + results.push_back(entry); + } + else + { + std::string sParam1 = params[1].get_str(); + entry.push_back(Pair("Param1",sParam1)); + std::string test = AdvancedCrypt(sParam1); + entry.push_back(Pair("EncPhrase",test)); + results.push_back(entry); + + } + + } + + else if (sItem == "decryptphrase") + { + if (params.size() != 2) + { + entry.push_back(Pair("Error","You must specify a phrase")); + results.push_back(entry); + } + else + { + std::string sParam1 = params[1].get_str(); + entry.push_back(Pair("Param1",sParam1)); + std::string test = AdvancedDecrypt(sParam1); + entry.push_back(Pair("DecPhrase",test)); + results.push_back(entry); + } + } + else if (sItem == "dportally") + { + TallyMagnitudesInSuperblock(); + entry.push_back(Pair("Done","Done")); + results.push_back(entry); - EnsureWalletIsUnlocked(); - // Check funds - double dBalance = GetTotalBalance(); - if (dTotalToSend > dBalance) - throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); - // Send - CReserveKey keyChange(pwalletMain); - int64_t nFeeRequired = 0; - bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired); - printf("Transaction Created."); - if (!fCreated) + } + else if (sItem == "addkey") { - if (totalAmount + nFeeRequired > pwalletMain->GetBalance()) - throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds"); - throw JSONRPCError(RPC_WALLET_ERROR, "Transaction creation failed"); + //To whitelist a project: + //execute addkey add project projectname 1 + //To blacklist a project: + //execute addkey delete project projectname 1 + //Key examples: + + //execute addkey add project milky 1 + //execute addkey delete project milky 1 + //execute addkey add project milky 2 + //execute addkey add price grc .0000046 + //execute addkey add price grc .0000045 + //execute addkey delete price grc .0000045 + //GRC will only memorize the *last* value it finds for a key in the highest block + + //execute memorizekeys + //execute listdata project + //execute listdata price + + if (params.size() != 5) + { + entry.push_back(Pair("Error","You must specify an action, message type, message name and value.")); + entry.push_back(Pair("Example","execute addkey add_or_delete keytype projectname value.")); + results.push_back(entry); + } + else + { + //execute addkey add project grid20 + std::string sAction = params[1].get_str(); + entry.push_back(Pair("Action",sAction)); + bool bAdd = (sAction=="add") ? true : false; + std::string sType = params[2].get_str(); + entry.push_back(Pair("Type",sType)); + std::string sPass = ""; + sPass = (sType=="project" || sType=="projectmapping") ? GetArgument("masterprojectkey", msMasterMessagePrivateKey) : msMasterMessagePrivateKey; + if (sType=="beacon" && sAction=="delete") sPass = GetArgument("masterprojectkey",""); + entry.push_back(Pair("Passphrase",sPass)); + std::string sName = params[3].get_str(); + entry.push_back(Pair("Name",sName)); + std::string sValue = params[4].get_str(); + entry.push_back(Pair("Value",sValue)); + std::string result = AddMessage(bAdd,sType,sName,sValue,sPass,AmountFromValue(5),.1,""); + entry.push_back(Pair("Results",result)); + results.push_back(entry); + } } - printf("Committing."); - // Rain the recipients - if (!pwalletMain->CommitTransaction(wtx, keyChange)) + else if (sItem == "sendrawcontract") { - printf("Commit failed."); - throw JSONRPCError(RPC_WALLET_ERROR, "Transaction commit failed"); + if (params.size() != 2) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "You must specify raw contract."); + if (pwalletMain->IsLocked()) + throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); + std::string sAddress = GetBurnAddress(); + CBitcoinAddress address(sAddress); + if (!address.IsValid()) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Gridcoin address"); + std::string sContract = params[1].get_str(); + entry.push_back(Pair("Contract",sContract)); + entry.push_back(Pair("Recipient",sAddress)); + int64_t nAmount = CENT; + // Wallet comments + CWalletTx wtx; + wtx.hashBoinc = sContract; + string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx, false); + if (!strError.empty()) + throw JSONRPCError(RPC_WALLET_ERROR, strError); + entry.push_back(Pair("TrxID",wtx.GetHash().GetHex())); + results.push_back(entry); } - std::string sNarr = "Rain successful: Sent " + wtx.GetHash().GetHex() + "."; - printf("Success %s",sNarr.c_str()); - res.push_back(Pair("Response", sNarr)); + else if (sItem == "memorizekeys") + { + std::string sOut = ""; + LoadAdminMessages(true,sOut); + entry.push_back(Pair("Results",sOut)); + results.push_back(entry); - return res; -} + } + else if (sItem == "superblockaverage") + { + std::string superblock = ReadCache("superblock","all").value; + double out_beacon_count = 0; + double out_participant_count = 0; + double out_avg = 0; + double avg = GetSuperblockAvgMag(superblock,out_beacon_count,out_participant_count,out_avg,false,nBestHeight); + entry.push_back(Pair("avg",avg)); + entry.push_back(Pair("beacon_count",out_beacon_count)); + entry.push_back(Pair("beacon_participant_count",out_participant_count)); + entry.push_back(Pair("average_magnitude",out_avg)); + entry.push_back(Pair("superblock_valid", VerifySuperblock(superblock, pindexBest))); + int64_t superblock_age = GetAdjustedTime() - ReadCache("superblock", "magnitudes").timestamp; + entry.push_back(Pair("Superblock Age",superblock_age)); + bool bDireNeed = NeedASuperblock(); + entry.push_back(Pair("Dire Need of Superblock",bDireNeed)); + results.push_back(entry); + } + else if (sItem == "currentcontractaverage") + { + std::string contract = NN::GetNeuralContract(); + entry.push_back(Pair("Contract",contract)); + double out_beacon_count = 0; + double out_participant_count = 0; + double out_avg = 0; + double avg = GetSuperblockAvgMag(contract,out_beacon_count,out_participant_count,out_avg,false,nBestHeight); + bool bValid = VerifySuperblock(contract, pindexBest); + entry.push_back(Pair("avg",avg)); + entry.push_back(Pair("beacon_count",out_beacon_count)); + entry.push_back(Pair("avg_mag",out_avg)); + entry.push_back(Pair("beacon_participant_count",out_participant_count)); + entry.push_back(Pair("superblock_valid",bValid)); + //Show current contract neural hash + std::string sNeuralHash = NN::GetNeuralHash(); + entry.push_back(Pair(".NET Neural Hash",sNeuralHash.c_str())); + entry.push_back(Pair("Length",(double)contract.length())); + std::string neural_hash = GetQuorumHash(contract); + entry.push_back(Pair("Wallet Neural Hash",neural_hash)); -Value unspentreport(const json_spirit::Array& params, bool fHelp) -{ - if (fHelp || params.size() > 0) - throw runtime_error( - "unspentreport\n"); + results.push_back(entry); - LOCK2(cs_main, pwalletMain->cs_wallet); + } + else if (sItem == "getlistof") + { + if (params.size() != 2) + { + entry.push_back(Pair("Error","You must specify a keytype.")); + results.push_back(entry); + } + else + { + std::string sType = params[1].get_str(); + entry.push_back(Pair("Key Type", sType)); + entry.push_back(Pair("Data", GetListOf(sType))); + results.push_back(entry); + } - Array aUnspentReport = GetJsonUnspentReport(); - return aUnspentReport; -} + } + else if (sItem == "listdata") + { + if (params.size() != 2) + { + entry.push_back(Pair("Error","You must specify a keytype (IE execute dumpkeys project)")); + results.push_back(entry); + } + else + { + std::string sType = params[1].get_str(); + entry.push_back(Pair("Key Type",sType)); + for(const auto& item : ReadCacheSection(sType)) + entry.push_back(Pair(item.first, item.second.value)); -Array LifetimeReport(std::string cpid) -{ - Array results; - Object c; - std::string Narr = ToString(GetAdjustedTime()); - c.push_back(Pair("Lifetime Payments Report",Narr)); - results.push_back(c); - Object entry; - CBlockIndex* pindex = pindexGenesisBlock; - while (pindex->nHeight < pindexBest->nHeight) - { - pindex = pindex->pnext; - if (pindex==NULL || !pindex->IsInMainChain()) continue; - if (pindex == pindexBest) break; - if (pindex->GetCPID() == cpid && (pindex->nResearchSubsidy > 0)) + results.push_back(entry); + } + + } + else if (sItem == "genorgkey") + { + if (params.size() != 3) + { + entry.push_back(Pair("Error","You must specify a passphrase and organization name")); + results.push_back(entry); + } + else + { + std::string sParam1 = params[1].get_str(); + entry.push_back(Pair("Passphrase",sParam1)); + std::string sParam2 = params[2].get_str(); + entry.push_back(Pair("OrgName",sParam2)); + + std::string sboinchashargs = LegacyDefaultBoincHashArgs(); + if (sParam1 != sboinchashargs) + { + entry.push_back(Pair("Error","Admin must be logged in")); + } + else { - entry.push_back(Pair(RoundToString((double)pindex->nHeight,0), RoundToString(pindex->nResearchSubsidy,2))); + std::string modulus = sboinchashargs.substr(0,12); + std::string key = sParam2 + "," + AdvancedCryptWithSalt(modulus,sParam2); + entry.push_back(Pair("OrgKey",key)); } + results.push_back(entry); - } - //8-14-2015 - StructCPID stCPID = GetInitializedStructCPID2(cpid,mvResearchAge); - entry.push_back(Pair("Average Magnitude",stCPID.ResearchAverageMagnitude)); - results.push_back(entry); - return results; + } -} + } + else if (sItem == "testorgkey") + { + if (params.size() != 3) + { + entry.push_back(Pair("Error","You must specify an org and public key")); + results.push_back(entry); + } + else + { + std::string sParam1 = params[1].get_str(); + entry.push_back(Pair("Org",sParam1)); + std::string sParam2 = params[2].get_str(); + entry.push_back(Pair("Key",sParam2)); + std::string key = sParam1 + "," + AdvancedDecryptWithSalt(sParam2,sParam1); + entry.push_back(Pair("PubKey",key)); + results.push_back(entry); + + } + + } + else if (sItem == "reindex") + { + int r = Restarter::CreateGridcoinRestorePoint(); + Restarter::ReindexGridcoinWallet(); + entry.push_back(Pair("Reindex Chain",r)); + results.push_back(entry); + } + /*else if (sItem == "downloadblocks") + { + int r=Restarter::DownloadGridcoinBlocks(); + entry.push_back(Pair("Download Blocks",r)); + results.push_back(entry); + }*/ + else if (sItem == "getnextproject") + { + GetNextProject(true); + entry.push_back(Pair("GetNext",1)); + results.push_back(entry); + } + else if (sItem == "resetcpids") + { + //Reload the config file + ReadConfigFile(mapArgs, mapMultiArgs); + HarvestCPIDs(true); + GetNextProject(true); + entry.push_back(Pair("Reset",1)); + results.push_back(entry); + } + else if (sItem == "encrypt_deprecated") + { + std::string s1 = "1234"; + std::string s1dec = AdvancedCrypt(s1); + std::string s1out = AdvancedDecrypt(s1dec); + entry.push_back(Pair("Execute Encrypt result1",s1)); + entry.push_back(Pair("Execute Encrypt result2",s1dec)); + entry.push_back(Pair("Execute Encrypt result3",s1out)); + results.push_back(entry); + } + else if (sItem == "debug") + { + if (params.size() == 2 && (params[1].get_str() == "true" || params[1].get_str() == "false")) + { + fDebug = (params[1].get_str() == "true") ? true : false; + entry.push_back(Pair("Debug", fDebug ? "Entering debug mode." : "Exiting debug mode.")); + } + else + entry.push_back(Pair("Error","You must specify true or false as an option.")); + results.push_back(entry); + } + else if (sItem == "debugnet") + { + if (params.size() == 2 && (params[1].get_str() == "true" || params[1].get_str() == "false")) + { + fDebugNet = (params[1].get_str() == "true") ? true : false; + entry.push_back(Pair("DebugNet", fDebugNet ? "Entering debug mode." : "Exiting debug mode.")); + } + else + entry.push_back(Pair("Error","You must specify true or false as an option.")); + results.push_back(entry); + } + else if (sItem == "debug2") + { + if (params.size() == 2 && (params[1].get_str() == "true" || params[1].get_str() == "false")) + { + fDebug2 = (params[1].get_str() == "true") ? true : false; + entry.push_back(Pair("Debug2", fDebug2 ? "Entering debug mode." : "Exiting debug mode.")); + } + else + entry.push_back(Pair("Error","You must specify true or false as an option.")); + results.push_back(entry); + } + else if (sItem == "debug3") + { + if (params.size() == 2 && (params[1].get_str() == "true" || params[1].get_str() == "false")) + { + fDebug3 = (params[1].get_str() == "true") ? true : false; + entry.push_back(Pair("Debug3", fDebug3 ? "Entering debug mode." : "Exiting debug mode.")); + } + else + entry.push_back(Pair("Error","You must specify true or false as an option.")); + results.push_back(entry); + } + else if (sItem == "debug10") + { + if (params.size() == 2 && (params[1].get_str() == "true" || params[1].get_str() == "false")) + { + fDebug10 = (params[1].get_str() == "true") ? true : false; + entry.push_back(Pair("Debug10", fDebug10 ? "Entering debug mode." : "Exiting debug mode.")); + } + else + entry.push_back(Pair("Error","You must specify true or false as an option.")); + results.push_back(entry); + } + else if (sItem == "help") + { + entry.push_back(Pair("execute addpoll <days> <question> <answers> <sharetype> <url>", "Add a poll (Requires minimum 100000 GRC balance)")); + entry.push_back(Pair("execute advertisebeacon", "Advertise a beacon (Requires wallet to be fully unlocked)")); + entry.push_back(Pair("execute askforoutstandingblocks", "Asks nodes for outstanding blocks")); + entry.push_back(Pair("execute backupprivatekeys", "Backup private keys (Wallet must be fully unlocked")); + entry.push_back(Pair("execute beaconreport", "Displays information about current active beacons in the network")); + entry.push_back(Pair("execute beaconstatus", "Displays information about your beacon")); + entry.push_back(Pair("execute burn <burnaddress> <burnamount> <burnkey> <burndetail>", "Burn coins for contract")); + entry.push_back(Pair("execute cleanchain", "Cleans current chain and attempts to reorganize")); + entry.push_back(Pair("execute currentneuralhash", "Displays the popular hash in current neural report from all neural nodes")); + entry.push_back(Pair("execute currentneuralreport", "Displays all hashes staked recently by neural nodes")); + entry.push_back(Pair("execute debug <true/false>", "Turn on/off debug messages on the fly")); + entry.push_back(Pair("execute debug2 <true/false>", "Turn on/off debug2 messages on the fly")); + entry.push_back(Pair("execute debug3 <true/false>", "Turn on/off debug3 messages on the fly")); + entry.push_back(Pair("execute debug10 <true/false>", "Turn on/off debug10 messages on the fly")); + entry.push_back(Pair("execute debugnew <true/false>", "Turn on/off debugnet messages on the fly")); + entry.push_back(Pair("execute decryptphrase <phrase>", "Decrypt an encrypted phrase")); + //entry.push_back(Pair("execute downloadblocks", "Download blocks from blockchain")); + entry.push_back(Pair("execute dportally", "Tally magnitudes in superblock")); + entry.push_back(Pair("execute encrypt <phrase>", "Encrypt a wallet pass phrase (autounlock feature)")); + entry.push_back(Pair("execute encryptphrase <phrase>", "Encrypt a phrase or message")); + entry.push_back(Pair("execute listallpolldetails", "Displays all polls past and present with details")); + entry.push_back(Pair("execute listallpolls", "Displays all polls past and present")); + entry.push_back(Pair("execute listpolldetails", "Displays all active polls details")); + entry.push_back(Pair("execute listpollresults <title> <true>", "Displays poll results for specified title. True is optional for expired polls")); + entry.push_back(Pair("execute listpolls", "Displays all active polls")); + entry.push_back(Pair("execute myneuralhash", "Displays your current neural hash from contract")); + entry.push_back(Pair("execute neuralhash", "Displays the network popular hash in neural report (Participating nodes)")); + entry.push_back(Pair("execute neuralreport", "Displays information of recently staked neural votes by participating nodes")); + entry.push_back(Pair("execute neuralresponse", "Requests a response from neural network")); + entry.push_back(Pair("execute rain <raindata>", "Sends rain to specified users. Format Address<COL>Amount<ROW>...")); + entry.push_back(Pair("execute reindex", "Reindex blockchain")); + entry.push_back(Pair("execute resendwallettx", "Resends a wallet tx")); + entry.push_back(Pair("execute resetcpids", "Resets wallet cpids (can be used to correct cpids after a split cpid is fixed)")); + entry.push_back(Pair("execute restart", "Restarts wallet")); + entry.push_back(Pair("execute restorepoint", "Creates a restore point for wallet")); + entry.push_back(Pair("execute staketime", "Displays unix timestamp based on stake gric time and cpid time")); + entry.push_back(Pair("execute superblockage", "Displays information and age about current superblock")); + entry.push_back(Pair("execute syncdpor2", "Synchronize with neural network")); + entry.push_back(Pair("execute tally", "Tallys research averages")); + entry.push_back(Pair("execute tallyneural", "Tally neural quorum data")); + entry.push_back(Pair("execute unspentreport", "Displays unspent wallet information")); + entry.push_back(Pair("execute upgradedbeaconreport", "Displays information about upgraded beacons")); + entry.push_back(Pair("execute updatequorumdata", "Updates neural quorum data")); + entry.push_back(Pair("execute versionreport", "Displays information about client versions that staked the last 100 blocks")); + entry.push_back(Pair("execute vote <title> <answer>", "Casts a vote for a specific poll with chosen answer")); + entry.push_back(Pair("execute votedetails <title>", "Displays information on a specified poll's votes")); + results.push_back(entry); + } + else if (sItem == "helpdev") + { + entry.push_back(Pair("execute addkey <add_or_delete> <keytype> <projectname> <value>", "Add or delete key to network")); + entry.push_back(Pair("execute executecode", "Excute .net code")); + entry.push_back(Pair("execute forcequorum", "Force quorum")); + entry.push_back(Pair("execute gatherneuralhashes", "Gather neural hashes")); + entry.push_back(Pair("execute getlistof <keytype>", "Get list of keytype data")); + entry.push_back(Pair("execute listdata <keytype>", "List data in a keytype")); + entry.push_back(Pair("execute memorizekeys", "Memorize keys from admin messages")); + entry.push_back(Pair("execute readdata <key> <value>", "Display value from a keys data")); + entry.push_back(Pair("execute refhash <grcaddress>", "Check if a grc address is a neural node participant as well as you")); + entry.push_back(Pair("execute sendblock <hash>", "Send a block to network")); + entry.push_back(Pair("execute testnewcontract", "Test current neural contract")); + entry.push_back(Pair("execute writedata <key> <value>", "Write data to a key with value")); + results.push_back(entry); + } +else + { + entry.push_back(Pair("Command " + sItem + " not found.",-1)); + results.push_back(entry); + } + return results; +} +>>>>>>> latest changes Array SuperblockReport(std::string cpid) { @@ -2645,50 +3990,6 @@ Value listitem(const Array& params, bool fHelp) results.push_back(entry); } - else if (sitem == "explainmagnitude") - { - Object entry; - - bool bForce = false; - - if (params.size() == 2) - { - std::string sOptional = params[1].get_str(); - - boost::to_lower(sOptional); - - if (sOptional == "true") - bForce = true; - } - - if (bForce) - { - if (msNeuralResponse.length() < 25) - { - entry.push_back(Pair("Neural Response", "Empty; Requesting a response..")); - entry.push_back(Pair("WARNING", "Only force once and try again without force if response is not received. Doing too many force attempts gets a temporary ban from neural node responses")); - - msNeuralResponse = ""; - - AsyncNeuralRequest("explainmag", GlobalCPUMiningCPID.cpid, 10); - } - } - - if (msNeuralResponse.length() > 25) - { - entry.push_back(Pair("Neural Response", "true")); - - std::vector<std::string> vMag = split(msNeuralResponse.c_str(),"<ROW>"); - - for (unsigned int i = 0; i < vMag.size(); i++) - entry.push_back(Pair(RoundToString(i+1,0),vMag[i].c_str())); - } - - else - entry.push_back(Pair("Neural Response", "false; Try again at a later time")); - - results.push_back(entry); - } else if (sitem == "superblocks") { std::string cpid = ""; @@ -2700,41 +4001,6 @@ Value listitem(const Array& params, bool fHelp) results = SuperblockReport(cpid); return results; } - else if (sitem == "magnitude") - { - std::string cpid = ""; - if (params.size() == 2) - { - cpid = params[1].get_str(); - } - - if (params.size() > 2) - { - Object entry; - entry.push_back(Pair("Error","You must either specify 'list magnitude' to see the entire report, or 'list magnitude CPID' to see a specific CPID.")); - results.push_back(entry); - return results; - } - results = MagnitudeReport(cpid); - if (results.size() > 1000) - { - results.clear(); - Object entry; - entry.push_back(Pair("Error","Magnitude report too large; try specifying the cpid : list magnitude cpid.")); - results.push_back(entry); - return results; - } - return results; - } - else if (sitem == "lifetime") - { - std::string cpid = msPrimaryCPID; - if (params.size() == 2) - { - cpid = params[1].get_str(); - } - - results = LifetimeReport(cpid); return results; } else if (sitem == "currenttime") @@ -2762,11 +4028,6 @@ Value listitem(const Array& params, bool fHelp) entry.push_back(Pair("manifest",sManifest)); results.push_back(entry); } - else if (sitem == "mymagnitude") - { - results = MagnitudeReport(msPrimaryCPID); - return results; - } else if (sitem == "memorypool") { Object entry; @@ -2879,43 +4140,6 @@ Value listitem(const Array& params, bool fHelp) } - } - else if (sitem=="cpids") - { - //Dump vectors: - - if (mvCPIDs.size() < 1) - { - HarvestCPIDs(false); - } - LogPrintf ("generating cpid report %s",sitem); - - for(map<string,StructCPID>::iterator ii=mvCPIDs.begin(); ii!=mvCPIDs.end(); ++ii) - { - - StructCPID structcpid = mvCPIDs[(*ii).first]; - - if (structcpid.initialized) - { - - if ((GlobalCPUMiningCPID.cpid.length() > 3 && - structcpid.cpid == GlobalCPUMiningCPID.cpid) - || !IsResearcher(structcpid.cpid) || !IsResearcher(GlobalCPUMiningCPID.cpid)) - { - Object entry; - entry.push_back(Pair("Project",structcpid.projectname)); - entry.push_back(Pair("CPID",structcpid.cpid)); - entry.push_back(Pair("RAC",structcpid.rac)); - entry.push_back(Pair("Team",structcpid.team)); - entry.push_back(Pair("CPID Link",structcpid.link)); - entry.push_back(Pair("Debug Info",structcpid.errors)); - entry.push_back(Pair("Project Settings Valid for Gridcoin",structcpid.Iscpidvalid)); - results.push_back(entry); - } - - } - } - } else if (sitem == "help") { diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 8810834c2d..982dca202d 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -26,7 +26,9 @@ Value getmininginfo(const Array& params, bool fHelp) if (fHelp || params.size() != 0) throw runtime_error( "getmininginfo\n" - "Returns an object containing mining-related information."); + "Returns an object containing mining-related information.\n"); + + LOCK2(cs_main, pwalletMain->cs_wallet); uint64_t nWeight = 0; int64_t nTime= GetAdjustedTime(); diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 33f13dc289..b23534d254 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -1956,7 +1956,7 @@ Value walletlock(const Array& params, bool fHelp) Value encryptwallet(const Array& params, bool fHelp) { - if (!pwalletMain->IsCrypted() && (fHelp || params.size() != 1)) + if (fHelp || params.size() != 1) throw runtime_error( "encryptwallet <passphrase>\n" "Encrypts the wallet with <passphrase>.\n"); From 2069cba9b059f98a6173fe44d49032604f38b848 Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Sun, 18 Feb 2018 17:15:48 -0800 Subject: [PATCH 08/28] Add debug4 for rpc response times --- src/util.cpp | 1 + src/util.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/util.cpp b/src/util.cpp index 240bb1dcf2..eda1eb825f 100755 --- a/src/util.cpp +++ b/src/util.cpp @@ -69,6 +69,7 @@ bool fDebug = false; bool fDebugNet = false; bool fDebug2 = false; bool fDebug3 = false; +bool fDebug4 = false; bool fDebug10 = false; bool fPrintToConsole = false; diff --git a/src/util.h b/src/util.h index 2dd11e82ab..35a56975ef 100755 --- a/src/util.h +++ b/src/util.h @@ -88,6 +88,7 @@ extern bool fDebug; extern bool fDebugNet; extern bool fDebug2; extern bool fDebug3; +extern bool fDebug4; extern bool fDebug10; extern bool fPrintToConsole; From 2b95193a9dc2d2ef8f3583d6108766c753040adb Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Sun, 18 Feb 2018 17:16:16 -0800 Subject: [PATCH 09/28] .. --- src/init.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/init.cpp b/src/init.cpp index 7a90e99c85..6cfc9973f5 100755 --- a/src/init.cpp +++ b/src/init.cpp @@ -421,11 +421,18 @@ bool AppInit2(ThreadHandlerPtr threads) } fDebug3 = false; + if (GetArg("-debug3", "false")=="true") { fDebug3 = true; LogPrintf("Entering GRC debug mode 3.\n"); } + + fDebug4 = GetBoolArg("-debug4"); + + if (fDebug4) + printf("Entering RPC time debug mode\r\n"); + fDebug10= (GetArg("-debug10","false")=="true"); #if !defined(WIN32) && !defined(QT_GUI) From afa5e0872b88d0ed683f53125ecb57ddad2820f2 Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Sun, 25 Feb 2018 22:57:32 -0800 Subject: [PATCH 10/28] complete mining category --- src/bitcoinrpc.cpp | 20 +-- src/bitcoinrpc.h | 12 +- src/rpcblockchain.cpp | 392 +++++++++++++++++++++++++++--------------- 3 files changed, 271 insertions(+), 153 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 23df913a5c..be5ca5ef10 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -341,17 +341,17 @@ static const CRPCCommand vRPCCommands[] = { "mymagnitude", &mymagnitude, true, cat_mining }, #ifdef WIN32 { "myneuralhash", &myneuralhash, true, cat_mining }, -#endif { "neuralhash", &neuralhash, true, cat_mining }, - {}, - {}, - {}, - {}, - {}, - {}, - {}, - {}, - {}, +#endif + { "proveownership", &proveownership, true, cat_mining }, + { "rsa", &rsa, true, cat_mining }, + { "rsaweight", &rsaweight, true, cat_mining }, + { "staketime", &staketime, false, cat_mining }, + { "superblockage", &superblockage, true, cat_mining }, + { "superblocks", &superblocks, true, cat_mining }, + { "syncdpor2", &syncdpor2, false, cat_mining }, + { "upgradedbeaconreport", &upgradedbeaconreport, true, cat_mining }, + { "validcpids", &validcpids, true, cat_mining }, {}, {}, {}, diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 97098d4708..f1b2cb490b 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -224,8 +224,18 @@ extern json_spirit::Value magnitude(const json_spirit::Array& params, bool fHelp extern json_spirit::Value mymagnitude(const json_spirit::Array& params, bool fHelp); #ifdef WIN32 extern json_spirit::Value myneuralhash(const json_spirit::Array& params, bool fHelp); -#endif extern json_spirit::Value neuralhash(const json_spirit::Array& params, bool fHelp); +#endif +extern json_spirit::Value neuralreport(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value proveownership(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value rsa(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value rsaweight(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value staketime(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value superblockage(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value superblocks(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value syncdpor2(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value upgradedbeaconreport(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value validcpids(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 93b39bc905..ecda385143 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1619,8 +1619,11 @@ Value magnitude(const json_spirit::Array& params, bool fHelp) if (results.size() > 1000) { results.clear(); + Object entry; + entry.push_back(Pair("Error","Magnitude report too large; try specifying the cpid : magnitude <cpid>.")); + results.push_back(entry); } @@ -1640,7 +1643,9 @@ Value mymagnitude(const Array& params, bool fHelp) if (msPrimaryCPID.empty()) { Object res; + res.push_back(Pair("Error", "Your CPID appears to be empty")); + results.push_back(res); } @@ -1666,7 +1671,6 @@ Value myneuralhash(const Array& params, bool fHelp) return res; } -#endif Value neuralhash(const Array& params, bool fHelp) { @@ -1683,6 +1687,251 @@ Value neuralhash(const Array& params, bool fHelp) return res; } +#endif + +Value neuralreport(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "neuralreport\n" + "\n" + "Displays neural report for the network\n"); + + Object res; + + Array myNeuralJSON = GetJSONNeuralNetworkReport(); + res.push_back(myNeuralJSON); + + return res; +} + +Value proveownership(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "proveownership\n" + "\n" + "Prove ownership of your CPID\n"); + + Object res; + + HarvestCPIDs(true); + GetNextProject(true); + std::string email = GetArgument("email", "NA"); + boost::to_lower(email); + + res.push_back(Pair("Boinc E-Mail", email)); + res.push_back(Pair("Boinc Public Key", GlobalCPUMiningCPID.boincruntimepublickey)); + res.push_back(Pair("CPID", GlobalCPUMiningCPID.cpid)); + + std::string sLongCPID = ComputeCPIDv2(email, GlobalCPUMiningCPID.boincruntimepublickey,1); + std::string sShortCPID = RetrieveMd5(GlobalCPUMiningCPID.boincruntimepublickey + email); + std::string sEmailMD5 = RetrieveMd5(email); + std::string sBPKMD5 = RetrieveMd5(GlobalCPUMiningCPID.boincruntimepublickey); + + res.push_back(Pair("Computed Email Hash", sEmailMD5)); + res.push_back(Pair("Computed BPK", sBPKMD5)); + res.push_back(Pair("Computed CPID", sLongCPID)); + res.push_back(Pair("Computed Short CPID", sShortCPID)); + + bool fResult = CPID_IsCPIDValid(sShortCPID, sLongCPID, 1); + + if (GlobalCPUMiningCPID.boincruntimepublickey.empty()) + { + fResult = false; + res.push_back(Pair("Error", "Boinc Public Key empty. Try mounting your boinc project first, and ensure the gridcoin datadir setting is set if boinc is not in the default location.")); + } + + res.push_back(Pair("CPID Valid", fResult)); + + return res; +} + +Value rsa(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "rsa\n" + "\n" + "Displays RSA report for your CPID\n"); + + Object res; + + if (msPrimaryCPID.empty() || msPrimaryCPID == "INVESTOR") + throw runtime_error( + "PrimaryCPID is empty or INVESTOR; No RSA available for this condition\n"); + + res = MagnitudeReport(msPrimaryCPID); + + return res; +} + +Value rsaweight(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "rsaweight\n" + "\n" + "Display Rsaweight for your CPID\n"); + + Object res; + + double out_magnitude = 0; + double out_owed = 0; + int64_t RSAWEIGHT = GetRSAWeightByCPID(GlobalCPUMiningCPID.cpid); + out_magnitude = GetUntrustedMagnitude(GlobalCPUMiningCPID.cpid, out_owed); + + res.push_back(Pair("RSA Weight", RSAWEIGHT)); + res.push_back(Pair("Magnitude", out_magnitude)); + res.push_back(Pair("RSA Owed", out_owed)); + + return res; +} + +Value staketime(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "staketime\n" + "\n" + "Display information about staking time\n"); + + Object res; + + std::string cpid = GlobalCPUMiningCPID.cpid; + std::string GRCAddress = DefaultWalletAddress(); + GetEarliestStakeTime(GRCAddress, cpid); + + res.push_back(Pair("GRCTime", ReadCache("global", "nGRCTime").timestamp)); + res.push_back(Pair("CPIDTime", ReadCache("global", "nCPIDTime").timestamp)); + + return res; +} + +Value superblockage(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "superblockage\n" + "\n" + "Display information regarding superblock age\n"); + + Object res; + + int64_t superblock_time = ReadCache("superblock", "magnitudes").timestamp; + int64_t superblock_age = GetAdjustedTime() - superblock_time; + + res.push_back(Pair("Superblock Age", superblock_age)); + res.push_back(Pair("Superblock Timestamp", TimestampToHRDate(superblock_time))); + res.push_back(Pair("Superblock Block Number", ReadCache("superblock", "block_number").value)); + res.push_back(Pair("Pending Superblock Height", ReadCache("neuralsecurity", "pending").value)); + + return res; +} + +Value superblocks(const Array& params, fHelp) +{ + if (fHelp || params.size() > 1) + throw runtime_error( + "superblocks <cpid>\n" + "\n" + "<cpid> -> Optional: Shows magnitude for a cpid for recent superblocks\n" + "Display data on recent superblocks\n"); + + Object res; + + std::string cpid = ""; + + if (params.size() > 0) + cpid = params[0].get_str(); + + res = SuperblockReport(cpid); + + return res; +} + +Value syncdpor2(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "syncdpor2\n" + "\n" + "Syncronize with the neural network\n"); + + Object res; + + std::string sOut = ""; + + bool bFull = GetCountOf("beacon") < 50 ? true : false; + + LoadAdminMessages(bFull, sOut); + FullSyncWithDPORNodes(); + + res.push_back(Pair("Syncing", 1)); + + return res; +} + +Value upgradedbeaconreport(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "upgradedbeaconreport\n" + "\n" + "Display upgraded beacon report of the network\n"); + + Array aUpgBR = GetUpgradedBeaconReport(); + + return aUpgBR; +} + +Value validcpids(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "validcpids\n" + "\n" + "Displays information about valid CPIDs collected from BOINC\n"); + + Object res; + + //Dump vectors: + if (mvCPIDs.size() < 1) + HarvestCPIDs(false); + + for(map<string,StructCPID>::iterator ii=mvCPIDs.begin(); ii!=mvCPIDs.end(); ++ii) + { + StructCPID structcpid = mvCPIDs[(*ii).first]; + + if (structcpid.initialized) + { + if (structcpid.cpid == GlobalCPUMiningCPID.cpid || !IsResearcher(structcpid.cpid)) + { + if (structcpid.verifiedteam == "gridcoin") + { + Object entry; + + entry.push_back(Pair("Project", structcpid.projectname)); + entry.push_back(Pair("CPID", structcpid.cpid)); + entry.push_back(Pair("CPIDhash", structcpid.cpidhash)); + entry.push_back(Pair("Email", structcpid.emailhash)); + entry.push_back(Pair("UTC", structcpid.utc)); + entry.push_back(Pair("RAC", structcpid.rac)); + entry.push_back(Pair("Team", structcpid.team)); + entry.push_back(Pair("RecTime", structcpid.rectime)); + entry.push_back(Pair("Age", structcpid.age)); + entry.push_back(Pair("Is my CPID Valid?", structcpid.Iscpidvalid)); + entry.push_back(Pair("CPID Link", structcpid.link)); + entry.push_back(Pair("Errors", structcpid.errors)); + + res.push_back(entry); + } + } + } + } + + return res; +} Value execute(const Array& params, bool fHelp) { @@ -1733,33 +1982,6 @@ Value execute(const Array& params, bool fHelp) entry.push_back(Pair("Result",fResult)); results.push_back(entry); } - else if (sItem=="proveownership") - { - HarvestCPIDs(true); - GetNextProject(true); - std::string email = GetArgument("email", "NA"); - boost::to_lower(email); - entry.push_back(Pair("Boinc E-Mail",email)); - entry.push_back(Pair("Boinc Public Key",GlobalCPUMiningCPID.boincruntimepublickey)); - entry.push_back(Pair("CPID",GlobalCPUMiningCPID.cpid)); - std::string sLongCPID = ComputeCPIDv2(email,GlobalCPUMiningCPID.boincruntimepublickey,1); - std::string sShortCPID = RetrieveMd5(GlobalCPUMiningCPID.boincruntimepublickey + email); - std::string sEmailMD5 = RetrieveMd5(email); - std::string sBPKMD5 = RetrieveMd5(GlobalCPUMiningCPID.boincruntimepublickey); - entry.push_back(Pair("Computed Email Hash",sEmailMD5)); - entry.push_back(Pair("Computed BPK",sBPKMD5)); - - entry.push_back(Pair("Computed CPID",sLongCPID)); - entry.push_back(Pair("Computed Short CPID", sShortCPID)); - bool fResult = CPID_IsCPIDValid(sShortCPID,sLongCPID,1); - if (GlobalCPUMiningCPID.boincruntimepublickey.empty()) - { - fResult=false; - entry.push_back(Pair("Error","Boinc Public Key empty. Try mounting your boinc project first, and ensure the gridcoin datadir setting is set if boinc is not in the default location.")); - } - entry.push_back(Pair("CPID Valid",fResult)); - results.push_back(entry); - } else if (sItem == "neuralrequest") { @@ -1768,15 +1990,6 @@ Value execute(const Array& params, bool fHelp) results.push_back(entry); } - else if (sItem == "syncdpor2") - { - std::string sOut = ""; - bool bFull = GetCountOf("beacon") < 50 ? true : false; - LoadAdminMessages(bFull,sOut); - FullSyncWithDPORNodes(); - entry.push_back(Pair("Syncing",1)); - results.push_back(entry); - } else if(sItem=="gatherneuralhashes") { GatherNeuralHashes(); @@ -1784,16 +1997,6 @@ Value execute(const Array& params, bool fHelp) results.push_back(entry); } - else if (sItem == "upgradedbeaconreport") - { - Array aUpgBR = GetUpgradedBeaconReport(); - results.push_back(aUpgBR); - } - else if (sItem == "neuralreport") - { - Array myNeuralJSON = GetJSONNeuralNetworkReport(); - results.push_back(myNeuralJSON); - } else if (sItem == "tallyneural") { ComputeNeuralNetworkSupermajorityHashes(); @@ -1806,17 +2009,6 @@ Value execute(const Array& params, bool fHelp) Array myNeuralJSON = GetJSONVersionReport(); results.push_back(myNeuralJSON); } - } - else if (sItem == "superblockage") - { - int64_t superblock_time = ReadCache("superblock", "magnitudes").timestamp; - int64_t superblock_age = GetAdjustedTime() - superblock_time; - entry.push_back(Pair("Superblock Age", superblock_age)); - entry.push_back(Pair("Superblock Timestamp", TimestampToHRDate(superblock_time))); - entry.push_back(Pair("Superblock Block Number", ReadCache("superblock", "block_number").value)); - entry.push_back(Pair("Pending Superblock Height", ReadCache("neuralsecurity","pending").value)); - results.push_back(entry); - } else if (sItem == "unusual") { @@ -2194,15 +2386,6 @@ Value execute(const Array& params, bool fHelp) } } } - else if (sItem=="staketime") - { - std::string cpid = GlobalCPUMiningCPID.cpid; - std::string GRCAddress = DefaultWalletAddress(); - GetEarliestStakeTime(GRCAddress,cpid); - entry.push_back(Pair("GRCTime", ReadCache("global", "nGRCTime").timestamp)); - entry.push_back(Pair("CPIDTime",ReadCache("global", "nCPIDTime").timestamp)); - results.push_back(entry); - } else if (sItem=="testnewcontract") { std::string contract = NN::GetNeuralContract(); @@ -3975,34 +4158,6 @@ Value listitem(const Array& params, bool fHelp) entry.push_back(Pair("Network Time",GetAdjustedTime())); results.push_back(entry); } - else if (sitem == "rsaweight") - { - double out_magnitude = 0; - double out_owed = 0; - int64_t RSAWEIGHT = GetRSAWeightByCPID(GlobalCPUMiningCPID.cpid); - out_magnitude = GetUntrustedMagnitude(GlobalCPUMiningCPID.cpid,out_owed); - - - Object entry; - entry.push_back(Pair("RSA Weight",RSAWEIGHT)); - entry.push_back(Pair("Magnitude",out_magnitude)); - entry.push_back(Pair("RSA Owed",out_owed)); - results.push_back(entry); - - } - else if (sitem == "superblocks") - { - std::string cpid = ""; - if (params.size() == 2) - { - cpid = params[1].get_str(); - } - - results = SuperblockReport(cpid); - return results; - } - return results; - } else if (sitem == "currenttime") { @@ -4035,12 +4190,6 @@ Value listitem(const Array& params, bool fHelp) entry.push_back(Pair("Included Tx",msMiningErrorsIncluded)); results.push_back(entry); } - else if (sitem == "rsa") - { - if (msPrimaryCPID=="") msPrimaryCPID="INVESTOR"; - results = MagnitudeReport(msPrimaryCPID); - return results; - } else if (sitem == "projects") { for (const auto& item : ReadCacheSection("project")) @@ -4099,47 +4248,6 @@ Value listitem(const Array& params, bool fHelp) } } return results; - } - else if (sitem=="validcpids") - { - //Dump vectors: - if (mvCPIDs.size() < 1) - { - HarvestCPIDs(false); - } - for(map<string,StructCPID>::iterator ii=mvCPIDs.begin(); ii!=mvCPIDs.end(); ++ii) - { - - StructCPID structcpid = mvCPIDs[(*ii).first]; - - if (structcpid.initialized) - { - - if (structcpid.cpid == GlobalCPUMiningCPID.cpid || !IsResearcher(structcpid.cpid)) - { - if (structcpid.verifiedteam=="gridcoin") - { - Object entry; - entry.push_back(Pair("Project",structcpid.projectname)); - entry.push_back(Pair("CPID",structcpid.cpid)); - entry.push_back(Pair("CPIDhash",structcpid.cpidhash)); - entry.push_back(Pair("Email",structcpid.emailhash)); - entry.push_back(Pair("UTC",structcpid.utc)); - entry.push_back(Pair("RAC",structcpid.rac)); - entry.push_back(Pair("Team",structcpid.team)); - entry.push_back(Pair("RecTime",structcpid.rectime)); - entry.push_back(Pair("Age",structcpid.age)); - entry.push_back(Pair("Is my CPID Valid?",structcpid.Iscpidvalid)); - entry.push_back(Pair("CPID Link",structcpid.link)); - entry.push_back(Pair("Errors",structcpid.errors)); - results.push_back(entry); - } - } - - } - } - - } else if (sitem == "help") { From c0d8dfc73196d22813444a6b994a506c4b1df83e Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Mon, 26 Feb 2018 00:13:57 -0800 Subject: [PATCH 11/28] more of developer category complete --- src/bitcoinrpc.cpp | 37 ++- src/bitcoinrpc.h | 22 +- src/rpcblockchain.cpp | 624 +++++++++++++++++++++++++----------------- 3 files changed, 433 insertions(+), 250 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index be5ca5ef10..e81060860d 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -327,7 +327,7 @@ static const CRPCCommand vRPCCommands[] = { "walletpassphrase", &walletpassphrase, true, cat_wallet }, { "walletpassphrasechange", &walletpassphrasechange, false, cat_wallet }, - // Mining commands + // Mining commands { "advertisebeacon", &advertisebeacon, false, cat_mining }, { "beaconreport", &beaconreport, true, cat_mining }, { "beaconstatus", &beaconstatus, true, cat_mining }, @@ -352,6 +352,31 @@ static const CRPCCommand vRPCCommands[] = { "syncdpor2", &syncdpor2, false, cat_mining }, { "upgradedbeaconreport", &upgradedbeaconreport, true, cat_mining }, { "validcpids", &validcpids, true, cat_mining }, + + // Developer commands + { "addkey", &addkey, false, cat_developer }, +#ifdef WIN32 + { "currentcontractaverage", ¤tcontractaverage, false, cat_developer }, +#endif + { "debug", &debug, true, cat_developer }, + { "debug10", &debug10, true, cat_developer }, + { "debug2", &debug2, true, cat_developer }, + { "debug3", &debug3, true, cat_developer }, + { "debugnet", &debugnet, true, cat_developer }, + { "dportally", &dportally, true, cat_developer }, + { "forcequorom", &forcequorom, true, cat_developer }, + { "gatherneuralhashes", &gatherneuralhashes, true, cat_developer }, + { "genboinckey", &genboinckey, true, cat_developer }, + { "genorgkey", &genorgkey, true, cat_developer }, + { "getblockstats", &rpc_getblockstats, true, cat_developer }, + { "getlistof", &getlistof, true, cat_developer }, + { "getnextproject", &getnextproject, false, cat_developer }, + { "listdata", &listdata, true, cat_developer }, + { "memorizekeys", &memorizekeys, true, cat_developer }, + {}, + {}, + {}, + {}, {}, {}, {}, @@ -439,6 +464,16 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri // Mining if (strMethod == "explainmagnitude" && n > 0) ConvertTo<bool>(params[0]); + + // Developer + if (strMethod == "debug" && n > 0) ConvertTo<bool>(params[0]); + if (strMethod == "debug10" && n > 0) ConvertTo<bool>(params[0]); + if (strMethod == "debug2" && n > 0) ConvertTo<bool>(params[0]); + if (strMethod == "debug3" && n > 0) ConvertTo<bool>(params[0]); + if (strMethod == "debugnet" && n > 0) ConvertTo<bool>(params[0]); + if (strMethod == "getblockstats" && n > 0) ConvertTo<int64_t>(params[0]); + if (strMethod == "getblockstats" && n > 1) ConvertTo<int64_t>(params[1]); + return params; } diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index f1b2cb490b..d7ee1137a2 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -237,6 +237,27 @@ extern json_spirit::Value syncdpor2(const json_spirit::Array& params, bool fHelp extern json_spirit::Value upgradedbeaconreport(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value validcpids(const json_spirit::Array& params, bool fHelp); +// Developers +extern json_spirit::Value addkey(const json_spirit::Array& params, bool fHelp); +#ifdef WIN32 +extern json_spirit::Value currentcontractaverage(const json_spirit::Array& params, bool fHelp); +#endif +extern json_spirit::Value debug(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value debug10(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value debug2(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value debug3(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value debugnet(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value dportally(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value forcequorom(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value gatherneuralhashes(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value genboinckey(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value genorgkey(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value rpc_getblockstats(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getlistof(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getnextproject(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value listdata(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value memorizekeys(const json_spirit::Array& params, bool fHelp); + extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value ping(const json_spirit::Array& params, bool fHelp); @@ -266,7 +287,6 @@ extern json_spirit::Value execute(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value rpc_reorganize(const json_spirit::Array& params, bool fHelp); // Brod -extern json_spirit::Value rpc_getblockstats(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value sendalert2(const json_spirit::Array& params, bool fHelp); // iFoggz diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index ecda385143..ac4d8ba9f9 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1833,9 +1833,9 @@ Value superblocks(const Array& params, fHelp) { if (fHelp || params.size() > 1) throw runtime_error( - "superblocks <cpid>\n" + "superblocks [cpid]\n" "\n" - "<cpid> -> Optional: Shows magnitude for a cpid for recent superblocks\n" + "[cpid] -> Optional: Shows magnitude for a cpid for recent superblocks\n" "Display data on recent superblocks\n"); Object res; @@ -1933,6 +1933,377 @@ Value validcpids(const Array& params, bool fHelp) return res; } +Value addkey(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 4) + throw runtime_error( + "addkey <action> <keytype> <keyname> <keyvalue>\n" + "\n" + "<action> ---> Specify add or delete of key\n" + "<keytype> --> Specify keytype ex: project\n" + "<keyname> --> Specify keyname ex: milky\n" + "<keyvalue> -> Specify keyvalue ex: 1\n" + "Add a key to the network\n"); + + Object res; + + //To whitelist a project: + //execute addkey add project projectname 1 + //To blacklist a project: + //execute addkey delete project projectname 1 + //Key examples: + + //execute addkey add project milky 1 + //execute addkey delete project milky 1 + //execute addkey add project milky 2 + //execute addkey add price grc .0000046 + //execute addkey add price grc .0000045 + //execute addkey delete price grc .0000045 + //GRC will only memorize the *last* value it finds for a key in the highest block + //execute memorizekeys + //execute listdata project + //execute listdata price + //execute addkey add project grid20 + + std::string sAction = params[0].get_str(); + bool bAdd = (sAction == "add") ? true : false; + std::string sType = params[1].get_str(); + std::string sPass = ""; + std::string sName = params[2].get_str(); + std::string sValue = params[3].get_str(); + + sPass = (sType == "project" || sType == "projectmapping" || (sType == "beacon" && sAction == "delete")) ? GetArgument("masterprojectkey", msMasterMessagePrivateKey) : msMasterMessagePrivateKey; + + res.push_back(Pair("Action", sAction)); + res.push_back(Pair("Type", sType)); + res.push_back(Pair("Passphrase", sPass)); + res.push_back(Pair("Name", sName)); + res.push_back(Pair("Value", sValue)); + + std::string result = AddMessage(bAdd, sType, sName, sValue, sPass, AmountFromValue(5), .1, ""); + + res.push_back(Pair("Results", result)); + + return res; +} + +#ifdef WIN32 +Value currentcontractaverage(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "currentcontractaverage\n" + "\n" + "Displays information on your current contract average with regards to superblock contract\n"); + + Object res; + + std::string contract = NN::GetNeuralContract(); + double out_beacon_count = 0; + double out_participant_count = 0; + double out_avg = 0; + double avg = GetSuperblockAvgMag(contract, out_beacon_count, out_participant_count, out_avg, false, nBestHeight); + bool bValid = VerifySuperblock(contract, pindexBest); + //Show current contract neural hash + std::string sNeuralHash = NN::GetNeuralHash(); + std::string neural_hash = GetQuorumHash(contract); + + res.push_back(Pair("Contract", contract)); + res.push_back(Pair("avg", avg)); + res.push_back(Pair("beacon_count", out_beacon_count)); + res.push_back(Pair("avg_mag", out_avg)); + res.push_back(Pair("beacon_participant_count", out_participant_count)); + res.push_back(Pair("superblock_valid", bValid)); + res.push_back(Pair(".NET Neural Hash", sNeuralHash.c_str())); + res.push_back(Pair("Length", (int)contract.length())); + res.push_back(Pair("Wallet Neural Hash", neural_hash)); + + results.push_back(entry); +} +#endif + +Value debug(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "debug <bool>\n" + "\n" + "<bool> -> Specify true or false\n" + "Enable or disable debug mode on the fly\n"); + + Object res; + + fDebug = params[0].get_bool(); + + res.push_back(Pair("Debug", fDebug ? "Entering debug mode." : "Exiting debug mode.")); + + return res; +} + +Value debug10(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "debug10 <bool>\n" + "\n" + "<bool> -> Specify true or false\n" + "Enable or disable debug mode on the fly\n"); + + Object res; + + fDebug10 = params[0].get_bool(); + + res.push_back(Pair("Debug10", fDebug10 ? "Entering debug mode." : "Exiting debug mode.")); + + return res; +} + +Value debug2(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "debug2 <bool>\n" + "\n" + "<bool> -> Specify true or false\n" + "Enable or disable debug mode on the fly\n"); + + Object res; + + fDebug2 = params[0].get_bool(); + + res.push_back(Pair("Debug2", fDebug2 ? "Entering debug mode." : "Exiting debug mode.")); + + return res; +} + +Value debug3(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "debug3 <bool>\n" + "\n" + "<bool> -> Specify true or false\n" + "Enable or disable debug mode on the fly\n"); + + Object res; + + fDebug3 = params[0].get_bool(); + + res.push_back(Pair("Debug3", fDebug3 ? "Entering debug mode." : "Exiting debug mode.")); + + return res; +} + +Value debugnet(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "debugnet <bool>\n" + "\n" + "<bool> -> Specify true or false\n" + "Enable or disable debug mode on the fly\n"); + + Object res; + + fDebugNet = params[0].get_bool(); + + res.push_back(Pair("DebugNet", fDebugNet ? "Entering debug mode." : "Exiting debug mode.")); + + return res; +} + +Value dportally(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "dporttally\n" + "\n" + "Request a tally of DPOR in superblock\n"); + + Object res; + + TallyMagnitudesInSuperblock(); + + res.push_back(Pair("Done", "Done")); + + return res; +} + +Value forcequorom(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "forcequorom\n" + "\n" + "Requests neural network for force a quorom amoung nodes\n"); + + Object res; + + AsyncNeuralRequest("quorum", "gridcoin", 10); + + res.push_back(Pair("Requested a quorum - waiting for resolution.", 1)); + + return res; +} + +Value gatherneuralhashes(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "gatherneuralhashes\n" + "\n" + "Requests neural network to gather neural hashes\n"); + + Object res; + + GatherNeuralHashes(); + + res.push_back(Pair("Sent", ".")); + + return res; +} + +Value genboinckey(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "genboinckey\n" + "\n" + "Generates a boinc key\n"); + + Object res; + + //Gridcoin - R Halford - Generate Boinc Mining Key - 2-6-2015 + GetNextProject(false); + std::string email = GetArgument("email", "NA"); + boost::to_lower(email); + GlobalCPUMiningCPID.email = email; + GlobalCPUMiningCPID.cpidv2 = ComputeCPIDv2(GlobalCPUMiningCPID.email, GlobalCPUMiningCPID.boincruntimepublickey, 0); + //Store the BPK in the aesskein, and the cpid in version + GlobalCPUMiningCPID.aesskein = email; //Good + GlobalCPUMiningCPID.lastblockhash = GlobalCPUMiningCPID.cpidhash; + + //block version not needed for keys for now + std::string sParam = SerializeBoincBlock(GlobalCPUMiningCPID,7); + std::string sBase = EncodeBase64(sParam); + + if (fDebug3) + printf("GenBoincKey: Utilizing email %s with %s for %s\r\n", GlobalCPUMiningCPID.email.c_str(), GlobalCPUMiningCPID.boincruntimepublickey.c_str(), sParam.c_str()); + + res.push_back(Pair("[Specify in config file without quotes] boinckey=", sBase)); + + return res; +} + +Value genorgkey(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 2) + throw runtime_error( + "genorgkey <passphrase> <orgranization>\n" + "\n" + "<passphrase> -> Set passphrase to be used\n" + "<orgranization> -> Set orgranization name to be used\n" + "Generates an Org key\n"); + + Object res; + + std::string sParam1 = params[0].get_str(); + std::string sParam2 = params[1].get_str(); + std::string sboinchashargs = LegacyDefaultBoincHashArgs(); + + res.push_back(Pair("Passphrase", sParam1)); + res.push_back(Pair("OrgName", sParam2)); + + if (sParam1 != sboinchashargs) + res.push_back(Pair("Error", "Admin must be logged in")); + + else + { + std::string modulus = sboinchashargs.substr(0, 12); + std::string key = sParam2 + "," + AdvancedCryptWithSalt(modulus, sParam2); + + res.push_back(Pair("OrgKey", key)); + } + + return res; +} + +Value getlistof(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "getlistof <keytype>\n" + "\n" + "<keytype> -> key of requested data\n" + "Displays data associated to a specified key type\n"); + + Object res; + + std::string sType = params[0].get_str(); + + res.push_back(Pair("Key Type", sType)); + res.push_back(Pair("Data", GetListOf(sType))); + + return res; +} + +Value getnextproject(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "getnextproject\n" + "\n" + "Requests wallet to get next project\n"); + + Object res; + + GetNextProject(true); + + res.push_back(Pair("GetNext", 1)); + + return res; +} + +Value listdata(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "listdata <keytype>\n" + "\n" + "<keytype> -> key in cache\n" + "Displays data associated to a key stored in cache\n"); + + Object res; + + std::string sType = params[0].get_str(); + + res.push_back(Pair("Key Type", sType)); + + for(const auto& item : ReadCacheSection(sType)) + res.push_back(Pair(item.first, item.second.value)); + + return res; +} + +Value memorizekeys(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "memorizekeys\n" + "\n" + "Runs a full table scan of Load Admin Messages\n"); + + Object res; + + std::string sOut; + + LoadAdminMessages(true, sOut); + + res.push_back(Pair("Results", sOut)); + + return res; +} + Value execute(const Array& params, bool fHelp) { if (fHelp || (params.size() != 1 && params.size() != 2 && params.size() != 3 && params.size() != 4 && params.size() != 5 && params.size() != 6 && params.size() != 7)) @@ -1989,13 +2360,6 @@ Value execute(const Array& params, bool fHelp) entry.push_back(Pair("Response", response)); results.push_back(entry); - } - else if(sItem=="gatherneuralhashes") - { - GatherNeuralHashes(); - entry.push_back(Pair("Sent",".")); - results.push_back(entry); - } else if (sItem == "tallyneural") { @@ -2413,12 +2777,6 @@ Value execute(const Array& params, bool fHelp) entry.push_back(Pair("Neural Network Live Quorum Hash",myNeuralHash)); results.push_back(entry); } - else if (sItem == "forcequorum") - { - AsyncNeuralRequest("quorum","gridcoin",10); - entry.push_back(Pair("Requested a quorum - waiting for resolution.",1)); - results.push_back(entry); - } else if (sItem == "tally") { bNetAveragesLoaded_retired = false; @@ -2426,25 +2784,6 @@ Value execute(const Array& params, bool fHelp) entry.push_back(Pair("Tally Network Averages",1)); results.push_back(entry); } - else if (sItem == "genboinckey") - { - //Gridcoin - R Halford - Generate Boinc Mining Key - 2-6-2015 - GetNextProject(false); - std::string email = GetArgument("email", "NA"); - boost::to_lower(email); - GlobalCPUMiningCPID.email=email; - GlobalCPUMiningCPID.cpidv2 = ComputeCPIDv2(GlobalCPUMiningCPID.email, GlobalCPUMiningCPID.boincruntimepublickey, 0); - //Store the BPK in the aesskein, and the cpid in version - GlobalCPUMiningCPID.aesskein = email; //Good - GlobalCPUMiningCPID.lastblockhash = GlobalCPUMiningCPID.cpidhash; - - //block version not needed for keys for now - std::string sParam = SerializeBoincBlock(GlobalCPUMiningCPID,7); - if (fDebug3) printf("GenBoincKey: Utilizing email %s with %s for %s \r\n",GlobalCPUMiningCPID.email.c_str(),GlobalCPUMiningCPID.boincruntimepublickey.c_str(),sParam.c_str()); - std::string sBase = EncodeBase64(sParam); - entry.push_back(Pair("[Specify in config file without quotes] boinckey=",sBase)); - results.push_back(entry); - } else if (sItem == "encryptphrase") { if (params.size() != 2) @@ -2482,60 +2821,6 @@ Value execute(const Array& params, bool fHelp) } } - else if (sItem == "dportally") - { - TallyMagnitudesInSuperblock(); - entry.push_back(Pair("Done","Done")); - results.push_back(entry); - - } - else if (sItem == "addkey") - { - //To whitelist a project: - //execute addkey add project projectname 1 - //To blacklist a project: - //execute addkey delete project projectname 1 - //Key examples: - - //execute addkey add project milky 1 - //execute addkey delete project milky 1 - //execute addkey add project milky 2 - //execute addkey add price grc .0000046 - //execute addkey add price grc .0000045 - //execute addkey delete price grc .0000045 - //GRC will only memorize the *last* value it finds for a key in the highest block - - //execute memorizekeys - //execute listdata project - //execute listdata price - - if (params.size() != 5) - { - entry.push_back(Pair("Error","You must specify an action, message type, message name and value.")); - entry.push_back(Pair("Example","execute addkey add_or_delete keytype projectname value.")); - results.push_back(entry); - } - else - { - //execute addkey add project grid20 - std::string sAction = params[1].get_str(); - entry.push_back(Pair("Action",sAction)); - bool bAdd = (sAction=="add") ? true : false; - std::string sType = params[2].get_str(); - entry.push_back(Pair("Type",sType)); - std::string sPass = ""; - sPass = (sType=="project" || sType=="projectmapping") ? GetArgument("masterprojectkey", msMasterMessagePrivateKey) : msMasterMessagePrivateKey; - if (sType=="beacon" && sAction=="delete") sPass = GetArgument("masterprojectkey",""); - entry.push_back(Pair("Passphrase",sPass)); - std::string sName = params[3].get_str(); - entry.push_back(Pair("Name",sName)); - std::string sValue = params[4].get_str(); - entry.push_back(Pair("Value",sValue)); - std::string result = AddMessage(bAdd,sType,sName,sValue,sPass,AmountFromValue(5),.1,""); - entry.push_back(Pair("Results",result)); - results.push_back(entry); - } - } else if (sItem == "sendrawcontract") { if (params.size() != 2) @@ -2559,14 +2844,6 @@ Value execute(const Array& params, bool fHelp) entry.push_back(Pair("TrxID",wtx.GetHash().GetHex())); results.push_back(entry); } - else if (sItem == "memorizekeys") - { - std::string sOut = ""; - LoadAdminMessages(true,sOut); - entry.push_back(Pair("Results",sOut)); - results.push_back(entry); - - } else if (sItem == "superblockaverage") { std::string superblock = ReadCache("superblock","all").value; @@ -2585,95 +2862,6 @@ Value execute(const Array& params, bool fHelp) entry.push_back(Pair("Dire Need of Superblock",bDireNeed)); results.push_back(entry); } - else if (sItem == "currentcontractaverage") - { - std::string contract = NN::GetNeuralContract(); - entry.push_back(Pair("Contract",contract)); - double out_beacon_count = 0; - double out_participant_count = 0; - double out_avg = 0; - double avg = GetSuperblockAvgMag(contract,out_beacon_count,out_participant_count,out_avg,false,nBestHeight); - bool bValid = VerifySuperblock(contract, pindexBest); - entry.push_back(Pair("avg",avg)); - entry.push_back(Pair("beacon_count",out_beacon_count)); - entry.push_back(Pair("avg_mag",out_avg)); - entry.push_back(Pair("beacon_participant_count",out_participant_count)); - entry.push_back(Pair("superblock_valid",bValid)); - //Show current contract neural hash - std::string sNeuralHash = NN::GetNeuralHash(); - entry.push_back(Pair(".NET Neural Hash",sNeuralHash.c_str())); - entry.push_back(Pair("Length",(double)contract.length())); - std::string neural_hash = GetQuorumHash(contract); - entry.push_back(Pair("Wallet Neural Hash",neural_hash)); - - results.push_back(entry); - - } - else if (sItem == "getlistof") - { - if (params.size() != 2) - { - entry.push_back(Pair("Error","You must specify a keytype.")); - results.push_back(entry); - } - else - { - std::string sType = params[1].get_str(); - entry.push_back(Pair("Key Type", sType)); - entry.push_back(Pair("Data", GetListOf(sType))); - results.push_back(entry); - } - - - } - else if (sItem == "listdata") - { - if (params.size() != 2) - { - entry.push_back(Pair("Error","You must specify a keytype (IE execute dumpkeys project)")); - results.push_back(entry); - } - else - { - std::string sType = params[1].get_str(); - entry.push_back(Pair("Key Type",sType)); - for(const auto& item : ReadCacheSection(sType)) - entry.push_back(Pair(item.first, item.second.value)); - - results.push_back(entry); - } - - } - else if (sItem == "genorgkey") - { - if (params.size() != 3) - { - entry.push_back(Pair("Error","You must specify a passphrase and organization name")); - results.push_back(entry); - } - else - { - std::string sParam1 = params[1].get_str(); - entry.push_back(Pair("Passphrase",sParam1)); - std::string sParam2 = params[2].get_str(); - entry.push_back(Pair("OrgName",sParam2)); - - std::string sboinchashargs = LegacyDefaultBoincHashArgs(); - if (sParam1 != sboinchashargs) - { - entry.push_back(Pair("Error","Admin must be logged in")); - } - else - { - std::string modulus = sboinchashargs.substr(0,12); - std::string key = sParam2 + "," + AdvancedCryptWithSalt(modulus,sParam2); - entry.push_back(Pair("OrgKey",key)); - } - results.push_back(entry); - - } - - } else if (sItem == "testorgkey") { if (params.size() != 3) @@ -2707,12 +2895,6 @@ Value execute(const Array& params, bool fHelp) entry.push_back(Pair("Download Blocks",r)); results.push_back(entry); }*/ - else if (sItem == "getnextproject") - { - GetNextProject(true); - entry.push_back(Pair("GetNext",1)); - results.push_back(entry); - } else if (sItem == "resetcpids") { //Reload the config file @@ -2732,61 +2914,6 @@ Value execute(const Array& params, bool fHelp) entry.push_back(Pair("Execute Encrypt result3",s1out)); results.push_back(entry); } - else if (sItem == "debug") - { - if (params.size() == 2 && (params[1].get_str() == "true" || params[1].get_str() == "false")) - { - fDebug = (params[1].get_str() == "true") ? true : false; - entry.push_back(Pair("Debug", fDebug ? "Entering debug mode." : "Exiting debug mode.")); - } - else - entry.push_back(Pair("Error","You must specify true or false as an option.")); - results.push_back(entry); - } - else if (sItem == "debugnet") - { - if (params.size() == 2 && (params[1].get_str() == "true" || params[1].get_str() == "false")) - { - fDebugNet = (params[1].get_str() == "true") ? true : false; - entry.push_back(Pair("DebugNet", fDebugNet ? "Entering debug mode." : "Exiting debug mode.")); - } - else - entry.push_back(Pair("Error","You must specify true or false as an option.")); - results.push_back(entry); - } - else if (sItem == "debug2") - { - if (params.size() == 2 && (params[1].get_str() == "true" || params[1].get_str() == "false")) - { - fDebug2 = (params[1].get_str() == "true") ? true : false; - entry.push_back(Pair("Debug2", fDebug2 ? "Entering debug mode." : "Exiting debug mode.")); - } - else - entry.push_back(Pair("Error","You must specify true or false as an option.")); - results.push_back(entry); - } - else if (sItem == "debug3") - { - if (params.size() == 2 && (params[1].get_str() == "true" || params[1].get_str() == "false")) - { - fDebug3 = (params[1].get_str() == "true") ? true : false; - entry.push_back(Pair("Debug3", fDebug3 ? "Entering debug mode." : "Exiting debug mode.")); - } - else - entry.push_back(Pair("Error","You must specify true or false as an option.")); - results.push_back(entry); - } - else if (sItem == "debug10") - { - if (params.size() == 2 && (params[1].get_str() == "true" || params[1].get_str() == "false")) - { - fDebug10 = (params[1].get_str() == "true") ? true : false; - entry.push_back(Pair("Debug10", fDebug10 ? "Entering debug mode." : "Exiting debug mode.")); - } - else - entry.push_back(Pair("Error","You must specify true or false as an option.")); - results.push_back(entry); - } else if (sItem == "help") { entry.push_back(Pair("execute addpoll <title> <days> <question> <answers> <sharetype> <url>", "Add a poll (Requires minimum 100000 GRC balance)")); @@ -4129,7 +4256,7 @@ std::string YesNo(bool f) { return f ? "Yes" : "No"; } - +/* Value listitem(const Array& params, bool fHelp) { if (fHelp || (params.size() != 1 && params.size() != 2 && params.size() != 3 && params.size() != 4)) @@ -4274,7 +4401,7 @@ Value listitem(const Array& params, bool fHelp) return results; } - +*/ // ppcoin: get information of sync-checkpoint @@ -4326,6 +4453,7 @@ Value rpc_getblockstats(const json_spirit::Array& params, bool fHelp) if(fHelp || params.size() < 1 || params.size() > 3 ) throw runtime_error( "getblockstats mode [startheight [endheight]]\n" + "\n" "Show stats on what wallets and cpids staked recent blocks.\n"); long mode= params[0].get_int(); (void)mode; //TODO From da8fb122f34a906c5fedac15fefe3c5babad7552 Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Mon, 26 Feb 2018 13:08:36 -0800 Subject: [PATCH 12/28] Complete developers category --- src/bitcoinrpc.cpp | 92 +++-- src/bitcoinrpc.h | 29 +- src/rpcblockchain.cpp | 790 ++++++++++++++++++++++++++---------------- 3 files changed, 578 insertions(+), 333 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index e81060860d..5078fd7d24 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -283,7 +283,7 @@ static const CRPCCommand vRPCCommands[] = { "decodescript", &decodescript, false, cat_wallet }, { "dumpprivkey", &dumpprivkey, false, cat_wallet }, { "dumpwallet", &dumpwallet, true, cat_wallet }, - { "encrypt", &encrypt, true, cat_wallet }, + { "encrypt", &encrypt, false, cat_wallet }, { "encryptwallet", &encryptwallet, false, cat_wallet }, { "getaccount", &getaccount, false, cat_wallet }, { "getaccountaddress", &getaccountaddress, true, cat_wallet }, @@ -329,29 +329,29 @@ static const CRPCCommand vRPCCommands[] = // Mining commands { "advertisebeacon", &advertisebeacon, false, cat_mining }, - { "beaconreport", &beaconreport, true, cat_mining }, - { "beaconstatus", &beaconstatus, true, cat_mining }, - { "cpids", &cpids, true, cat_mining }, - { "currentneuralhash", ¤tneuralhash, true, cat_mining }, - { "currentneuralreport", ¤tneuralreport, true, cat_mining }, - { "explainmagnitude", &explainmagnitude, true, cat_mining }, + { "beaconreport", &beaconreport, false, cat_mining }, + { "beaconstatus", &beaconstatus, false, cat_mining }, + { "cpids", &cpids, false, cat_mining }, + { "currentneuralhash", ¤tneuralhash, false, cat_mining }, + { "currentneuralreport", ¤tneuralreport, false, cat_mining }, + { "explainmagnitude", &explainmagnitude, false, cat_mining }, { "getmininginfo", &getmininginfo, false, cat_mining }, - { "lifetime", &lifetime, true, cat_mining }, - { "magnitude", &magnitude, true, cat_mining }, - { "mymagnitude", &mymagnitude, true, cat_mining }, + { "lifetime", &lifetime, false, cat_mining }, + { "magnitude", &magnitude, false, cat_mining }, + { "mymagnitude", &mymagnitude, false, cat_mining }, #ifdef WIN32 - { "myneuralhash", &myneuralhash, true, cat_mining }, - { "neuralhash", &neuralhash, true, cat_mining }, + { "myneuralhash", &myneuralhash, false, cat_mining }, + { "neuralhash", &neuralhash, false, cat_mining }, #endif - { "proveownership", &proveownership, true, cat_mining }, - { "rsa", &rsa, true, cat_mining }, - { "rsaweight", &rsaweight, true, cat_mining }, + { "proveownership", &proveownership, false, cat_mining }, + { "rsa", &rsa, false, cat_mining }, + { "rsaweight", &rsaweight, false, cat_mining }, { "staketime", &staketime, false, cat_mining }, - { "superblockage", &superblockage, true, cat_mining }, - { "superblocks", &superblocks, true, cat_mining }, + { "superblockage", &superblockage, false, cat_mining }, + { "superblocks", &superblocks, false, cat_mining }, { "syncdpor2", &syncdpor2, false, cat_mining }, - { "upgradedbeaconreport", &upgradedbeaconreport, true, cat_mining }, - { "validcpids", &validcpids, true, cat_mining }, + { "upgradedbeaconreport", &upgradedbeaconreport, false, cat_mining }, + { "validcpids", &validcpids, false, cat_mining }, // Developer commands { "addkey", &addkey, false, cat_developer }, @@ -363,20 +363,40 @@ static const CRPCCommand vRPCCommands[] = { "debug2", &debug2, true, cat_developer }, { "debug3", &debug3, true, cat_developer }, { "debugnet", &debugnet, true, cat_developer }, - { "dportally", &dportally, true, cat_developer }, - { "forcequorom", &forcequorom, true, cat_developer }, - { "gatherneuralhashes", &gatherneuralhashes, true, cat_developer }, - { "genboinckey", &genboinckey, true, cat_developer }, - { "genorgkey", &genorgkey, true, cat_developer }, - { "getblockstats", &rpc_getblockstats, true, cat_developer }, - { "getlistof", &getlistof, true, cat_developer }, + { "dportally", &dportally, false, cat_developer }, + { "forcequorom", &forcequorom, false, cat_developer }, + { "gatherneuralhashes", &gatherneuralhashes, false, cat_developer }, + { "genboinckey", &genboinckey, false, cat_developer }, + { "genorgkey", &genorgkey, false, cat_developer }, + { "getblockstats", &rpc_getblockstats, false, cat_developer }, + { "getlistof", &getlistof, false, cat_developer }, { "getnextproject", &getnextproject, false, cat_developer }, - { "listdata", &listdata, true, cat_developer }, - { "memorizekeys", &memorizekeys, true, cat_developer }, - {}, - {}, - {}, - {}, + { "listdata", &listdata, false, cat_developer }, + { "memorizekeys", &memorizekeys, false, cat_developer }, + { "network", &network, false, cat_developer }, + { "neuralrequest", &neuralrequest, false, cat_developer }, + { "projects", &projects, false, cat_developer }, + { "readconfig", &readconfig, false, cat_developer }, + { "readdata", &readdata, false, cat_developer }, +#ifdef WIN32 + { "refhash", &refhash, false, cat_developer }, +#endif + { "reorganize", &rpc_reorganize, false, cat_developer }, + { "seefile", &seefile, false, cat_developer }, + { "sendalert", &sendalert, false, cat_developer }, + { "sendalert2", &sendalert2, false, cat_developer }, + { "sendrawcontract", &sendrawcontract, false, cat_developer }, + { "superblockaverage", &superblockaverage, false, cat_developer }, + { "tally", &tally, false, cat_developer }, + { "tallyneural", &tallyneural, false, cat_developer }, +#ifdef WIN32 + { "testnewcontract", &testnewcontract, false, cat_developer }, +#endif + { "testorgkey", &testorgkey, false, cat_developer }, + { "unusual", &unusual, false, cat_developer }, + { "updatequoromdata", &updatequoromdata, false, cat_developer }, + { "versionreport", &versionreport, false, cat_developer }, + { "writedata", &writedata, false, cat_developer }, {}, {}, {}, @@ -473,6 +493,14 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri if (strMethod == "debugnet" && n > 0) ConvertTo<bool>(params[0]); if (strMethod == "getblockstats" && n > 0) ConvertTo<int64_t>(params[0]); if (strMethod == "getblockstats" && n > 1) ConvertTo<int64_t>(params[1]); + if (strMethod == "sendalert" && n > 2) ConvertTo<int64_t>(params[2]); + if (strMethod == "sendalert" && n > 3) ConvertTo<int64_t>(params[3]); + if (strMethod == "sendalert" && n > 4) ConvertTo<int64_t>(params[4]); + if (strMethod == "sendalert" && n > 5) ConvertTo<int64_t>(params[5]); + if (strMethod == "sendalert" && n > 6) ConvertTo<int64_t>(params[6]); + if (strMethod == "sendalert2" && n > 1) ConvertTo<int64_t>(params[1]); + if (strMethod == "sendalert2" && n > 4) ConvertTo<int64_t>(params[4]); + if (strMethod == "sendalert2" && n > 5) ConvertTo<int64_t>(params[5]); return params; } diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index d7ee1137a2..bd84656b23 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -257,12 +257,37 @@ extern json_spirit::Value getlistof(const json_spirit::Array& params, bool fHelp extern json_spirit::Value getnextproject(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value listdata(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value memorizekeys(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value network(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value neuralrequest(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value projects(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value readconfig(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value readdata(const json_spirit::Array& params, bool fHelp); +#ifdef WIN32 +extern json_spirit::Value refhash(const json_spirit::Array& params, bool fHelp); +#endif +extern json_spirit::Value rpc_reorganize(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value seefile(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value sendalert(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value sendalert2(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value sendrawcontract(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value superblockaverage(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value tally(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value tallyneural(const json_spirit::Array& params, bool fHelp); +#ifdef WIN32 +extern json_spirit::Value testnewcontract(const json_spirit::Array& params, bool fHelp); +#endif +extern json_spirit::Value testorgkey(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value unusual(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value updatequoromdata(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value versionreport(const json_spirit::Array& params, bool fhelp); +extern json_spirit::value writedata(const json_spirit::Array& params, bool fHelp); + + extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value ping(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value sendalert(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getnettotals(const json_spirit::Array& params, bool fHelp); @@ -284,10 +309,8 @@ extern json_spirit::Value getcheckpoint(const json_spirit::Array& params, bool f extern json_spirit::Value showblock(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value listitem(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value execute(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value rpc_reorganize(const json_spirit::Array& params, bool fHelp); // Brod -extern json_spirit::Value sendalert2(const json_spirit::Array& params, bool fHelp); // iFoggz //extern json_spirit::Value blockchain(const json_spirit::Array& params, bool fHelp); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index ac4d8ba9f9..84f221c6af 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1114,18 +1114,21 @@ Value burn2(const Array& params, bool fHelp) if (!isValid) { res.push_back(Pair("Error","Invalid GRC Burn Address.")); + return res; } if (dAmount == 0 || dAmount < 0) { res.push_back(Pair("Error","Burn amount must be > 0.")); + return res; } if (sKey.empty() || sDetail.empty()) { res.push_back(Pair("Error","Burn Key and Burn Detail must be populated.")); + return res; } @@ -1150,8 +1153,10 @@ Value encrypt(const Array& params, bool fHelp) //Encrypt a phrase std::string sParam = params[0].get_str(); std::string encrypted = AdvancedCryptWithHWID(sParam); + res.push_back(Pair("Passphrase",encrypted)); res.push_back(Pair("[Specify in config file] autounlock=",encrypted)); + return res; } @@ -1167,6 +1172,7 @@ Value newburnaddress(const Array& params, bool fHelp) //3-12-2016 - R Halford - Allow the user to make vanity GRC Burn Addresses that have no corresponding private key std::string sBurnTemplate = "GRCBurnAddressGRCBurnAddressGRCBurnAddress"; + if (params.size() > 0) sBurnTemplate = params[0].get_str(); @@ -1196,15 +1202,19 @@ Value newburnaddress(const Array& params, bool fHelp) vector<unsigned char> v(sBinary.begin(), sBinary.end()); //Make the new address so that it passes base 58 Checks std::string encoded1 = EncodeBase58(v); - res.push_back(Pair("CombinedHex",combined)); std::string encoded2 = EncodeBase58Check(vchDecoded30); + + res.push_back(Pair("CombinedHex",combined)); + if (encoded2.length() != 34) { res.push_back(Pair("Burn Address Creation failed","NOTE: the input phrase must not include zeroes, or nonbase58 characters.")); + return res; } // Give the user the new vanity burn address res.push_back(Pair("Burn Address",encoded2)); + return res; } @@ -1226,20 +1236,26 @@ Value rain(const json_spirit::Array& params, bool fHelp) std::string sRainCommand = ExtractXML(sRecipients,"<RAIN>","</RAIN>"); std::string sRainMessage = MakeSafeMessage(ExtractXML(sRecipients,"<RAINMESSAGE>","</RAINMESSAGE>")); std::string sRain = "<NARR>Project Rain: " + sRainMessage + "</NARR>"; - if (!sRainCommand.empty()) sRecipients = sRainCommand; + + if (!sRainCommand.empty()) + sRecipients = sRainCommand; + wtx.hashBoinc = sRain; int64_t totalAmount = 0; double dTotalToSend = 0; std::vector<std::string> vRecipients = split(sRecipients.c_str(),"<ROW>"); printf("Creating Rain transaction with %f recipients. ",(double)vRecipients.size()); + for (unsigned int i = 0; i < vRecipients.size(); i++) { std::string sRow = vRecipients[i]; std::vector<std::string> vReward = split(sRow.c_str(),"<COL>"); + if (vReward.size() > 1) { std::string sAddress = vReward[0]; std::string sAmount = vReward[1]; + if (sAddress.length() > 10 && sAmount.length() > 0) { double dAmount = RoundFromString(sAmount,4); @@ -1248,8 +1264,10 @@ Value rain(const json_spirit::Array& params, bool fHelp) CBitcoinAddress address(sAddress); if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Gridcoin address: ")+sAddress); + if (setAddress.count(address)) throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+sAddress); + setAddress.insert(address); dTotalToSend += dAmount; int64_t nAmount = AmountFromDouble(dAmount); @@ -1265,6 +1283,7 @@ Value rain(const json_spirit::Array& params, bool fHelp) EnsureWalletIsUnlocked(); // Check funds double dBalance = GetTotalBalance(); + if (dTotalToSend > dBalance) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); // Send @@ -1272,21 +1291,25 @@ Value rain(const json_spirit::Array& params, bool fHelp) int64_t nFeeRequired = 0; bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired); printf("Transaction Created."); + if (!fCreated) { if (totalAmount + nFeeRequired > pwalletMain->GetBalance()) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds"); throw JSONRPCError(RPC_WALLET_ERROR, "Transaction creation failed"); } + printf("Committing."); // Rain the recipients if (!pwalletMain->CommitTransaction(wtx, keyChange)) { printf("Commit failed."); + throw JSONRPCError(RPC_WALLET_ERROR, "Transaction commit failed"); } std::string sNarr = "Rain successful: Sent " + wtx.GetHash().GetHex() + "."; printf("Success %s",sNarr.c_str()); + res.push_back(Pair("Response", sNarr)); return res; @@ -1322,8 +1345,8 @@ Value advertisebeacon(const json_spirit::Array& params, bool fHelp) std::string sOutPrivKey = ""; std::string sError = ""; std::string sMessage = ""; - bool fResult = AdvertiseBeacon(sOutPrivKey,sOutPubKey,sError,sMessage); + res.push_back(Pair("Result",SuccessFail(fResult))); res.push_back(Pair("CPID",GlobalCPUMiningCPID.cpid.c_str())); res.push_back(Pair("Message",sMessage.c_str())); @@ -1354,6 +1377,7 @@ Value beaconreport(const Array& params, bool fHelp) Object res; Array myBeaconJSONReport = GetJSONBeaconReport(); + res.push_back(myBeaconJSONReport); return res; @@ -1377,16 +1401,15 @@ Value beaconstatus(const json_spirit::Array& params, bool fHelp) if (params.size() > 0) sCPID = params[0].get_str(); - res.push_back(Pair("CPID", sCPID)); std::string sPubKey = GetBeaconPublicKey(sCPID, false); std::string sPrivKey = GetStoredBeaconPrivateKey(sCPID); int64_t iBeaconTimestamp = BeaconTimeStamp(sCPID, false); std::string timestamp = TimestampToHRDate(iBeaconTimestamp); - bool hasBeacon = HasActiveBeacon(sCPID); + + res.push_back(Pair("CPID", sCPID)); res.push_back(Pair("Beacon Exists",YesNo(hasBeacon))); res.push_back(Pair("Beacon Timestamp",timestamp.c_str())); - res.push_back(Pair("Public Key", sPubKey.c_str())); res.push_back(Pair("Private Key", sPrivKey.c_str())); @@ -1399,6 +1422,7 @@ Value beaconstatus(const json_spirit::Array& params, bool fHelp) // Verify the users Local Public Key matches the Beacon Public Key std::string sLocalPubKey = GetStoredBeaconPublicKey(sCPID); + res.push_back(Pair("Local Configuration Public Key", sLocalPubKey.c_str())); if (sLocalPubKey.empty()) @@ -1409,6 +1433,7 @@ Value beaconstatus(const json_spirit::Array& params, bool fHelp) // Prior superblock Magnitude double dMagnitude = GetMagnitudeByCpidFromLastSuperblock(sCPID); + res.push_back(Pair("Magnitude (As of last superblock)", dMagnitude)); if (dMagnitude==0) @@ -1421,6 +1446,7 @@ Value beaconstatus(const json_spirit::Array& params, bool fHelp) { std::string sSignature = SignBlockWithCPID(sCPID,hashBlock.GetHex()); bool fResult = VerifyCPIDSignature(sCPID, hashBlock.GetHex(), sSignature); + res.push_back(Pair("Block Signing Test Results", fResult)); if (!fResult) @@ -1495,6 +1521,7 @@ Value currentneuralhash(const Array& params, bool fHelp) double popularity = 0; std::string consensus_hash = GetCurrentNeuralNetworkSupermajorityHash(popularity); + res.push_back(Pair("Popular",consensus_hash)); return res; @@ -1511,6 +1538,7 @@ Value currentneuralreport(const Array& params, bool fHelp) Object res; Array myNeuralJSON = GetJSONCurrentNeuralNetworkReport(); + res.push_back(myNeuralJSON); return res; @@ -1577,21 +1605,28 @@ Value lifetime(const Array& params, bool fHelp) std::string cpid = msPrimaryCPID; std::string Narr = ToString(GetAdjustedTime()); + c.push_back(Pair("Lifetime Payments Report",Narr)); results.push_back(c); + CBlockIndex* pindex = pindexGenesisBlock; + while (pindex->nHeight < pindexBest->nHeight) { pindex = pindex->pnext; + if (pindex==NULL || !pindex->IsInMainChain()) continue; + if (pindex == pindexBest) break; + if (pindex->GetCPID() == cpid && (pindex->nResearchSubsidy > 0)) res.push_back(Pair(pindex->nHeight, RoundToString(pindex->nResearchSubsidy,2))); } //8-14-2015 StructCPID stCPID = GetInitializedStructCPID2(cpid,mvResearchAge); + res.push_back(Pair("Average Magnitude",stCPID.ResearchAverageMagnitude)); results.push_back(res); @@ -1667,7 +1702,8 @@ Value myneuralhash(const Array& params, bool fHelp) Object res; std::string myNeuralHash = NN::GetNeuralHash(); - res.push_back(Pair("My Neural Hash",myNeuralHash.c_str())); + + res.push_back(Pair("My Neural Hash", myNeuralHash.c_str())); return res; } @@ -1682,8 +1718,12 @@ Value neuralhash(const Array& params, bool fHelp) Object res; - std::string myNeuralHash = NN::GetNeuralHash(); - res.push_back(Pair("My Neural Hash",myNeuralHash.c_str())); + double popularity = 0; + std::string consensus_hash = GetNeuralNetworkSupermajorityHash(popularity); + + res.push_back(Pair("Popular", consensus_hash)); + + results.push_back(entry); return res; } @@ -1700,6 +1740,7 @@ Value neuralreport(const Array& params, bool fHelp) Object res; Array myNeuralJSON = GetJSONNeuralNetworkReport(); + res.push_back(myNeuralJSON); return res; @@ -1717,18 +1758,17 @@ Value proveownership(const Array& params, bool fHelp) HarvestCPIDs(true); GetNextProject(true); + std::string email = GetArgument("email", "NA"); boost::to_lower(email); - - res.push_back(Pair("Boinc E-Mail", email)); - res.push_back(Pair("Boinc Public Key", GlobalCPUMiningCPID.boincruntimepublickey)); - res.push_back(Pair("CPID", GlobalCPUMiningCPID.cpid)); - std::string sLongCPID = ComputeCPIDv2(email, GlobalCPUMiningCPID.boincruntimepublickey,1); std::string sShortCPID = RetrieveMd5(GlobalCPUMiningCPID.boincruntimepublickey + email); std::string sEmailMD5 = RetrieveMd5(email); std::string sBPKMD5 = RetrieveMd5(GlobalCPUMiningCPID.boincruntimepublickey); + res.push_back(Pair("Boinc E-Mail", email)); + res.push_back(Pair("Boinc Public Key", GlobalCPUMiningCPID.boincruntimepublickey)); + res.push_back(Pair("CPID", GlobalCPUMiningCPID.cpid)); res.push_back(Pair("Computed Email Hash", sEmailMD5)); res.push_back(Pair("Computed BPK", sBPKMD5)); res.push_back(Pair("Computed CPID", sLongCPID)); @@ -1739,6 +1779,7 @@ Value proveownership(const Array& params, bool fHelp) if (GlobalCPUMiningCPID.boincruntimepublickey.empty()) { fResult = false; + res.push_back(Pair("Error", "Boinc Public Key empty. Try mounting your boinc project first, and ensure the gridcoin datadir setting is set if boinc is not in the default location.")); } @@ -2304,6 +2345,443 @@ Value memorizekeys(const Array& params, bool fHelp) return res; } +Value network(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "network\n" + "\n" + "Display information about the network health\n"); + + Object res; + + for(map<string,StructCPID>::iterator ii=mvNetwork.begin(); ii!=mvNetwork.end(); ++ii) + { + StructCPID stNet = mvNetwork[(*ii).first]; + + if (stNet.initialized) + { + Object results; + + results.push_back(Pair("Project", stNet.projectname)); + results.push_back(Pair("Avg RAC", stNet.AverageRAC)); + + if (stNet.projectname == "NETWORK") + { + double MaximumEmission = BLOCKS_PER_DAY*GetMaximumBoincSubsidy(GetAdjustedTime()); + double MoneySupply = DoubleFromAmount(pindexBest->nMoneySupply); + double iPct = ( (stNet.InterestSubsidy/14) * 365 / (MoneySupply+.01)); + double magnitude_unit = GRCMagnitudeUnit(GetAdjustedTime()); + + results.push_back(Pair("Network Total Magnitude", stNet.NetworkMagnitude)); + results.push_back(Pair("Network Average Magnitude", stNet.NetworkAvgMagnitude)); + results.push_back(Pair("Network Avg Daily Payments", stNet.payments/14)); + results.push_back(Pair("Network Max Daily Payments", MaximumEmission)); + results.push_back(Pair("Network Interest Paid (14 days)", stNet.InterestSubsidy)); + results.push_back(Pair("Network Avg Daily Interest", stNet.InterestSubsidy/14)); + results.push_back(Pair("Total Money Supply", MoneySupply)); + results.push_back(Pair("Network Interest %", iPct)); + results.push_back(Pair("Magnitude Unit (GRC payment per Magnitude per day)", magnitude_unit)); + } + + res.push_back(results); + } + } + + return res; +} + +Value neuralrequest(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "neuralrequest\n" + "\n" + "Sends a request to neural network and displays response\n"); + + Object res; + + std::string response = NeuralRequest("REQUEST"); + + res.push_back(Pair("Response", response)); + + return res; +} + +Value projects(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "projects\n" + "\n" + "Displays information on projects in the network\n"); + + Object res; + + for (const auto& item : ReadCacheSection("project")) + { + Object entry; + + std::string sProjectName = ToOfficialName(item.first); + + if (sProjectName.empty()) + continue; + + std::string sProjectURL = item.second.value; + sProjectURL.erase(std::remove(sProjectURL.begin(), sProjectURL.end(), '@'), sProjectURL.end()); + + // If contains an additional stats URL for project stats; remove it for the user to goto the correct website. + if (sProjectURL.find("stats/") != string::npos) + { + std::size_t tFound = sProjectURL.find("stats/"); + sProjectURL.erase(tFound, sProjectURL.length()); + } + + entry.push_back(Pair("Project", sProjectName)); + entry.push_back(Pair("URL", sProjectURL)); + + res.push_back(entry); + } + + return res; +} + +Value readconfig(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "readconfig\n" + "\n" + "Re-reads config file; Does not overwrite pre-existing loaded values\n"); + + Object res; + + ReadConfigFile(mapArgs, mapMultiArgs); + + res.push_back(Pair("readconfig", 1)); + + return res; +} + +Value readdata(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "readdata <key>\n" + "\n" + "<key> -> generic key\n" + "Reads generic data from disk from a specified key\n"); + + Object res; + + std::string sKey = params[0].get_str(); + std::string sValue = "?"; + + //CTxDB txdb("cr"); + CTxDB txdb; + + if (!txdb.ReadGenericData(sKey, sValue)) + { + res.push_back(Pair("Error", sValue)); + + sValue = "Failed to read from disk."; + } + + res.push_back(Pair("Key", sKey)); + res.push_back(Pair("Result", sValue)); + + return res; +} + +Value seefile(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "seefile\n" + "\n" + "Unit test for sending a file from node to node\n"); + + Object res; + + // This is a unit test to prove viability of transmitting a file from node to node + std::string sFile = "C:\\test.txt"; + std::vector<unsigned char> v = readFileToVector(sFile); + + res.push_back(Pair("byte1", v[1])); + res.push_back(Pair("bytes", (int)v.size())); + + for (unsigned int i = 0; i < v.size(); i++) + res.push_back(Pair("bytes", v[i])); + + std::string sManifest = FileManifest(); + + res.push_back(Pair("manifest", sManifest)); + + return res; +} + +#ifdef WIN32 +Value refhash(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "refhash <walletaddress>\n" + "\n" + "<walletaddress> -> GRC address to test against\n" + "Tests to see if a GRC Address is a participant in neural network along with default wallet address\n"); + + Object res; + + std::string rh = params[0].get_str(); + bool r1 = StrLessThanReferenceHash(rh); + bool r2 = IsNeuralNodeParticipant(DefaultWalletAddress(), GetAdjustedTime()); + + res.push_back(Pair("<Ref Hash", r1)); + + res.push_back(Pair("WalletAddress<Ref Hash", r2)); + + return res; +} +#endif + +Value sendrawcontract(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "sendrawcontract <contract>\n" + "\n" + "<contract> -> custom contract\n" + "Send a raw contract in a transaction on the network\n"); + + Object res; + + if (pwalletMain->IsLocked()) + throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); + + std::string sAddress = GetBurnAddress(); + + CBitcoinAddress address(sAddress); + + if (!address.IsValid()) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Gridcoin address"); + + std::string sContract = params[0].get_str(); + int64_t nAmount = CENT; + // Wallet comments + CWalletTx wtx; + wtx.hashBoinc = sContract; + + string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx, false); + + if (!strError.empty()) + throw JSONRPCError(RPC_WALLET_ERROR, strError); + + res.push_back(Pair("Contract", sContract)); + res.push_back(Pair("Recipient", sAddress)); + res.push_back(Pair("TrxID", wtx.GetHash().GetHex())); + + return res; +} + +Value superblockaverage(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "superblockaverage\n" + "\n" + "Displays average information for current superblock\n"); + + Object res; + + std::string superblock = ReadCache("superblock", "all").value; + double out_beacon_count = 0; + double out_participant_count = 0; + double out_avg = 0; + double avg = GetSuperblockAvgMag(superblock, out_beacon_count, out_participant_count, out_avg, false, nBestHeight); + int64_t superblock_age = GetAdjustedTime() - ReadCache("superblock", "magnitudes").timestamp; + bool bDireNeed = NeedASuperblock(); + + res.push_back(Pair("avg", avg)); + res.push_back(Pair("beacon_count", out_beacon_count)); + res.push_back(Pair("beacon_participant_count", out_participant_count)); + res.push_back(Pair("average_magnitude", out_avg)); + res.push_back(Pair("superblock_valid", VerifySuperblock(superblock, pindexBest))); + res.push_back(Pair("Superblock Age", superblock_age)); + res.push_back(Pair("Dire Need of Superblock", bDireNeed)); + + return res; +} + +Value tally(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "tally\n" + "\n" + "Requests a tally of research averages\n"); + + Object res; + + bNetAveragesLoaded_retired = false; + TallyResearchAverages_v9(); + + res.push_back(Pair("Tally Network Averages", 1)); + + return res; +} + +Value tallyneural(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "tallyneural\n" + "\n" + "Requests a tally of neural network\n"); + + Object res; + + ComputeNeuralNetworkSupermajorityHashes(); + UpdateNeuralNetworkQuorumData(); + + res.push_back(Pair("Ready", ".")); + + return res; +} + +#ifdef WIN32 +Value testnewcontract(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "testnewcontract\n" + "\n" + "Tests current local neural contract\n"); + + Object res; + + std::string contract = NN::GetNeuralContract(); + std::string myNeuralHash = NN::GetNeuralHash(); + // Convert to Binary + std::string sBin = PackBinarySuperblock(contract); + // Hash of current superblock + std::string sUnpacked = UnpackBinarySuperblock(sBin); + std::string neural_hash = GetQuorumHash(contract); + std::string binary_neural_hash = GetQuorumHash(sUnpacked); + + res.push_back(Pair("My Neural Hash", myNeuralHash)); + res.push_back(Pair("Contract Test", contract)); + res.push_back(Pair("Contract Length", (int)contract.length())); + res.push_back(Pair("Binary Length", (int)sBin.length())); + res.push_back(Pair("Unpacked length", (int)sUnpacked.length())); + res.push_back(Pair("Unpacked", sUnpacked)); + res.push_back(Pair("Local Core Quorum Hash", neural_hash)); + res.push_back(Pair("Binary Local Core Quorum Hash", binary_neural_hash)); + res.push_back(Pair("Neural Network Live Quorum Hash", myNeuralHash)); + + return res; +} +#endif + +Value testorgkey(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 2) + throw runtime_error( + "testorgkey <organization> <publickey>\n" + "\n" + "<organization> -> Organization name\n" + "<publickey> ----> Public key for testing\n" + "Test a orgkey created by genorgkey\n"); + + Object res; + + std::string sParam1 = params[0].get_str(); + std::string sParam2 = params[1].get_str(); + std::string key = sParam1 + "," + AdvancedDecryptWithSalt(sParam2, sParam1); + + res.push_back(Pair("Org", sParam1)); + res.push_back(Pair("Key", sParam2)); + res.push_back(Pair("PubKey", key)); + + return res; +} + +Value unusual(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "unusual\n" + "\n" + "Displays report on unusual network activity in debug.log\n"); + + Object res; + + UnusualActivityReport(); + + res.push_back(Pair("UAR", 1)); + + return res; +} + +Value updatequoromdata(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "updatequoromdata\n" + "\n" + "Rquests update of neural network quorom data\n"); + + Object res; + + UpdateNeuralNetworkQuorumData(); + + res.push_back(Pair("Updated.", "")); + + return res; +} + +Value versionreport(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "versionreport\n" + "\n" + "Displays a report on various versions recently stake on the network\n"); + + Array myNeuralJSON = GetJSONVersionReport(); + + return myNeuralJSON; +} + +Value writedata(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 2) + throw runtime_error( + "writedata <key> <value>\n" + "\n" + "<key> ---> Key where value will be written\n" + "<value> -> Value to be written to specified key\n" + "Writes a value to specified key\n"); + + Object res; + + std::string sKey = params[0].get_str(); + std::string sValue = params[1].get_str(); + //CTxDB txdb("rw"); + CTxDB txdb; + txdb.TxnBegin(); + std::string result = "Success."; + + if (!txdb.WriteGenericData(sKey, sValue)) + result = "Unable to write."; + + if (!txdb.TxnCommit()) + result = "Unable to Commit."; + + res.push_back(Pair("Result", result)); + + return res; +} + Value execute(const Array& params, bool fHelp) { if (fHelp || (params.size() != 1 && params.size() != 2 && params.size() != 3 && params.size() != 4 && params.size() != 5 && params.size() != 6 && params.size() != 7)) @@ -2353,126 +2831,12 @@ Value execute(const Array& params, bool fHelp) entry.push_back(Pair("Result",fResult)); results.push_back(entry); } - else if (sItem == "neuralrequest") - { - - std::string response = NeuralRequest("REQUEST"); - entry.push_back(Pair("Response", response)); - results.push_back(entry); - - } - else if (sItem == "tallyneural") - { - ComputeNeuralNetworkSupermajorityHashes(); - UpdateNeuralNetworkQuorumData(); - entry.push_back(Pair("Ready",".")); - results.push_back(entry); - } - else if (sItem == "versionreport") - { - Array myNeuralJSON = GetJSONVersionReport(); - results.push_back(myNeuralJSON); - } - else if (sItem == "unusual") - { - - UnusualActivityReport(); - entry.push_back(Pair("UAR",1)); - results.push_back(entry); - - - } - else if (sItem == "neuralhash") - { - double popularity = 0; - std::string consensus_hash = GetNeuralNetworkSupermajorityHash(popularity); - entry.push_back(Pair("Popular",consensus_hash)); - results.push_back(entry); - } - else if (sItem=="updatequorumdata") - { - UpdateNeuralNetworkQuorumData(); - entry.push_back(Pair("Updated.","")); - results.push_back(entry); - } else if (sItem == "askforoutstandingblocks") { bool fResult = AskForOutstandingBlocks(uint256(0)); entry.push_back(Pair("Sent.",fResult)); results.push_back(entry); } - else if (sItem == "readconfig") - { - ReadConfigFile(mapArgs, mapMultiArgs); - - } - else if (sItem == "writedata") - { - if (params.size() != 3) - { - entry.push_back(Pair("Error","You must specify the Key and Value. For example execute writedata dog_color black.")); - results.push_back(entry); - } - else - { - std::string sKey = params[1].get_str(); - std::string sValue = params[2].get_str(); - //CTxDB txdb("rw"); - CTxDB txdb; - txdb.TxnBegin(); - std::string result = "Success."; - if (!txdb.WriteGenericData(sKey,sValue)) result = "Unable to write."; - if (!txdb.TxnCommit()) result = "Unable to Commit."; - entry.push_back(Pair("Result",result)); - results.push_back(entry); - } - - } - else if (sItem == "readdata") - { - if (params.size() != 2) - { - entry.push_back(Pair("Error","You must specify the Key. For example execute readdata dog_color.")); - results.push_back(entry); - } - else - { - std::string sKey = params[1].get_str(); - std::string sValue = "?"; - //CTxDB txdb("cr"); - CTxDB txdb; - if (!txdb.ReadGenericData(sKey,sValue)) - { - entry.push_back(Pair("Error",sValue)); - - sValue = "Failed to read from disk."; - } - entry.push_back(Pair("Key",sKey)); - - entry.push_back(Pair("Result",sValue)); - results.push_back(entry); - } - - } - else if (sItem == "refhash") - { - if (params.size() != 2) - { - entry.push_back(Pair("Error","You must specify the Reference Hash.")); - results.push_back(entry); - } - else - { - std::string rh = params[1].get_str(); - bool r1 = StrLessThanReferenceHash(rh); - bool r2 = IsNeuralNodeParticipant(DefaultWalletAddress(), GetAdjustedTime()); - entry.push_back(Pair("<Ref Hash",r1)); - entry.push_back(Pair("WalletAddress<Ref Hash",r2)); - results.push_back(entry); - - } - - } else if (sItem == "vote") { if (params.size() != 3) @@ -2750,40 +3114,6 @@ Value execute(const Array& params, bool fHelp) } } } - else if (sItem=="testnewcontract") - { - std::string contract = NN::GetNeuralContract(); - std::string myNeuralHash = NN::GetNeuralHash(); - entry.push_back(Pair("My Neural Hash",myNeuralHash.c_str())); - results.push_back(entry); - - entry.push_back(Pair("Contract Test",contract)); - // Convert to Binary - std::string sBin = PackBinarySuperblock(contract); - entry.push_back(Pair("Contract Length",(int)contract.length())); - entry.push_back(Pair("Binary Length",(int)sBin.length())); - //entry.push_back(Pair("Binary",sBin.c_str())); - // Hash of current superblock - std::string sUnpacked = UnpackBinarySuperblock(sBin); - entry.push_back(Pair("Unpacked length",(int)sUnpacked.length())); - - entry.push_back(Pair("Unpacked",sUnpacked.c_str())); - std::string neural_hash = GetQuorumHash(contract); - std::string binary_neural_hash = GetQuorumHash(sUnpacked); - - entry.push_back(Pair("Local Core Quorum Hash",neural_hash)); - entry.push_back(Pair("Binary Local Core Quorum Hash",binary_neural_hash)); - - entry.push_back(Pair("Neural Network Live Quorum Hash",myNeuralHash)); - results.push_back(entry); - } - else if (sItem == "tally") - { - bNetAveragesLoaded_retired = false; - TallyResearchAverages_v9(); - entry.push_back(Pair("Tally Network Averages",1)); - results.push_back(entry); - } else if (sItem == "encryptphrase") { if (params.size() != 2) @@ -2820,67 +3150,6 @@ Value execute(const Array& params, bool fHelp) } - } - else if (sItem == "sendrawcontract") - { - if (params.size() != 2) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "You must specify raw contract."); - if (pwalletMain->IsLocked()) - throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); - std::string sAddress = GetBurnAddress(); - CBitcoinAddress address(sAddress); - if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Gridcoin address"); - std::string sContract = params[1].get_str(); - entry.push_back(Pair("Contract",sContract)); - entry.push_back(Pair("Recipient",sAddress)); - int64_t nAmount = CENT; - // Wallet comments - CWalletTx wtx; - wtx.hashBoinc = sContract; - string strError = pwalletMain->SendMoneyToDestination(address.Get(), nAmount, wtx, false); - if (!strError.empty()) - throw JSONRPCError(RPC_WALLET_ERROR, strError); - entry.push_back(Pair("TrxID",wtx.GetHash().GetHex())); - results.push_back(entry); - } - else if (sItem == "superblockaverage") - { - std::string superblock = ReadCache("superblock","all").value; - double out_beacon_count = 0; - double out_participant_count = 0; - double out_avg = 0; - double avg = GetSuperblockAvgMag(superblock,out_beacon_count,out_participant_count,out_avg,false,nBestHeight); - entry.push_back(Pair("avg",avg)); - entry.push_back(Pair("beacon_count",out_beacon_count)); - entry.push_back(Pair("beacon_participant_count",out_participant_count)); - entry.push_back(Pair("average_magnitude",out_avg)); - entry.push_back(Pair("superblock_valid", VerifySuperblock(superblock, pindexBest))); - int64_t superblock_age = GetAdjustedTime() - ReadCache("superblock", "magnitudes").timestamp; - entry.push_back(Pair("Superblock Age",superblock_age)); - bool bDireNeed = NeedASuperblock(); - entry.push_back(Pair("Dire Need of Superblock",bDireNeed)); - results.push_back(entry); - } - else if (sItem == "testorgkey") - { - if (params.size() != 3) - { - entry.push_back(Pair("Error","You must specify an org and public key")); - results.push_back(entry); - } - else - { - std::string sParam1 = params[1].get_str(); - entry.push_back(Pair("Org",sParam1)); - std::string sParam2 = params[2].get_str(); - entry.push_back(Pair("Key",sParam2)); - std::string key = sParam1 + "," + AdvancedDecryptWithSalt(sParam2,sParam1); - entry.push_back(Pair("PubKey",key)); - results.push_back(entry); - - } - } else if (sItem == "reindex") { @@ -4294,22 +4563,6 @@ Value listitem(const Array& params, bool fHelp) results.push_back(entry); } - else if (sitem == "seefile") - { - // This is a unit test to prove viability of transmitting a file from node to node - std::string sFile = "C:\\test.txt"; - std::vector<unsigned char> v = readFileToVector(sFile); - Object entry; - entry.push_back(Pair("byte1",v[1])); - entry.push_back(Pair("bytes",(double)v.size())); - for (unsigned int i = 0; i < v.size(); i++) - { - entry.push_back(Pair("bytes",v[i])); - } - std::string sManifest = FileManifest(); - entry.push_back(Pair("manifest",sManifest)); - results.push_back(entry); - } else if (sitem == "memorypool") { Object entry; @@ -4317,65 +4570,6 @@ Value listitem(const Array& params, bool fHelp) entry.push_back(Pair("Included Tx",msMiningErrorsIncluded)); results.push_back(entry); } - else if (sitem == "projects") - { - for (const auto& item : ReadCacheSection("project")) - { - Object entry; - - std::string sProjectName = ToOfficialName(item.first); - if (sProjectName.empty()) - continue; - - std::string sProjectURL = item.second.value; - sProjectURL.erase(std::remove(sProjectURL.begin(), sProjectURL.end(), '@'), sProjectURL.end()); - - // If contains an additional stats URL for project stats; remove it for the user to goto the correct website. - if (sProjectURL.find("stats/") != string::npos) - { - std::size_t tFound = sProjectURL.find("stats/"); - sProjectURL.erase(tFound, sProjectURL.length()); - } - - entry.push_back(Pair("Project", sProjectName)); - entry.push_back(Pair("URL", sProjectURL)); - results.push_back(entry); - } - } - else if (sitem == "network") - { - for(map<string,StructCPID>::iterator ii=mvNetwork.begin(); ii!=mvNetwork.end(); ++ii) - { - - StructCPID stNet = mvNetwork[(*ii).first]; - - if (stNet.initialized) - { - Object entry; - entry.push_back(Pair("Project",stNet.projectname)); - entry.push_back(Pair("Avg RAC",stNet.AverageRAC)); - if (stNet.projectname=="NETWORK") - { - entry.push_back(Pair("Network Total Magnitude",stNet.NetworkMagnitude)); - entry.push_back(Pair("Network Average Magnitude",stNet.NetworkAvgMagnitude)); - double MaximumEmission = BLOCKS_PER_DAY*GetMaximumBoincSubsidy(GetAdjustedTime()); - entry.push_back(Pair("Network Avg Daily Payments", stNet.payments/14)); - entry.push_back(Pair("Network Max Daily Payments",MaximumEmission)); - entry.push_back(Pair("Network Interest Paid (14 days)", stNet.InterestSubsidy)); - entry.push_back(Pair("Network Avg Daily Interest", stNet.InterestSubsidy/14)); - double MoneySupply = DoubleFromAmount(pindexBest->nMoneySupply); - entry.push_back(Pair("Total Money Supply", MoneySupply)); - double iPct = ( (stNet.InterestSubsidy/14) * 365 / (MoneySupply+.01)); - entry.push_back(Pair("Network Interest %", iPct)); - double magnitude_unit = GRCMagnitudeUnit(GetAdjustedTime()); - entry.push_back(Pair("Magnitude Unit (GRC payment per Magnitude per day)", magnitude_unit)); - } - results.push_back(entry); - - } - } - return results; - } else if (sitem == "help") { Object entry; From 365edbed8c20e5ccdd69e2b487c71127f9200c2b Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Tue, 27 Feb 2018 10:12:18 -0800 Subject: [PATCH 13/28] update changes --- src/bitcoinrpc.cpp | 259 +++++++++++++++++++++++------------------- src/bitcoinrpc.h | 5 +- src/rpcblockchain.cpp | 186 ++++++++++++++++-------------- 3 files changed, 251 insertions(+), 199 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 5078fd7d24..5b0a5500f5 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -268,135 +268,161 @@ Value stop(const Array& params, bool fHelp) static const CRPCCommand vRPCCommands[] = { // name function safemd category // ------------------------ ----------------------- ------ ----------------- - { "help", &help, true, cat_null }, + { "help", &help, true, cat_null }, // Wallet commands - { "addmultisigaddress", &addmultisigaddress, false, cat_wallet }, - { "addredeemscript", &addredeemscript, false, cat_wallet }, - { "backupprivatekeys", &backupprivatekeys, false, cat_wallet }, - { "backupwallet", &backupwallet, true, cat_wallet }, - { "burn", &burn, false, cat_wallet }, - { "burn2", &burn2, false, cat_wallet }, - { "checkwallet", &checkwallet, false, cat_wallet }, - { "createrawtransaction", &createrawtransaction, false, cat_wallet }, - { "decoderawtransaction", &decoderawtransaction, false, cat_wallet }, - { "decodescript", &decodescript, false, cat_wallet }, - { "dumpprivkey", &dumpprivkey, false, cat_wallet }, - { "dumpwallet", &dumpwallet, true, cat_wallet }, - { "encrypt", &encrypt, false, cat_wallet }, - { "encryptwallet", &encryptwallet, false, cat_wallet }, - { "getaccount", &getaccount, false, cat_wallet }, - { "getaccountaddress", &getaccountaddress, true, cat_wallet }, - { "getaddressesbyaccount", &getaddressesbyaccount, true, cat_wallet }, - { "getbalance", &getbalance, false, cat_wallet }, - { "getnewaddress", &getnewaddress, true, cat_wallet }, - { "getnewpubkey", &getnewpubkey, true, cat_wallet }, - { "getrawtransaction", &getrawtransaction, false, cat_wallet }, - { "getreceivedbyaccount", &getreceivedbyaccount, false, cat_wallet }, - { "getreceivedbyaddress", &getreceivedbyaddress, false, cat_wallet }, - { "gettransaction", &gettransaction, false, cat_wallet }, - { "importprivkey", &importprivkey, false, cat_wallet }, - { "importwallet", &importwallet, false, cat_wallet }, - { "keypoolrefill", &keypoolrefill, true, cat_wallet }, - { "listaccounts", &listaccounts, false, cat_wallet }, - { "listaddressgroupings", &listaddressgroupings, false, cat_wallet }, - { "listreceivedbyaccount", &listreceivedbyaccount, false, cat_wallet }, - { "listreceivedbyaddress", &listreceivedbyaddress, false, cat_wallet }, - { "listsinceblock", &listsinceblock, false, cat_wallet }, - { "listtransactions", &listtransactions, false, cat_wallet }, - { "listunspent", &listunspent, false, cat_wallet }, - { "makekeypair", &makekeypair, false, cat_wallet }, - { "move", &movecmd, false, cat_wallet }, - { "newburnaddress", &newburnaddress, false, cat_wallet }, - { "rain", &rain, false, cat_wallet }, - { "repairwallet", &repairwallet, false, cat_wallet }, - { "resendtx", &resendtx, false, cat_wallet }, - { "reservebalance", &reservebalance, false, cat_wallet }, - { "sendfrom", &sendfrom, false, cat_wallet }, - { "sendrawtransaction", &sendrawtransaction, false, cat_wallet }, - { "sendtoaddress", &sendtoaddress, false, cat_wallet }, - { "setaccount", &setaccount, true, cat_wallet }, - { "settxfee", &settxfee, false, cat_wallet }, - { "signmessage", &signmessage, false, cat_wallet }, - { "signrawtransaction", &signrawtransaction, false, cat_wallet }, - { "unspentreport", &unspentreport, false, cat_wallet }, - { "validateaddress", &validateaddress, true, cat_wallet }, - { "validatepubkey", &validatepubkey, true, cat_wallet }, - { "verifymessage", &verifymessage, false, cat_wallet }, - { "walletlock", &walletlock, true, cat_wallet }, - { "walletpassphrase", &walletpassphrase, true, cat_wallet }, - { "walletpassphrasechange", &walletpassphrasechange, false, cat_wallet }, + { "addmultisigaddress", &addmultisigaddress, false, cat_wallet }, + { "addredeemscript", &addredeemscript, false, cat_wallet }, + { "backupprivatekeys", &backupprivatekeys, false, cat_wallet }, + { "backupwallet", &backupwallet, true, cat_wallet }, + { "burn", &burn, false, cat_wallet }, + { "burn2", &burn2, false, cat_wallet }, + { "checkwallet", &checkwallet, false, cat_wallet }, + { "createrawtransaction", &createrawtransaction, false, cat_wallet }, + { "decoderawtransaction", &decoderawtransaction, false, cat_wallet }, + { "decodescript", &decodescript, false, cat_wallet }, + { "dumpprivkey", &dumpprivkey, false, cat_wallet }, + { "dumpwallet", &dumpwallet, true, cat_wallet }, + { "encrypt", &encrypt, false, cat_wallet }, + { "encryptwallet", &encryptwallet, false, cat_wallet }, + { "getaccount", &getaccount, false, cat_wallet }, + { "getaccountaddress", &getaccountaddress, true, cat_wallet }, + { "getaddressesbyaccount", &getaddressesbyaccount, true, cat_wallet }, + { "getbalance", &getbalance, false, cat_wallet }, + { "getnewaddress", &getnewaddress, true, cat_wallet }, + { "getnewpubkey", &getnewpubkey, true, cat_wallet }, + { "getrawtransaction", &getrawtransaction, false, cat_wallet }, + { "getreceivedbyaccount", &getreceivedbyaccount, false, cat_wallet }, + { "getreceivedbyaddress", &getreceivedbyaddress, false, cat_wallet }, + { "gettransaction", &gettransaction, false, cat_wallet }, + { "importprivkey", &importprivkey, false, cat_wallet }, + { "importwallet", &importwallet, false, cat_wallet }, + { "keypoolrefill", &keypoolrefill, true, cat_wallet }, + { "listaccounts", &listaccounts, false, cat_wallet }, + { "listaddressgroupings", &listaddressgroupings, false, cat_wallet }, + { "listreceivedbyaccount", &listreceivedbyaccount, false, cat_wallet }, + { "listreceivedbyaddress", &listreceivedbyaddress, false, cat_wallet }, + { "listsinceblock", &listsinceblock, false, cat_wallet }, + { "listtransactions", &listtransactions, false, cat_wallet }, + { "listunspent", &listunspent, false, cat_wallet }, + { "makekeypair", &makekeypair, false, cat_wallet }, + { "move", &movecmd, false, cat_wallet }, + { "newburnaddress", &newburnaddress, false, cat_wallet }, + { "rain", &rain, false, cat_wallet }, + { "repairwallet", &repairwallet, false, cat_wallet }, + { "resendtx", &resendtx, false, cat_wallet }, + { "reservebalance", &reservebalance, false, cat_wallet }, + { "sendfrom", &sendfrom, false, cat_wallet }, + { "sendrawtransaction", &sendrawtransaction, false, cat_wallet }, + { "sendtoaddress", &sendtoaddress, false, cat_wallet }, + { "setaccount", &setaccount, true, cat_wallet }, + { "settxfee", &settxfee, false, cat_wallet }, + { "signmessage", &signmessage, false, cat_wallet }, + { "signrawtransaction", &signrawtransaction, false, cat_wallet }, + { "unspentreport", &unspentreport, false, cat_wallet }, + { "validateaddress", &validateaddress, true, cat_wallet }, + { "validatepubkey", &validatepubkey, true, cat_wallet }, + { "verifymessage", &verifymessage, false, cat_wallet }, + { "walletlock", &walletlock, true, cat_wallet }, + { "walletpassphrase", &walletpassphrase, true, cat_wallet }, + { "walletpassphrasechange", &walletpassphrasechange, false, cat_wallet }, // Mining commands - { "advertisebeacon", &advertisebeacon, false, cat_mining }, - { "beaconreport", &beaconreport, false, cat_mining }, - { "beaconstatus", &beaconstatus, false, cat_mining }, - { "cpids", &cpids, false, cat_mining }, - { "currentneuralhash", ¤tneuralhash, false, cat_mining }, - { "currentneuralreport", ¤tneuralreport, false, cat_mining }, - { "explainmagnitude", &explainmagnitude, false, cat_mining }, - { "getmininginfo", &getmininginfo, false, cat_mining }, - { "lifetime", &lifetime, false, cat_mining }, - { "magnitude", &magnitude, false, cat_mining }, - { "mymagnitude", &mymagnitude, false, cat_mining }, + { "advertisebeacon", &advertisebeacon, false, cat_mining }, + { "beaconreport", &beaconreport, false, cat_mining }, + { "beaconstatus", &beaconstatus, false, cat_mining }, + { "cpids", &cpids, false, cat_mining }, + { "currentneuralhash", ¤tneuralhash, false, cat_mining }, + { "currentneuralreport", ¤tneuralreport, false, cat_mining }, + { "explainmagnitude", &explainmagnitude, false, cat_mining }, + { "getmininginfo", &getmininginfo, false, cat_mining }, + { "lifetime", &lifetime, false, cat_mining }, + { "magnitude", &magnitude, false, cat_mining }, + { "mymagnitude", &mymagnitude, false, cat_mining }, #ifdef WIN32 - { "myneuralhash", &myneuralhash, false, cat_mining }, - { "neuralhash", &neuralhash, false, cat_mining }, + { "myneuralhash", &myneuralhash, false, cat_mining }, + { "neuralhash", &neuralhash, false, cat_mining }, #endif - { "proveownership", &proveownership, false, cat_mining }, - { "rsa", &rsa, false, cat_mining }, - { "rsaweight", &rsaweight, false, cat_mining }, - { "staketime", &staketime, false, cat_mining }, - { "superblockage", &superblockage, false, cat_mining }, - { "superblocks", &superblocks, false, cat_mining }, - { "syncdpor2", &syncdpor2, false, cat_mining }, - { "upgradedbeaconreport", &upgradedbeaconreport, false, cat_mining }, - { "validcpids", &validcpids, false, cat_mining }, + { "proveownership", &proveownership, false, cat_mining }, + { "rsa", &rsa, false, cat_mining }, + { "rsaweight", &rsaweight, false, cat_mining }, + { "staketime", &staketime, false, cat_mining }, + { "superblockage", &superblockage, false, cat_mining }, + { "superblocks", &superblocks, false, cat_mining }, + { "syncdpor2", &syncdpor2, false, cat_mining }, + { "upgradedbeaconreport", &upgradedbeaconreport, false, cat_mining }, + { "validcpids", &validcpids, false, cat_mining }, // Developer commands - { "addkey", &addkey, false, cat_developer }, + { "addkey", &addkey, false, cat_developer }, #ifdef WIN32 - { "currentcontractaverage", ¤tcontractaverage, false, cat_developer }, + { "currentcontractaverage", ¤tcontractaverage, false, cat_developer }, #endif - { "debug", &debug, true, cat_developer }, - { "debug10", &debug10, true, cat_developer }, - { "debug2", &debug2, true, cat_developer }, - { "debug3", &debug3, true, cat_developer }, - { "debugnet", &debugnet, true, cat_developer }, - { "dportally", &dportally, false, cat_developer }, - { "forcequorom", &forcequorom, false, cat_developer }, - { "gatherneuralhashes", &gatherneuralhashes, false, cat_developer }, - { "genboinckey", &genboinckey, false, cat_developer }, - { "genorgkey", &genorgkey, false, cat_developer }, - { "getblockstats", &rpc_getblockstats, false, cat_developer }, - { "getlistof", &getlistof, false, cat_developer }, - { "getnextproject", &getnextproject, false, cat_developer }, - { "listdata", &listdata, false, cat_developer }, - { "memorizekeys", &memorizekeys, false, cat_developer }, - { "network", &network, false, cat_developer }, - { "neuralrequest", &neuralrequest, false, cat_developer }, - { "projects", &projects, false, cat_developer }, - { "readconfig", &readconfig, false, cat_developer }, - { "readdata", &readdata, false, cat_developer }, + { "debug", &debug, true, cat_developer }, + { "debug10", &debug10, true, cat_developer }, + { "debug2", &debug2, true, cat_developer }, + { "debug3", &debug3, true, cat_developer }, + { "debugnet", &debugnet, true, cat_developer }, + { "dportally", &dportally, false, cat_developer }, + { "forcequorom", &forcequorom, false, cat_developer }, + { "gatherneuralhashes", &gatherneuralhashes, false, cat_developer }, + { "genboinckey", &genboinckey, false, cat_developer }, + { "genorgkey", &genorgkey, false, cat_developer }, + { "getblockstats", &rpc_getblockstats, false, cat_developer }, + { "getlistof", &getlistof, false, cat_developer }, + { "getnextproject", &getnextproject, false, cat_developer }, + { "listdata", &listdata, false, cat_developer }, + { "memorizekeys", &memorizekeys, false, cat_developer }, + { "network", &network, false, cat_developer }, + { "neuralrequest", &neuralrequest, false, cat_developer }, + { "projects", &projects, false, cat_developer }, + { "readconfig", &readconfig, false, cat_developer }, + { "readdata", &readdata, false, cat_developer }, #ifdef WIN32 - { "refhash", &refhash, false, cat_developer }, + { "refhash", &refhash, false, cat_developer }, #endif - { "reorganize", &rpc_reorganize, false, cat_developer }, - { "seefile", &seefile, false, cat_developer }, - { "sendalert", &sendalert, false, cat_developer }, - { "sendalert2", &sendalert2, false, cat_developer }, - { "sendrawcontract", &sendrawcontract, false, cat_developer }, - { "superblockaverage", &superblockaverage, false, cat_developer }, - { "tally", &tally, false, cat_developer }, - { "tallyneural", &tallyneural, false, cat_developer }, + { "reorganize", &rpc_reorganize, false, cat_developer }, + { "seefile", &seefile, false, cat_developer }, + { "sendalert", &sendalert, false, cat_developer }, + { "sendalert2", &sendalert2, false, cat_developer }, + { "sendrawcontract", &sendrawcontract, false, cat_developer }, + { "superblockaverage", &superblockaverage, false, cat_developer }, + { "tally", &tally, false, cat_developer }, + { "tallyneural", &tallyneural, false, cat_developer }, #ifdef WIN32 - { "testnewcontract", &testnewcontract, false, cat_developer }, + { "testnewcontract", &testnewcontract, false, cat_developer }, #endif - { "testorgkey", &testorgkey, false, cat_developer }, - { "unusual", &unusual, false, cat_developer }, - { "updatequoromdata", &updatequoromdata, false, cat_developer }, - { "versionreport", &versionreport, false, cat_developer }, - { "writedata", &writedata, false, cat_developer }, + { "testorgkey", &testorgkey, false, cat_developer }, + { "unusual", &unusual, false, cat_developer }, + { "updatequoromdata", &updatequoromdata, false, cat_developer }, + { "versionreport", &versionreport, false, cat_developer }, + { "writedata", &writedata, false, cat_developer }, + + // Network commands + { "addnode", &addnode, false, cat_network }, + { "addpoll", &addpoll, false, cat_network }, + { "askforoutstandingblocks", &askforoutstandingblocks, false, cat_network }, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, {}, {}, {}, @@ -502,6 +528,9 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri if (strMethod == "sendalert2" && n > 4) ConvertTo<int64_t>(params[4]); if (strMethod == "sendalert2" && n > 5) ConvertTo<int64_t>(params[5]); + // Network + if (strMethod == "addpoll" && n > 1) ConvertTo<double>(params[1]); + if (strMethod == "addpoll" && n > 4) ConvertTo<double>(params[4]); return params; } diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index bd84656b23..4c608d7b08 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -282,13 +282,16 @@ extern json_spirit::Value updatequoromdata(const json_spirit::Array& params, boo extern json_spirit::Value versionreport(const json_spirit::Array& params, bool fhelp); extern json_spirit::value writedata(const json_spirit::Array& params, bool fHelp); +// Network +extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value addpoll(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value askforoutstandingblocks(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value ping(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getnettotals(const json_spirit::Array& params, bool fHelp); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 84f221c6af..6de38e8832 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -2782,6 +2782,109 @@ Value writedata(const Array& params, bool fHelp) return res; } +// Network RPC commands + +Value addpoll(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 6) + throw runtime_error( + "addpoll <title> <days> <question> <answers> <sharetype> <url>\n" + "\n" + "<title> -----> The title for poll with no spaces. Use _ in between words\n" + "<days> ------> The number of days the poll will run\n" + "<question> --> The question with no spaces. Use _ in between words\n" + "<answers> ---> The answers available for voter to choose from. Use - in between words and ; to seperate answers\n" + "<sharetype> -> The share type of the poll; 1 = Magnitude 2 = Balance 3 = Magnitude + Balance 4 = CPID count 5 = Participant count\n" + "<url> -------> The corresponding url for the poll\n" + "Add a poll to the network; Requires 100K GRC balance\n"); + + Object res; + + std::string Title = params[0].get_str(); + double days = Round(params[1].get_real(), 0); + std::string Question = params[2].get_str(); + std::string Answers = params[3].get_str(); + double sharetype = Round(params[4].get_real(), 0); + std::string sURL = params[5].get_str(); + + if (Title.empty() || Question.empty() || Answers.empty()) + { + res.push_back(Pair("Error", "You must specify a Poll Title, Poll Question and Poll Answers.")); + + return res; + } + + else + { + if (days < 7) + { + res.push_back(Pair("Error", "Minimum duration is 7 days; please specify a longer poll duration.")); + + return res; + } + + else + { + double nBalance = GetTotalBalance(); + + if (nBalance < 100000) + { + res.push_back(Pair("Error", "You must have a balance > 100,000 GRC to create a poll. Please post the desired poll on https://cryptocurrencytalk.com/forum/464-gridcoin-grc/ or https://github.com/Erkan-Yilmaz/Gridcoin-tasks/issues/45")); + + return res;; + } + + else + { + if (days < 0 || days == 0) + { + res.push_back(Pair("Error", "You must specify a positive value for days for the expiration date.")); + + return res; + } + + else + { + if (sharetype != 1 && sharetype != 2 && sharetype != 3 && sharetype != 4 && sharetype != 5) + { + res.push_back(Pair("Error", "You must specify a value of 1, 2, 3, 4 or 5 for the sharetype.")); + + return res; + } + + else + { + std::string expiration = RoundToString(GetAdjustedTime() + (days*86400), 0); + std::string contract = "<TITLE>" + Title + "" + days + "" + Question + "" + Answers + "" + sharetype + "" + sURL + "" + expiration + ""; + std::string result = AddContract("poll",Title,contract); + + res.push_back(Pair("Success", "Your poll has been added: " + result)); + + return res; + } + } + } + } + } +} + +Value askforoutstandingblocks(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "askforoutstandingblocks\n" + "\n" + "Requests network for outstanding blocks\n"); + + Object res; + + bool fResult = AskForOutstandingBlocks(uint256(0)); + + res.push_back(Pair("Sent.", fResult)); + + return res; +} + Value execute(const Array& params, bool fHelp) { if (fHelp || (params.size() != 1 && params.size() != 2 && params.size() != 3 && params.size() != 4 && params.size() != 5 && params.size() != 6 && params.size() != 7)) @@ -2831,12 +2934,6 @@ Value execute(const Array& params, bool fHelp) entry.push_back(Pair("Result",fResult)); results.push_back(entry); } - else if (sItem == "askforoutstandingblocks") - { - bool fResult = AskForOutstandingBlocks(uint256(0)); - entry.push_back(Pair("Sent.",fResult)); - results.push_back(entry); - } else if (sItem == "vote") { if (params.size() != 3) @@ -2953,83 +3050,6 @@ Value execute(const Array& params, bool fHelp) } } - } - else if (sItem == "addpoll") - { - if (params.size() != 7) - { - entry.push_back(Pair("Error","You must specify the Poll Title, Expiration In DAYS from Now, Question, Answers delimited by a semicolon, ShareType (1=Magnitude,2=Balance,3=Both,4=CPIDCount,5=ParticipantCount) and discussion URL (use TinyURL.com to make a small URL). Please use underscores in place of spaces inside a sentence. ")); - entry.push_back(Pair("execute addpoll <days> <question> <answers> <sharetype> <url>", "Add a poll (Requires minimum 100000 GRC balance)")); - entry.push_back(Pair("<title>", "Title for poll with no spaces. Use _ in between words")); - entry.push_back(Pair("<days>", "Number of days the poll will run")); - entry.push_back(Pair("<question>", "The poll question in which you seek input for")); - entry.push_back(Pair("<answers>", "The available answers to which a voter can vote seperated by a semicolon")); - entry.push_back(Pair("<sharetype>", "1 = Magnitude 2 = Balance 3 = Magnitude + Balance 4 = CPID count 5 = Participant count")); - entry.push_back(Pair("<url>", "Short url for information about the poll")); - results.push_back(entry); - } - else - { - std::string Title = params[1].get_str(); - std::string Days = params[2].get_str(); - double days = RoundFromString(Days,0); - std::string Question = params[3].get_str(); - std::string Answers = params[4].get_str(); - std::string ShareType = params[5].get_str(); - std::string sURL = params[6].get_str(); - double sharetype = RoundFromString(ShareType,0); - if (Title=="" || Question == "" || Answers == "") - { - entry.push_back(Pair("Error","You must specify a Poll Title, Poll Question and Poll Answers.")); - results.push_back(entry); - } - else - { - if (days < 7) - { - entry.push_back(Pair("Error","Minimum duration is 7 days; please specify a longer poll duration.")); - results.push_back(entry); - } - else - { - double nBalance = GetTotalBalance(); - - if (nBalance < 100000) - { - entry.push_back(Pair("Error","You must have a balance > 100,000 GRC to create a poll. Please post the desired poll on https://cryptocurrencytalk.com/forum/464-gridcoin-grc/ or https://github.com/Erkan-Yilmaz/Gridcoin-tasks/issues/45")); - results.push_back(entry); - } - else - { - if (days < 0 || days == 0) - { - entry.push_back(Pair("Error","You must specify a positive value for days for the expiration date.")); - results.push_back(entry); - - } - else - { - if (sharetype != 1 && sharetype != 2 && sharetype != 3 && sharetype !=4 && sharetype !=5) - { - entry.push_back(Pair("Error","You must specify a value of 1, 2, 3, 4 or 5 for the sharetype.")); - results.push_back(entry); - - } - else - { - std::string expiration = RoundToString(GetAdjustedTime() + (days*86400),0); - std::string contract = "<TITLE>" + Title + "" + RoundToString(days,0) + "" + Question + "" + Answers + "" + RoundToString(sharetype,0) + "" + sURL + "" + expiration + ""; - std::string result = AddContract("poll",Title,contract); - entry.push_back(Pair("Success","Your poll has been added: " + result)); - results.push_back(entry); - } - - } - } - } - } - } - } else if (sItem == "votedetails") { From 7cebebd4a03aa5a944b9297a99b34a406bec2d18 Mon Sep 17 00:00:00 2001 From: Paul Jensen Date: Wed, 28 Feb 2018 14:03:12 -0800 Subject: [PATCH 14/28] more done --- src/bitcoinrpc.cpp | 26 ++++--- src/bitcoinrpc.h | 19 +++-- src/rpcblockchain.cpp | 163 +++++++++++++++++++++++++----------------- src/rpcnet.cpp | 2 +- 4 files changed, 126 insertions(+), 84 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 5b0a5500f5..1b73078ee7 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -402,16 +402,16 @@ static const CRPCCommand vRPCCommands[] = { "addnode", &addnode, false, cat_network }, { "addpoll", &addpoll, false, cat_network }, { "askforoutstandingblocks", &askforoutstandingblocks, false, cat_network }, - {}, - {}, - {}, - {}, - {}, - {}, - {}, - {}, - {}, - {}, + { "currenttime", ¤ttime, false, cat_network }, + { "decryptphrase", &decryptphrase, false, cat_network }, +// { "downloadblocks", &downloadblocks, false, cat_network }, + { "encryptphrase", &encryptphrase, false, cat_network }, + { "getaddednodeinfo", &getaddednodeinfo, true, cat_network }, + { "getbestblockhash", &getbestblockhash, true, cat_network }, + { "getblock", &getblock, true, cat_network }, + { "getblockbynumber", &getblockbynumber, true, cat_network }, + { "getblockcount", &getblockcount, true, cat_network }, + { "getblockhash", &getblockhash, true, cat_network }, {}, {}, {}, @@ -531,6 +531,12 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 1) ConvertTo(params[1]); if (strMethod == "addpoll" && n > 4) ConvertTo(params[4]); + if (strMethod == "getaddednodeinfo" && n > 0) ConvertTo(params[0]); + if (strMethod == "getblock" && n > 1) ConvertTo(params[1]); + if (strMethod == "getblockbynumber" && n > 0) ConvertTo(params[0]); + if (strMethod == "getblockbynumber" && n > 1) ConvertTo(params[1]); + if (strMethod == "getblockhash" && n > 0) ConvertTo(params[0]); + return params; } diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 4c608d7b08..63612b2b79 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -286,26 +286,33 @@ extern json_spirit::value writedata(const json_spirit::Array& params, bool fHelp extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value addpoll(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value askforoutstandingblocks(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value currenttime(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value decryptphrase(const json_spirit::Array& params, bool fHelp); +//extern json_spirit::Value downloadblocks(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value encryptphrase(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getbestblockhash(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getblockbynumber(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getblockhash(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value ping(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getnettotals(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getinfo(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getbestblockhash(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp -extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp + extern json_spirit::Value getdifficulty(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getrawmempool(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getblockhash(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getblockbynumber(const json_spirit::Array& params, bool fHelp); + + extern json_spirit::Value getcheckpoint(const json_spirit::Array& params, bool fHelp); //Gridcoin RPC Commands: diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 6de38e8832..3df8756481 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -388,7 +388,9 @@ Value getbestblockhash(const Array& params, bool fHelp) if (fHelp || params.size() != 0) throw runtime_error( "getbestblockhash\n" - "Returns the hash of the best block in the longest block chain."); + "Returns the hash of the best block in the longest block chain.\n"); + + LOCK(cs_main); return hashBestChain.GetHex(); } @@ -398,7 +400,9 @@ Value getblockcount(const Array& params, bool fHelp) if (fHelp || params.size() != 0) throw runtime_error( "getblockcount\n" - "Returns the number of blocks in the longest block chain."); + "Returns the number of blocks in the longest block chain.\n"); + + LOCK(cs_main); return nBestHeight; } @@ -409,7 +413,9 @@ Value getdifficulty(const Array& params, bool fHelp) if (fHelp || params.size() != 0) throw runtime_error( "getdifficulty\n" - "Returns the difficulty as a multiple of the minimum difficulty."); + "Returns the difficulty as a multiple of the minimum difficulty.\n"); + + LOCK(cs_main); Object obj; obj.push_back(Pair("proof-of-work", GetDifficulty())); @@ -455,11 +461,14 @@ Value getblockhash(const Array& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "getblockhash \n" - "Returns hash of block in best-block-chain at ."); + "Returns hash of block in best-block-chain at .\n"); int nHeight = params[0].get_int(); if (nHeight < 0 || nHeight > nBestHeight) throw runtime_error("Block number out of range."); if (fDebug10) LogPrintf("Getblockhash %f",(double)nHeight); + + LOCK(cs_main); + CBlockIndex* RPCpblockindex = RPCBlockFinder.FindByHeight(nHeight); return RPCpblockindex->phashBlock->GetHex(); } @@ -470,11 +479,13 @@ Value getblock(const Array& params, bool fHelp) throw runtime_error( "getblock [txinfo]\n" "txinfo optional to print more detailed tx info\n" - "Returns details of a block with given block-hash."); + "Returns details of a block with given block-hash.\n"); std::string strHash = params[0].get_str(); uint256 hash(strHash); + LOCK(cs_main); + if (mapBlockIndex.count(hash) == 0) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); @@ -491,7 +502,9 @@ Value getblockbynumber(const Array& params, bool fHelp) throw runtime_error( "getblockbynumber [txinfo]\n" "txinfo optional to print more detailed tx info\n" - "Returns details of a block with given block-number."); + "Returns details of a block with given block-number.\n"); + + LOCK(cs_main); int nHeight = params[0].get_int(); if (nHeight < 0 || nHeight > nBestHeight) @@ -2885,6 +2898,83 @@ Value askforoutstandingblocks(const Array& params, bool fHelp) return res; } +Value currenttime(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "currenttime\n" + "\n" + "Displays UTC unix time as well as date and time in UTC\n"); + + Object res; + + res.push_back(Pair("Unix", GetAdjustedTime())); + res.push_back(Pair("UTC", TimestampToHRDate(GetAdjustedTime()))); + + return res; +} + +Value decryptphrase(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "decryptphrase \n" + "\n" + " -> Encrypted phrase to decrypt\n" + "Decrypts an encrypted phrase\n"); + + Object res; + + std::string sParam1 = params[0].get_str(); + std::string test = AdvancedDecrypt(sParam1); + + res.push_back(Pair("Phrase", sParam1)); + res.push_back(Pair("Decrypted Phrase", test)); + + return res; +} + +/* +#ifdef WIN32 +Value downloadblocks(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "downloadblocks\n" + "\n" + "Download blocks from a snapshot\n"); + + Object res; + + int r = Restarter::DownloadGridcoinBlocks(); + + res.push_back(Pair("Download Blocks", r)); + + return res; +} +#endif +*/ + +Value encryptphrase(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "encryptphrase \n" + "\n" + " Phase you wish to encrypt\n" + "Encrypt a phrase\n"); + + Object res; + + std::string sParam1 = params[0].get_str(); + std::string test = AdvancedCrypt(sParam1); + + res.push_back(Pair("Phrase", sParam1)); + res.push_back(Pair("Encrypted Phrase", test)); + + return res; +} + Value execute(const Array& params, bool fHelp) { if (fHelp || (params.size() != 1 && params.size() != 2 && params.size() != 3 && params.size() != 4 && params.size() != 5 && params.size() != 6 && params.size() != 7)) @@ -3134,43 +3224,7 @@ Value execute(const Array& params, bool fHelp) } } } - else if (sItem == "encryptphrase") - { - if (params.size() != 2) - { - entry.push_back(Pair("Error","You must specify a phrase")); - results.push_back(entry); - } - else - { - std::string sParam1 = params[1].get_str(); - entry.push_back(Pair("Param1",sParam1)); - std::string test = AdvancedCrypt(sParam1); - entry.push_back(Pair("EncPhrase",test)); - results.push_back(entry); - - } - - } - else if (sItem == "decryptphrase") - { - if (params.size() != 2) - { - entry.push_back(Pair("Error","You must specify a phrase")); - results.push_back(entry); - } - else - { - std::string sParam1 = params[1].get_str(); - entry.push_back(Pair("Param1",sParam1)); - std::string test = AdvancedDecrypt(sParam1); - entry.push_back(Pair("DecPhrase",test)); - results.push_back(entry); - - } - - } else if (sItem == "reindex") { int r = Restarter::CreateGridcoinRestorePoint(); @@ -3178,12 +3232,6 @@ Value execute(const Array& params, bool fHelp) entry.push_back(Pair("Reindex Chain",r)); results.push_back(entry); } - /*else if (sItem == "downloadblocks") - { - int r=Restarter::DownloadGridcoinBlocks(); - entry.push_back(Pair("Download Blocks",r)); - results.push_back(entry); - }*/ else if (sItem == "resetcpids") { //Reload the config file @@ -3193,16 +3241,6 @@ Value execute(const Array& params, bool fHelp) entry.push_back(Pair("Reset",1)); results.push_back(entry); } - else if (sItem == "encrypt_deprecated") - { - std::string s1 = "1234"; - std::string s1dec = AdvancedCrypt(s1); - std::string s1out = AdvancedDecrypt(s1dec); - entry.push_back(Pair("Execute Encrypt result1",s1)); - entry.push_back(Pair("Execute Encrypt result2",s1dec)); - entry.push_back(Pair("Execute Encrypt result3",s1out)); - results.push_back(entry); - } else if (sItem == "help") { entry.push_back(Pair("execute addpoll <days> <question> <answers> <sharetype> <url>", "Add a poll (Requires minimum 100000 GRC balance)")); @@ -4574,15 +4612,6 @@ Value listitem(const Array& params, bool fHelp) entry.push_back(Pair("Network Time",GetAdjustedTime())); results.push_back(entry); } - else if (sitem == "currenttime") - { - - Object entry; - entry.push_back(Pair("Unix",GetAdjustedTime())); - entry.push_back(Pair("UTC",TimestampToHRDate(GetAdjustedTime()))); - results.push_back(entry); - - } else if (sitem == "memorypool") { Object entry; diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 9a520e176a..4b4f08dd91 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -93,7 +93,7 @@ Value addnode(const Array& params, bool fHelp) (strCommand != "onetry" && strCommand != "add" && strCommand != "remove")) throw runtime_error( "addnode <node> <add|remove|onetry>\n" - "Attempts add or remove <node> from the addnode list or try a connection to <node> once."); + "Attempts add or remove <node> from the addnode list or try a connection to <node> once.\n"); string strNode = params[0].get_str(); From afacace63d7cca714416b880497b2f19c08bd824 Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Tue, 6 Mar 2018 16:45:07 -0800 Subject: [PATCH 15/28] Complete with some refactoring; TODO spacing --- src/bitcoinrpc.cpp | 46 ++- src/bitcoinrpc.h | 39 ++- src/rpcblockchain.cpp | 761 ++++++++++++++++++++---------------------- src/rpcnet.cpp | 3 + src/rpcwallet.cpp | 3 + 5 files changed, 423 insertions(+), 429 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 1b73078ee7..cff87a023c 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -268,7 +268,9 @@ Value stop(const Array& params, bool fHelp) static const CRPCCommand vRPCCommands[] = { // name function safemd category // ------------------------ ----------------------- ------ ----------------- + { "list", &listitem, true, cat_null }, { "help", &help, true, cat_null }, + { "execute", &execute, true, cat_null }, // Wallet commands { "addmultisigaddress", &addmultisigaddress, false, cat_wallet }, @@ -344,6 +346,7 @@ static const CRPCCommand vRPCCommands[] = { "neuralhash", &neuralhash, false, cat_mining }, #endif { "proveownership", &proveownership, false, cat_mining }, + { "resetcpids", &resetcpids, false, cat_mining }, { "rsa", &rsa, false, cat_mining }, { "rsaweight", &rsaweight, false, cat_mining }, { "staketime", &staketime, false, cat_mining }, @@ -385,6 +388,7 @@ static const CRPCCommand vRPCCommands[] = { "seefile", &seefile, false, cat_developer }, { "sendalert", &sendalert, false, cat_developer }, { "sendalert2", &sendalert2, false, cat_developer }, + { "sendblock", &sendblock, false, cat_developer }, { "sendrawcontract", &sendrawcontract, false, cat_developer }, { "superblockaverage", &superblockaverage, false, cat_developer }, { "tally", &tally, false, cat_developer }, @@ -412,21 +416,30 @@ static const CRPCCommand vRPCCommands[] = { "getblockbynumber", &getblockbynumber, true, cat_network }, { "getblockcount", &getblockcount, true, cat_network }, { "getblockhash", &getblockhash, true, cat_network }, - {}, - {}, - {}, - {}, - {}, - {}, - {}, - {}, - {}, - {}, - {}, - {}, - {}, - {}, - + { "getcheckpoint", &getcheckpoint, true, cat_network }, + { "getconnectioncount", &getconnectioncount, true, cat_network }, + { "getdifficulty", &getdifficulty, true, cat_network }, + { "getinfo", &getinfo, true, cat_network }, + { "getnettotals", &getnettotals, true, cat_network }, + { "getpeerinfo", &getpeerinfo, true, cat_network }, + { "getrawmempool", &getrawmempool, true, cat_network }, + { "listallpolls", &listallpolls, true, cat_network }, + { "listallpolldetails", &listallpolldetails, true, cat_network }, + { "listpolldetails", &listpolldetails, true, cat_network }, + { "listpollresults", &listpollresults, true, cat_network }, + { "listpolls", &listpolls, true, cat_network }, + { "memorypool", &memorypool, true, cat_network }, + { "networktime", &networktime, true, cat_network }, + { "ping", &ping, true, cat_network }, +#ifdef WIN32 + { "reindex", &reindex, true, cat_network }, + { "restart", &restart, true, cat_network }, + { "restorepoint", &restorepoint, true, cat_network }, +#endif + { "showblock", &showblock, true, cat_network }, + { "stop", &stop, true, cat_network }, + { "vote", &vote, false, cat_network }, + { "votedetails", &votedetails, true, cat_network } }; template<typename T> @@ -536,7 +549,8 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri if (strMethod == "getblockbynumber" && n > 0) ConvertTo<int64_t>(params[0]); if (strMethod == "getblockbynumber" && n > 1) ConvertTo<bool>(params[1]); if (strMethod == "getblockhash" && n > 0) ConvertTo<int64_t>(params[0]); - + if (strMethod == "listpollresults" && n > 1) ConvertTo<bool>(params[1]); + if (strMethod == "showblock" && n > 0) ConvertTo<int64_t>(params[0]); return params; } diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 63612b2b79..c8ec80625e 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -152,6 +152,10 @@ extern std::vector<unsigned char> ParseHexV(const json_spirit::Value& v, std::st // Rpc reordered by category +// Deprecated +extern json_spirit::Value listitem(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value execute(const json_spirit::Array& params, bool fHelp); + // Wallet extern json_spirit::Value addmultisigaddress(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value addredeemscript(const json_spirit::Array& params, bool fHelp); @@ -228,6 +232,7 @@ extern json_spirit::Value neuralhash(const json_spirit::Array& params, bool fHel #endif extern json_spirit::Value neuralreport(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value proveownership(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value resetcpids(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value rsa(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value rsaweight(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value staketime(const json_spirit::Array& params, bool fHelp); @@ -269,6 +274,7 @@ extern json_spirit::Value rpc_reorganize(const json_spirit::Array& params, bool extern json_spirit::Value seefile(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value sendalert(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value sendalert2(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value sendblock(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value sendrawcontract(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value superblockaverage(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value tally(const json_spirit::Array& params, bool fHelp); @@ -296,29 +302,40 @@ extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp) extern json_spirit::Value getblockbynumber(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getblockhash(const json_spirit::Array& params, bool fHelp); - - -extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp +extern json_spirit::Value getcheckpoint(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getdifficulty(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getinfo(const json_spirit::Array& params, bool fHelp); // To Be Deprecated --> getblockchaininfo getnetworkinfo getwalletinfo +extern json_spirit::Value getnettotals(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getrawmempool(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value listallpolls(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value listallpolldetails(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value listpolldetails(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value listpollresults(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value listpolls(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value memorypool(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value networktime(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value ping(const json_spirit::Array& params, bool fHelp); +#ifdef WIN32 +extern json_spirit::Value reindex(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value restart(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value restorepoint(const json_spirit::Array& params, bool fHelp); +#endif +extern json_spirit::Value showblock(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value vote(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value votedetails(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getnettotals(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getinfo(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getdifficulty(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getrawmempool(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value getcheckpoint(const json_spirit::Array& params, bool fHelp); //Gridcoin RPC Commands: -extern json_spirit::Value showblock(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value listitem(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value execute(const json_spirit::Array& params, bool fHelp); + // Brod diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 3df8756481..e35da80952 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -370,6 +370,9 @@ Value showblock(const Array& params, bool fHelp) int nHeight = params[0].get_int(); if (nHeight < 0 || nHeight > nBestHeight) throw runtime_error("Block number out of range."); + + LOCK(cs_main); + CBlockIndex* pblockindex = RPCBlockFinder.FindByHeight(nHeight); if (pblockindex==NULL) @@ -470,6 +473,7 @@ Value getblockhash(const Array& params, bool fHelp) LOCK(cs_main); CBlockIndex* RPCpblockindex = RPCBlockFinder.FindByHeight(nHeight); + return RPCpblockindex->phashBlock->GetHex(); } @@ -1801,6 +1805,24 @@ Value proveownership(const Array& params, bool fHelp) return res; } +Value resetcpids(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "resetcpids\n" + "\n" + "Reloads cpids\n"); + + Object res; + + ReadConfigFile(mapArgs, mapMultiArgs); + HarvestCPIDs(true); + GetNextProject(true); + res.push_back(Pair("Reset", 1)); + + return res; +} + Value rsa(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) @@ -2557,6 +2579,26 @@ Value refhash(const Array& params, bool fHelp) } #endif +Value sendblock(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "sendblock <blockhash>\n" + "\n" + "<blockhash> Blockhash of block to send to network\n" + "Sends a block to the network\n"); + + Object res; + + std::string sHash = params[0].get_str(); + uint256 hash = uint256(sHash); + bool fResult = AskForOutstandingBlocks(hash); + + res.push_back(Pair("Requesting", hash.ToString())); + res.push_back(Pair("Result", fResult)); + + return res; +} Value sendrawcontract(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) @@ -2820,67 +2862,50 @@ Value addpoll(const Array& params, bool fHelp) double sharetype = Round(params[4].get_real(), 0); std::string sURL = params[5].get_str(); - if (Title.empty() || Question.empty() || Answers.empty()) + if (Title.empty() || Question.empty() || Answers.empty() || sURL.empty()) { - res.push_back(Pair("Error", "You must specify a Poll Title, Poll Question and Poll Answers.")); + res.push_back(Pair("Error", "Must specify a poll title, question, answers, and URL\n")); return res; } + if (days < 7) + res.push_back(Pair("Error", "Minimum duration is 7 days; please specify a longer poll duration.")); + else { - if (days < 7) - { - res.push_back(Pair("Error", "Minimum duration is 7 days; please specify a longer poll duration.")); - return res; - } + LOCK2(cs_main, pwalletMain->cs_wallet); - else - { - double nBalance = GetTotalBalance(); + double nBalance = GetTotalBalance(); - if (nBalance < 100000) - { - res.push_back(Pair("Error", "You must have a balance > 100,000 GRC to create a poll. Please post the desired poll on https://cryptocurrencytalk.com/forum/464-gridcoin-grc/ or https://github.com/Erkan-Yilmaz/Gridcoin-tasks/issues/45")); + if (nBalance < 100000) + res.push_back(Pair("Error", "You must have a balance > 100,000 GRC to create a poll. Please post the desired poll on https://cryptocurrencytalk.com/forum/464-gridcoin-grc/ or https://github.com/Erkan-Yilmaz/Gridcoin-tasks/issues/45")); - return res;; - } + else + { + if (days < 0 || days == 0) + res.push_back(Pair("Error", "You must specify a positive value for days for the expiration date.")); else { - if (days < 0 || days == 0) - { - res.push_back(Pair("Error", "You must specify a positive value for days for the expiration date.")); - - return res; - } + if (sharetype != 1 && sharetype != 2 && sharetype != 3 && sharetype != 4 && sharetype != 5) + res.push_back(Pair("Error", "You must specify a value of 1, 2, 3, 4 or 5 for the sharetype.")); else { - if (sharetype != 1 && sharetype != 2 && sharetype != 3 && sharetype != 4 && sharetype != 5) - { - res.push_back(Pair("Error", "You must specify a value of 1, 2, 3, 4 or 5 for the sharetype.")); - - return res; - } + std::string expiration = RoundToString(GetAdjustedTime() + (days*86400), 0); + std::string contract = "<TITLE>" + Title + "" + days + "" + Question + "" + Answers + "" + sharetype + "" + sURL + "" + expiration + ""; + std::string result = AddContract("poll",Title,contract); - else - { - std::string expiration = RoundToString(GetAdjustedTime() + (days*86400), 0); - std::string contract = "" + Title + "" + days + "" + Question + "" + Answers + "" + sharetype + "" + sURL + "" + expiration + ""; - std::string result = AddContract("poll",Title,contract); - - res.push_back(Pair("Success", "Your poll has been added: " + result)); - - return res; - } + res.push_back(Pair("Success", "Your poll has been added: " + result)); } } } } -} + return res; +} Value askforoutstandingblocks(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) @@ -2975,345 +3000,332 @@ Value encryptphrase(const Array& params, bool fHelp) return res; } -Value execute(const Array& params, bool fHelp) +Value listallpolls(const Array& params, bool fHelp) { - if (fHelp || (params.size() != 1 && params.size() != 2 && params.size() != 3 && params.size() != 4 && params.size() != 5 && params.size() != 6 && params.size() != 7)) + if (fHelp || params.size() != 0) throw runtime_error( - "execute \r\n" - "Executes an arbitrary command by name.\n" - "execute help\n" - "Displays help on various available execute commands.\n"); + "listallpolls\n" + "\n" + "Lists all polls\n"); - std::string sItem = params[0].get_str(); + LOCK(cs_main); - if (sItem=="") throw runtime_error("Item invalid."); + std::string out1; + Array res = GetJSONPollsReport(false, "", out1, true); - Array results; - Object oOut; - oOut.push_back(Pair("Command",sItem)); - results.push_back(oOut); - Object entry; + return res; +} - if (sItem == "restorepoint") - { - int r= Restarter::CreateGridcoinRestorePoint(); - //We must stop the node before we can do this - //RestartGridcoin(); - entry.push_back(Pair("Restore Point",r)); - results.push_back(entry); - } - else if (sItem == "restart") - { - printf("Restarting Gridcoin..."); - int iResult = Restarter::RestartGridcoin(); - entry.push_back(Pair("RebootClient", iResult)); - results.push_back(entry); +Value listallpolldetails(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "listallpolldetails\n" + "\n" + "Lists all polls with details\n"); - } - else if (sItem == "sendblock") - { - if (params.size() != 2) - { - entry.push_back(Pair("Error","You must specify the block hash to send.")); - results.push_back(entry); - } - std::string sHash = params[1].get_str(); - uint256 hash = uint256(sHash); - bool fResult = AskForOutstandingBlocks(hash); - entry.push_back(Pair("Requesting",hash.ToString())); - entry.push_back(Pair("Result",fResult)); - results.push_back(entry); - } - else if (sItem == "vote") - { - if (params.size() != 3) - { - entry.push_back(Pair("Error","You must specify the Poll Title, and the Answer. For example: execute vote gender male.")); - results.push_back(entry); - } - else - { - std::string Title = params[1].get_str(); - std::string Answer = params[2].get_str(); - if (Title=="" || Answer == "" ) - { - entry.push_back(Pair("Error","You must specify both the answer and the title.")); - results.push_back(entry); + LOCK(cs_main); - } - else - { - //Verify the Existence of the poll, the acceptability of the answer, and the expiration of the poll: (EXIST, EXPIRED, ACCEPTABLE) - //If polltype == 1, use magnitude, if 2 use Balance, if 3 use hybrid: - //6-20-2015 - double nBalance = GetTotalBalance(); - uint256 hashRand = GetRandHash(); - std::string email = GetArgument("email", "NA"); - boost::to_lower(email); - GlobalCPUMiningCPID.email=email; - GlobalCPUMiningCPID.cpidv2 = ComputeCPIDv2(GlobalCPUMiningCPID.email, GlobalCPUMiningCPID.boincruntimepublickey, hashRand); - GlobalCPUMiningCPID.lastblockhash = GlobalCPUMiningCPID.cpidhash; - - if (!PollExists(Title)) - { - entry.push_back(Pair("Error","Poll does not exist.")); - results.push_back(entry); + std::string out1; + Array res = GetJSONPollsReport(true, "", out1, true); - } - else - { - if (PollExpired(Title)) - { - entry.push_back(Pair("Error","Sorry, Poll is already expired.")); - results.push_back(entry); - } - else - { - if (!PollAcceptableAnswer(Title,Answer)) - { - std::string acceptable_answers = PollAnswers(Title); - entry.push_back(Pair("Error","Sorry, Answer " + Answer + " is not one of the acceptable answers, allowable answers are: " + acceptable_answers + ". If you are voting multiple choice, please use a semicolon delimited vote string such as : 'dog;cat'.")); - results.push_back(entry); - } - else - { - std::string sParam = SerializeBoincBlock(GlobalCPUMiningCPID,pindexBest->nVersion); - std::string GRCAddress = DefaultWalletAddress(); - StructCPID structMag = GetInitializedStructCPID2(GlobalCPUMiningCPID.cpid,mvMagnitudes); - double dmag = structMag.Magnitude; - double poll_duration = PollDuration(Title)*86400; - - // Prevent Double Voting - std::string cpid1 = GlobalCPUMiningCPID.cpid; - std::string GRCAddress1 = DefaultWalletAddress(); - GetEarliestStakeTime(GRCAddress1,cpid1); - double cpid_age = GetAdjustedTime() - ReadCache("global", "nCPIDTime").timestamp; - double stake_age = GetAdjustedTime() - ReadCache("global", "nGRCTime").timestamp; - - StructCPID structGRC = GetInitializedStructCPID2(GRCAddress,mvMagnitudes); - - - printf("CPIDAge %f,StakeAge %f,Poll Duration %f \r\n",cpid_age,stake_age,poll_duration); - - double dShareType= RoundFromString(GetPollXMLElementByPollTitle(Title,"",""),0); - - // Share Type 1 == "Magnitude" - // Share Type 2 == "Balance" - // Share Type 3 == "Both" - if (cpid_age < poll_duration) dmag = 0; - if (stake_age < poll_duration) nBalance = 0; - - if ((dShareType == 1) && cpid_age < poll_duration) - { - entry.push_back(Pair("Error","Sorry, When voting in a magnitude poll, your CPID must be older than the poll duration.")); - results.push_back(entry); - } - else if (dShareType == 2 && stake_age < poll_duration) - { - entry.push_back(Pair("Error","Sorry, When voting in a Balance poll, your stake age must be older than the poll duration.")); - results.push_back(entry); - } - else if (dShareType == 3 && stake_age < poll_duration && cpid_age < poll_duration) - { - entry.push_back(Pair("Error","Sorry, When voting in a Both Share Type poll, your stake age Or your CPID age must be older than the poll duration.")); - results.push_back(entry); - } - else - { - std::string voter = ""+GlobalCPUMiningCPID.cpidv2 + "" - + GlobalCPUMiningCPID.cpid + "" + GRCAddress + "" - + hashRand.GetHex() + "" + RoundToString(nBalance,2) - + "" + RoundToString(dmag,0) + ""; - // Add the provable balance and the provable magnitude - this goes into effect July 1 2017 - voter += GetProvableVotingWeightXML(); - std::string pk = Title + ";" + GRCAddress + ";" + GlobalCPUMiningCPID.cpid; - std::string contract = "" + Title + "" + Answer + "" + voter; - std::string result = AddContract("vote",pk,contract); - std::string narr = "Your CPID weight is " + RoundToString(dmag,0) + " and your Balance weight is " + RoundToString(nBalance,0) + "."; - entry.push_back(Pair("Success",narr + " " + "Your vote has been cast for topic " + Title + ": With an Answer of " + Answer + ": " + result.c_str())); - results.push_back(entry); - } - } - } - } + return res; +} - } - } +Value listpolldetails(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "listpolldetails\n" + "\n" + "Lists poll details\n"); - } - else if (sItem == "votedetails") - { - if (params.size() != 2) - { - entry.push_back(Pair("Error","You must specify the Poll Title.")); - results.push_back(entry); - } - else - { - std::string Title1 = params[1].get_str(); + LOCK(cs_main); - if (!PollExists(Title1)) - { - entry.push_back(Pair("Error","Poll does not exist. Please execute listpolls.")); - results.push_back(entry); + std::string out1; + Array res = GetJSONPollsReport(true, "", out1, false); - } - else - { - std::string Title = params[1].get_str(); - Array myVotes = GetJsonVoteDetailsReport(Title); - results.push_back(myVotes); - } - } - } - else if (sItem == "listpolls") + return res; +} + +Value listpollresults(const Array& params, bool fHelp) +{ + if (fHelp || params.size() > 2 || params.size() < 1) + throw runtime_error( + "listpollresults [bool:showexpired]\n" + "\n" + " ----> name of the poll\n" + "[showexpired] -> Optional; Default false\n" + "Displays results for specified poll\n"); + + LOCK(cs_main); + + Object res; + bool bIncExpired = false; + + if (params.size() == 2) + bIncExpired = params[1].get_bool(); + + std::string Title1 = params[0].get_str(); + + if (!PollExists(Title1)) { - std::string out1; - Array myPolls = GetJSONPollsReport(false,"",out1,false); - results.push_back(myPolls); + res.push_back(Pair("Error", "Poll does not exist. Please listpolls.")); + + return res } - else if (sItem == "listallpolls") + + else { - std::string out1; - Array myPolls = GetJSONPollsReport(false,"",out1,true); - results.push_back(myPolls); + std::string Title = params[0].get_str(); + std::string out1 = ""; + Array myPolls = GetJSONPollsReport(true, Title, out1, bIncExpired); + res.push_back(myPolls); } - else if (sItem == "listallpolldetails") - { - std::string out1; - Array myPolls = GetJSONPollsReport(true,"",out1,true); - results.push_back(myPolls); - } - else if (sItem=="listpolldetails") + return res; +} + +Value listpolls(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "listpolls\n" + "\n" + "Lists polls\n"); + + LOCK(cs_main); + + std::string out1; + Array res = GetJSONPollsReport(false, "", out1, false); + + return res; +} + +Value memorypool(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "memorypool\n" + "\n" + "Displays included and excluded memory pool txs\n"); + + Object res; + + res.push_back(Pair("Excluded Tx", msMiningErrorsExcluded)); + res.push_back(Pair("Included Tx", msMiningErrorsIncluded)); + + return res; +} + +Value networktime(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "networktime\n" + "\n" + "Displays current network time\n"); + + Object res; + + res.push_back(Pair("Network Time", GetAdjustedTime())); + + return res; +} + +#ifdef WIN32 +Value reindex(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "reindex\n" + "\n" + "Re-index the block chain\n"); + + Object res; + + int r = Restarter::CreateGridcoinRestorePoint(); + Restarter::ReindexGridcoinWallet(); + res.push_back(Pair("Reindex Chain", r)); + + return res; +} + +Value restart(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "restart\n" + "\n" + "Restarts the wallet\n"); + + Object res; + + printf("Restarting Gridcoin..."); + int iResult = Restarter::RestartGridcoin(); + res.push_back(Pair("RebootClient", iResult)); + + return res; +} + +Value restorepoint(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "restorepoint\n" + "\n" + "Create a restore point\n"); + + Object res; + + int r= Restarter::CreateGridcoinRestorePoint(); + //We must stop the node before we can do this + //RestartGridcoin(); + res.push_back(Pair("Restore Point", r)); + + return res; +} +#endif + +Value vote(const Array& params, bool fHelp) +{ + if (fHelp || params.size != 2) + throw runtime_error( + "vote <answers>\n" + "\n" + "<title -> Title of poll being voted on\n" + "<answers> -> Answers chosen for specified poll seperated by ;\n" + "Vote on a specific poll with specified answers\n"); + + Object res; + + std::string Title = params[0].get_str(); + std::string Answer = params[1].get_str(); + + if (Title.empty() || Answer.empty()) { - std::string out1; - Array myPolls = GetJSONPollsReport(true,"",out1,false); - results.push_back(myPolls); + res.push_back(Pair("Error", "Must specify a poll title and answers\n")); + + return res; } - else if (sItem=="listpollresults") + + LOCK2(cs_main, pwalletMain->cs_wallet); + + //Verify the Existence of the poll, the acceptability of the answer, and the expiration of the poll: (EXIST, EXPIRED, ACCEPTABLE) + //If polltype == 1, use magnitude, if 2 use Balance, if 3 use hybrid: + //6-20-2015 + double nBalance = GetTotalBalance(); + uint256 hashRand = GetRandHash(); + std::string email = GetArgument("email", "NA"); + boost::to_lower(email); + GlobalCPUMiningCPID.email = email; + GlobalCPUMiningCPID.cpidv2 = ComputeCPIDv2(GlobalCPUMiningCPID.email, GlobalCPUMiningCPID.boincruntimepublickey, hashRand); + GlobalCPUMiningCPID.lastblockhash = GlobalCPUMiningCPID.cpidhash; + + if (!PollExists(Title)) + res.push_back(Pair("Error", "Poll does not exist.")); + + else { - bool bIncExpired = false; - if (params.size() == 3) - { - std::string include_expired = params[2].get_str(); - if (include_expired=="true") bIncExpired=true; - } + if (PollExpired(Title)) + res.push_back(Pair("Error", "Sorry, Poll is already expired.")); - if (params.size() != 2 && params.size() != 3) - { - entry.push_back(Pair("Error","You must specify the Poll Title. Example: listpollresults pollname. You may also specify execute listpollresults pollname true if you want to see expired polls.")); - results.push_back(entry); - } else { - std::string Title1 = params[1].get_str(); - - if (!PollExists(Title1)) + if (!PollAcceptableAnswer(Title, Answer)) { - entry.push_back(Pair("Error","Poll does not exist. Please execute listpolls.")); - results.push_back(entry); - + std::string acceptable_answers = PollAnswers(Title); + res.push_back(Pair("Error", "Sorry, Answer " + Answer + " is not one of the acceptable answers, allowable answers are: " + acceptable_answers + ". If you are voting multiple choice, please use a semicolon delimited vote string such as : 'dog;cat'.")); } + else { - std::string Title = params[1].get_str(); - std::string out1 = ""; - Array myPolls = GetJSONPollsReport(true,Title,out1,bIncExpired); - results.push_back(myPolls); + std::string sParam = SerializeBoincBlock(GlobalCPUMiningCPID, pindexBest->nVersion); + std::string GRCAddress = DefaultWalletAddress(); + StructCPID structMag = GetInitializedStructCPID2(GlobalCPUMiningCPID.cpid, mvMagnitudes); + double dmag = structMag.Magnitude; + double poll_duration = PollDuration(Title) * 86400; + + // Prevent Double Voting + std::string cpid1 = GlobalCPUMiningCPID.cpid; + std::string GRCAddress1 = DefaultWalletAddress(); + GetEarliestStakeTime(GRCAddress1, cpid1); + double cpid_age = GetAdjustedTime() - ReadCache("global", "nCPIDTime").timestamp; + double stake_age = GetAdjustedTime() - ReadCache("global", "nGRCTime").timestamp; + + StructCPID structGRC = GetInitializedStructCPID2(GRCAddress, mvMagnitudes); + + printf("CPIDAge %f, StakeAge %f, Poll Duration %f \r\n", cpid_age, stake_age, poll_duration); + + double dShareType= RoundFromString(GetPollXMLElementByPollTitle(Title, "<SHARETYPE>", "</SHARETYPE>"), 0); + + // Share Type 1 == "Magnitude" + // Share Type 2 == "Balance" + // Share Type 3 == "Both" + if (cpid_age < poll_duration) dmag = 0; + + if (stake_age < poll_duration) nBalance = 0; + + if ((dShareType == 1) && cpid_age < poll_duration) + res.push_back(Pair("Error", "Sorry, When voting in a magnitude poll, your CPID must be older than the poll duration.")); + + else if (dShareType == 2 && stake_age < poll_duration) + res.push_back(Pair("Error", "Sorry, When voting in a Balance poll, your stake age must be older than the poll duration.")); + + else if (dShareType == 3 && stake_age < poll_duration && cpid_age < poll_duration) + res.push_back(Pair("Error", "Sorry, When voting in a Both Share Type poll, your stake age Or your CPID age must be older than the poll duration.")); + + else + { + std::string voter = "<CPIDV2>"+GlobalCPUMiningCPID.cpidv2 + "</CPIDV2><CPID>" + + GlobalCPUMiningCPID.cpid + "</CPID><GRCADDRESS>" + GRCAddress + "</GRCADDRESS><RND>" + + hashRand.GetHex() + "</RND><BALANCE>" + RoundToString(nBalance,2) + + "</BALANCE><MAGNITUDE>" + RoundToString(dmag,0) + "</MAGNITUDE>"; + // Add the provable balance and the provable magnitude - this goes into effect July 1 2017 + voter += GetProvableVotingWeightXML(); + std::string pk = Title + ";" + GRCAddress + ";" + GlobalCPUMiningCPID.cpid; + std::string contract = "<TITLE>" + Title + "" + Answer + "" + voter; + std::string result = AddContract("vote",pk,contract); + std::string narr = "Your CPID weight is " + RoundToString(dmag,0) + " and your Balance weight is " + RoundToString(nBalance,0) + "."; + + res.push_back(Pair("Success", narr + " " + "Your vote has been cast for topic " + Title + ": With an Answer of " + Answer + ": " + result.c_str())); + } } } } - else if (sItem == "reindex") - { - int r = Restarter::CreateGridcoinRestorePoint(); - Restarter::ReindexGridcoinWallet(); - entry.push_back(Pair("Reindex Chain",r)); - results.push_back(entry); - } - else if (sItem == "resetcpids") - { - //Reload the config file - ReadConfigFile(mapArgs, mapMultiArgs); - HarvestCPIDs(true); - GetNextProject(true); - entry.push_back(Pair("Reset",1)); - results.push_back(entry); - } - else if (sItem == "help") - { - entry.push_back(Pair("execute addpoll <days> <question> <answers> <sharetype> <url>", "Add a poll (Requires minimum 100000 GRC balance)")); - entry.push_back(Pair("execute advertisebeacon", "Advertise a beacon (Requires wallet to be fully unlocked)")); - entry.push_back(Pair("execute askforoutstandingblocks", "Asks nodes for outstanding blocks")); - entry.push_back(Pair("execute backupprivatekeys", "Backup private keys (Wallet must be fully unlocked")); - entry.push_back(Pair("execute beaconreport", "Displays information about current active beacons in the network")); - entry.push_back(Pair("execute beaconstatus", "Displays information about your beacon")); - entry.push_back(Pair("execute burn <burnaddress> <burnamount> <burnkey> <burndetail>", "Burn coins for contract")); - entry.push_back(Pair("execute cleanchain", "Cleans current chain and attempts to reorganize")); - entry.push_back(Pair("execute currentneuralhash", "Displays the popular hash in current neural report from all neural nodes")); - entry.push_back(Pair("execute currentneuralreport", "Displays all hashes staked recently by neural nodes")); - entry.push_back(Pair("execute debug <true/false>", "Turn on/off debug messages on the fly")); - entry.push_back(Pair("execute debug2 <true/false>", "Turn on/off debug2 messages on the fly")); - entry.push_back(Pair("execute debug3 <true/false>", "Turn on/off debug3 messages on the fly")); - entry.push_back(Pair("execute debug10 <true/false>", "Turn on/off debug10 messages on the fly")); - entry.push_back(Pair("execute debugnew <true/false>", "Turn on/off debugnet messages on the fly")); - entry.push_back(Pair("execute decryptphrase <phrase>", "Decrypt an encrypted phrase")); - //entry.push_back(Pair("execute downloadblocks", "Download blocks from blockchain")); - entry.push_back(Pair("execute dportally", "Tally magnitudes in superblock")); - entry.push_back(Pair("execute encrypt <phrase>", "Encrypt a wallet pass phrase (autounlock feature)")); - entry.push_back(Pair("execute encryptphrase <phrase>", "Encrypt a phrase or message")); - entry.push_back(Pair("execute listallpolldetails", "Displays all polls past and present with details")); - entry.push_back(Pair("execute listallpolls", "Displays all polls past and present")); - entry.push_back(Pair("execute listpolldetails", "Displays all active polls details")); - entry.push_back(Pair("execute listpollresults <title> <true>", "Displays poll results for specified title. True is optional for expired polls")); - entry.push_back(Pair("execute listpolls", "Displays all active polls")); - entry.push_back(Pair("execute myneuralhash", "Displays your current neural hash from contract")); - entry.push_back(Pair("execute neuralhash", "Displays the network popular hash in neural report (Participating nodes)")); - entry.push_back(Pair("execute neuralreport", "Displays information of recently staked neural votes by participating nodes")); - entry.push_back(Pair("execute neuralresponse", "Requests a response from neural network")); - entry.push_back(Pair("execute rain <raindata>", "Sends rain to specified users. Format Address<COL>Amount<ROW>...")); - entry.push_back(Pair("execute reindex", "Reindex blockchain")); - entry.push_back(Pair("execute resendwallettx", "Resends a wallet tx")); - entry.push_back(Pair("execute resetcpids", "Resets wallet cpids (can be used to correct cpids after a split cpid is fixed)")); - entry.push_back(Pair("execute restart", "Restarts wallet")); - entry.push_back(Pair("execute restorepoint", "Creates a restore point for wallet")); - entry.push_back(Pair("execute staketime", "Displays unix timestamp based on stake gric time and cpid time")); - entry.push_back(Pair("execute superblockage", "Displays information and age about current superblock")); - entry.push_back(Pair("execute syncdpor2", "Synchronize with neural network")); - entry.push_back(Pair("execute tally", "Tallys research averages")); - entry.push_back(Pair("execute tallyneural", "Tally neural quorum data")); - entry.push_back(Pair("execute unspentreport", "Displays unspent wallet information")); - entry.push_back(Pair("execute upgradedbeaconreport", "Displays information about upgraded beacons")); - entry.push_back(Pair("execute updatequorumdata", "Updates neural quorum data")); - entry.push_back(Pair("execute versionreport", "Displays information about client versions that staked the last 100 blocks")); - entry.push_back(Pair("execute vote <title> <answer>", "Casts a vote for a specific poll with chosen answer")); - entry.push_back(Pair("execute votedetails <title>", "Displays information on a specified poll's votes")); - results.push_back(entry); - } - else if (sItem == "helpdev") - { - entry.push_back(Pair("execute addkey <add_or_delete> <keytype> <projectname> <value>", "Add or delete key to network")); - entry.push_back(Pair("execute executecode", "Excute .net code")); - entry.push_back(Pair("execute forcequorum", "Force quorum")); - entry.push_back(Pair("execute gatherneuralhashes", "Gather neural hashes")); - entry.push_back(Pair("execute getlistof <keytype>", "Get list of keytype data")); - entry.push_back(Pair("execute listdata <keytype>", "List data in a keytype")); - entry.push_back(Pair("execute memorizekeys", "Memorize keys from admin messages")); - entry.push_back(Pair("execute readdata <key> <value>", "Display value from a keys data")); - entry.push_back(Pair("execute refhash <grcaddress>", "Check if a grc address is a neural node participant as well as you")); - entry.push_back(Pair("execute sendblock <hash>", "Send a block to network")); - entry.push_back(Pair("execute testnewcontract", "Test current neural contract")); - entry.push_back(Pair("execute writedata <key> <value>", "Write data to a key with value")); - results.push_back(entry); - } -else + return res; +} + +Value votedetails(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "votedetails <pollname>]n" + "\n" + "<pollname> Specified poll name\n" + "Displays vote details of a specified poll\n"); + + Object res; + + std::string Title = params[0].get_str(); + + if (!PollExists(Title)) + res.push_back(Pair("Error", "Poll does not exist. Please listpolls.")); + + else { - entry.push_back(Pair("Command " + sItem + " not found.",-1)); - results.push_back(entry); + Array myVotes = GetJsonVoteDetailsReport(Title); + + res.push_back(myVotes); } - return results; + return res; +} + +Value execute(const Array& params, bool fHelp) +{ + throw runtime_error("execute function has been deprecated; run the command as previously done so but without execute\n"); } >>>>>>> latest changes @@ -4583,69 +4595,11 @@ std::string YesNo(bool f) { return f ? "Yes" : "No"; } -/* + Value listitem(const Array& params, bool fHelp) { - if (fHelp || (params.size() != 1 && params.size() != 2 && params.size() != 3 && params.size() != 4)) - throw runtime_error( - "list <string::itemname>\n" - "Returns details of a given item by name.\n" - "list help\n" - "Displays help on various available list commands.\n"); - - std::string sitem = params[0].get_str(); - - std::string args = ""; - if (params.size()==2) - { - args=params[1].get_str(); - } - - - Array results; - Object e2; - e2.push_back(Pair("Command",sitem)); - results.push_back(e2); - if (sitem == "networktime") - { - Object entry; - entry.push_back(Pair("Network Time",GetAdjustedTime())); - results.push_back(entry); - } - else if (sitem == "memorypool") - { - Object entry; - entry.push_back(Pair("Excluded Tx",msMiningErrorsExcluded)); - entry.push_back(Pair("Included Tx",msMiningErrorsIncluded)); - results.push_back(entry); - } - else if (sitem == "help") - { - Object entry; - entry.push_back(Pair("list cpids", "Displays information on cpids and the projects they are associated with")); - entry.push_back(Pair("list currenttime", "Displays current unix time as well as UTC time and date")); - entry.push_back(Pair("list explainmagnitude <true>", "Displays information about your magnitude from NN; Optional true to force response")); - entry.push_back(Pair("list lifetime", "Displays information on the life time of your cpid")); - entry.push_back(Pair("list magnitude <cpid>", "Displays information on magnitude. cpid is optional.")); - entry.push_back(Pair("list memorypool", "Displays information currently on Txs in memory pool")); - entry.push_back(Pair("list network", "Displays detailed information on the network")); - entry.push_back(Pair("list projects", "Displays information on whitelisted projects on the network")); - entry.push_back(Pair("list rsa", "Displays information on your RSA/CPID history")); - entry.push_back(Pair("list rsaweight", "Displays information on RSA Weight")); - entry.push_back(Pair("list staking", "Displays information on your staking")); - entry.push_back(Pair("list superblocks", "Displays information on superblocks over last 14 days. cpid optional")); - entry.push_back(Pair("list validcpids", "Displays information on your valid cpid")); - results.push_back(entry); - } - else - { - throw runtime_error("Item invalid."); - } - return results; - + throw runtime_error("list is deprecated; Please run the command the same as previously without list\n"); } -*/ - // ppcoin: get information of sync-checkpoint Value getcheckpoint(const Array& params, bool fHelp) @@ -4656,6 +4610,9 @@ Value getcheckpoint(const Array& params, bool fHelp) "Show info of synchronized checkpoint.\n"); Object result; + + LOCK(cs_main); + const CBlockIndex* pindexCheckpoint = Checkpoints::GetLastCheckpoint(mapBlockIndex); if(pindexCheckpoint != NULL) { diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 4b4f08dd91..4e2323bd53 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -26,6 +26,7 @@ Value getconnectioncount(const Array& params, bool fHelp) "Returns the number of connections to other nodes."); LOCK(cs_vNodes); + return (int)vNodes.size(); } @@ -284,6 +285,8 @@ Value getpeerinfo(const Array& params, bool fHelp) "getpeerinfo\n" "Returns data about each connected network node."); + LOCK(cs_vNodes); + vector<CNodeStats> vstats; CopyNodeStats(vstats); diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index b23534d254..d107fac0ba 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -108,6 +108,9 @@ Value getinfo(const Array& params, bool fHelp) GetProxy(NET_IPV4, proxy); Object obj, diff; + + LOCK2(cs_main, pwalletMain->cs_wallet); + obj.push_back(Pair("version", FormatFullVersion())); obj.push_back(Pair("minor_version", CLIENT_VERSION_MINOR)); From a974c90330e9e02f7a0a5f7751a259d37dd07755 Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Tue, 6 Mar 2018 17:52:31 -0800 Subject: [PATCH 16/28] Fix compiler issues --- src/rpcblockchain.cpp | 65 +++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index e35da80952..05652a7d43 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1391,11 +1391,7 @@ Value beaconreport(const Array& params, bool fHelp) "\n" "Displays list of valid beacons in the network\n"); - Object res; - - Array myBeaconJSONReport = GetJSONBeaconReport(); - - res.push_back(myBeaconJSONReport); + Array res = GetJSONBeaconReport(); return res; } @@ -1498,7 +1494,7 @@ Value cpids(const Array& params, bool fHelp) if (mvCPIDs.size() < 1) HarvestCPIDs(false); - printf ("generating cpid report %s\n",sitem.c_str()); + printf ("generating cpid report\n"); for(map<string,StructCPID>::iterator ii=mvCPIDs.begin(); ii!=mvCPIDs.end(); ++ii) { @@ -1552,11 +1548,7 @@ Value currentneuralreport(const Array& params, bool fHelp) "\n" "Displays information for the current neural hashes in network\n"); - Object res; - - Array myNeuralJSON = GetJSONCurrentNeuralNetworkReport(); - - res.push_back(myNeuralJSON); + Array res = GetJSONCurrentNeuralNetworkReport(); return res; } @@ -1603,8 +1595,6 @@ Value explainmagnitude(const Array& params, bool fHelp) else res.push_back(Pair("Neural Response", "false; Try again at a later time")); - res.push_back(entry); - return res; } @@ -1623,7 +1613,7 @@ Value lifetime(const Array& params, bool fHelp) std::string cpid = msPrimaryCPID; std::string Narr = ToString(GetAdjustedTime()); - c.push_back(Pair("Lifetime Payments Report",Narr)); + c.push_back(Pair("Lifetime Payments Report", Narr)); results.push_back(c); CBlockIndex* pindex = pindexGenesisBlock; @@ -1639,12 +1629,12 @@ Value lifetime(const Array& params, bool fHelp) break; if (pindex->GetCPID() == cpid && (pindex->nResearchSubsidy > 0)) - res.push_back(Pair(pindex->nHeight, RoundToString(pindex->nResearchSubsidy,2))); + res.push_back(Pair(ToString(pindex->nHeight), RoundToString(pindex->nResearchSubsidy, 2))); } //8-14-2015 - StructCPID stCPID = GetInitializedStructCPID2(cpid,mvResearchAge); + StructCPID stCPID = GetInitializedStructCPID2(cpid, mvResearchAge); - res.push_back(Pair("Average Magnitude",stCPID.ResearchAverageMagnitude)); + res.push_back(Pair("Average Magnitude", stCPID.ResearchAverageMagnitude)); results.push_back(res); return results; @@ -1754,11 +1744,7 @@ Value neuralreport(const Array& params, bool fHelp) "\n" "Displays neural report for the network\n"); - Object res; - - Array myNeuralJSON = GetJSONNeuralNetworkReport(); - - res.push_back(myNeuralJSON); + Array res = GetJSONNeuralNetworkReport(); return res; } @@ -1831,7 +1817,7 @@ Value rsa(const Array& params, bool fHelp) "\n" "Displays RSA report for your CPID\n"); - Object res; + Array res; if (msPrimaryCPID.empty() || msPrimaryCPID == "INVESTOR") throw runtime_error( @@ -1905,7 +1891,7 @@ Value superblockage(const Array& params, bool fHelp) return res; } -Value superblocks(const Array& params, fHelp) +Value superblocks(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) throw runtime_error( @@ -1914,7 +1900,7 @@ Value superblocks(const Array& params, fHelp) "[cpid] -> Optional: Shows magnitude for a cpid for recent superblocks\n" "Display data on recent superblocks\n"); - Object res; + Array res; std::string cpid = ""; @@ -1969,7 +1955,7 @@ Value validcpids(const Array& params, bool fHelp) "\n" "Displays information about valid CPIDs collected from BOINC\n"); - Object res; + Array res; //Dump vectors: if (mvCPIDs.size() < 1) @@ -2388,7 +2374,7 @@ Value network(const Array& params, bool fHelp) "\n" "Display information about the network health\n"); - Object res; + Array res; for(map<string,StructCPID>::iterator ii=mvNetwork.begin(); ii!=mvNetwork.end(); ++ii) { @@ -2451,7 +2437,7 @@ Value projects(const Array& params, bool fHelp) "\n" "Displays information on projects in the network\n"); - Object res; + Array res; for (const auto& item : ReadCacheSection("project")) { @@ -2895,8 +2881,8 @@ Value addpoll(const Array& params, bool fHelp) else { std::string expiration = RoundToString(GetAdjustedTime() + (days*86400), 0); - std::string contract = "<TITLE>" + Title + "" + days + "" + Question + "" + Answers + "" + sharetype + "" + sURL + "" + expiration + ""; - std::string result = AddContract("poll",Title,contract); + std::string contract = "" + Title + "" + RoundToString(days, 0) + "" + Question + "" + Answers + "" + ToString(sharetype) + "" + sURL + "" + expiration + ""; + std::string result = AddContract("poll", Title,contract); res.push_back(Pair("Success", "Your poll has been added: " + result)); } @@ -3060,7 +3046,7 @@ Value listpollresults(const Array& params, bool fHelp) LOCK(cs_main); - Object res; + Array res; bool bIncExpired = false; if (params.size() == 2) @@ -3070,11 +3056,11 @@ Value listpollresults(const Array& params, bool fHelp) if (!PollExists(Title1)) { - res.push_back(Pair("Error", "Poll does not exist. Please listpolls.")); + Object result; - return res + result.push_back(Pair("Error", "Poll does not exist. Please listpolls.")); + res.push_back(result); } - else { std::string Title = params[0].get_str(); @@ -3189,7 +3175,7 @@ Value restorepoint(const Array& params, bool fHelp) Value vote(const Array& params, bool fHelp) { - if (fHelp || params.size != 2) + if (fHelp || params.size() != 2) throw runtime_error( "vote <answers>\n" "\n" @@ -3306,12 +3292,17 @@ Value votedetails(const Array& params, bool fHelp) "<pollname> Specified poll name\n" "Displays vote details of a specified poll\n"); - Object res; + Array res; std::string Title = params[0].get_str(); if (!PollExists(Title)) - res.push_back(Pair("Error", "Poll does not exist. Please listpolls.")); + { + Object results; + + results.push_back(Pair("Error", "Poll does not exist. Please listpolls.")); + res.push_back(results); + } else { From 6b783e1a63907a162f10fe1043b3bd963c74dea2 Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Tue, 6 Mar 2018 19:30:35 -0800 Subject: [PATCH 17/28] Add getwalletinfo, getblockchaininfo, getnetworkinfo --- src/bitcoinrpc.cpp | 3 +++ src/bitcoinrpc.h | 5 ++++- src/rpcblockchain.cpp | 25 +++++++++++++++++++++++++ src/rpcnet.cpp | 31 +++++++++++++++++++++++++++++++ src/rpcwallet.cpp | 24 ++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 1 deletion(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index cff87a023c..c6f8c15d01 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -297,6 +297,7 @@ static const CRPCCommand vRPCCommands[] = { "getreceivedbyaccount", &getreceivedbyaccount, false, cat_wallet }, { "getreceivedbyaddress", &getreceivedbyaddress, false, cat_wallet }, { "gettransaction", &gettransaction, false, cat_wallet }, + { "getwalletinfo", &getwalletinfo, true, cat_wallet }, { "importprivkey", &importprivkey, false, cat_wallet }, { "importwallet", &importwallet, false, cat_wallet }, { "keypoolrefill", &keypoolrefill, true, cat_wallet }, @@ -406,6 +407,8 @@ static const CRPCCommand vRPCCommands[] = { "addnode", &addnode, false, cat_network }, { "addpoll", &addpoll, false, cat_network }, { "askforoutstandingblocks", &askforoutstandingblocks, false, cat_network }, + { "getblockchaininfo", &getblockchaininfo, true, cat_network }, + { "getnetworkinfo", &getnetworkinfo, true, cat_network }, { "currenttime", ¤ttime, false, cat_network }, { "decryptphrase", &decryptphrase, false, cat_network }, // { "downloadblocks", &downloadblocks, false, cat_network }, diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index c8ec80625e..1c0c4662f0 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -181,6 +181,7 @@ extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bo extern json_spirit::Value getreceivedbyaccount(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getreceivedbyaddress(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value gettransaction(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getwalletinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value importwallet(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value keypoolrefill(const json_spirit::Array& params, bool fHelp); @@ -286,7 +287,7 @@ extern json_spirit::Value testorgkey(const json_spirit::Array& params, bool fHel extern json_spirit::Value unusual(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value updatequoromdata(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value versionreport(const json_spirit::Array& params, bool fhelp); -extern json_spirit::value writedata(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value writedata(const json_spirit::Array& params, bool fHelp); // Network extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp); @@ -300,6 +301,7 @@ extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, boo extern json_spirit::Value getbestblockhash(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getblockbynumber(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getblockchaininfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getblockhash(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getcheckpoint(const json_spirit::Array& params, bool fHelp); @@ -307,6 +309,7 @@ extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, b extern json_spirit::Value getdifficulty(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getinfo(const json_spirit::Array& params, bool fHelp); // To Be Deprecated --> getblockchaininfo getnetworkinfo getwalletinfo extern json_spirit::Value getnettotals(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getnetworkinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getrawmempool(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value listallpolls(const json_spirit::Array& params, bool fHelp); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 05652a7d43..a07d1e2713 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -2892,6 +2892,7 @@ Value addpoll(const Array& params, bool fHelp) return res; } + Value askforoutstandingblocks(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) @@ -2909,6 +2910,30 @@ Value askforoutstandingblocks(const Array& params, bool fHelp) return res; } +Value getblockchaininfo(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "getblockchaininfo\n" + "\n" + "Displays data on current blockchain\n"); + + LOCK(cs_main); + + Object res, diff; + + res.push_back(Pair("blocks", nBestHeight)); + res.push_back(Pair("moneysupply", ValueFromAmount(pindexBest->nMoneySupply))); + diff.push_back(Pair("proof-of-work", GetDifficulty())); + diff.push_back(Pair("proof-of-stake", GetDifficulty(GetLastBlockIndex(pindexBest, true)))); + res.push_back(Pair("difficulty", diff)); + res.push_back(Pair("testnet", fTestNet)); + res.push_back(Pair("errors", GetWarnings("statusbar"))); + + return res; +} + + Value currenttime(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 4e2323bd53..f66d6b7e56 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -471,3 +471,34 @@ Value sendalert2(const Array& params, bool fHelp) result.push_back(Pair("Success", true)); return result; } + + +Value getnetworkinfo(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "getnetworkinfo\n" + "\n" + "Displays network related information\n"); + + Object res; + + proxyType proxy; + GetProxy(NET_IPV4, proxy); + + LOCK(cs_main); + + res.push_back(Pair("version", FormatFullVersion())); + res.push_back(Pair("minor_version", CLIENT_VERSION_MINOR)); + res.push_back(Pair("protocolversion", PROTOCOL_VERSION)); + res.push_back(Pair("timeoffset", GetTimeOffset())); + res.push_back(Pair("connections", (int)vNodes.size())); + res.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee))); + res.push_back(Pair("mininput", ValueFromAmount(nMinimumInputValue))); + res.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string()))); + res.push_back(Pair("ip", addrSeenByPeer.ToStringIP())); + res.push_back(Pair("localaddresses", mapresults)); + res.push_back(Pair("errors", GetWarnings("statusbar"))); + + return res; +} diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index d107fac0ba..19847a52e8 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -141,6 +141,30 @@ Value getinfo(const Array& params, bool fHelp) return obj; } +Value getwalletinfo(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "getwalletinfo\n" + "\n" + "Displays information about the wallet\n"); + + LOCK(pwalletMain->cs_wallet); + + Object res; + + res.push_back(Pair("walletversion", pwalletMain->GetVersion())); + res.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance()))); + res.push_back(Pair("newmint", ValueFromAmount(pwalletMain->GetNewMint()))); + res.push_back(Pair("stake", ValueFromAmount(pwalletMain->GetStake()))); + res.push_back(Pair("keypoololdest", pwalletMain->GetOldestKeyPoolTime())); + res.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize())); + + if (pwalletMain->IsCrypted()) + res.push_back(Pair("unlocked_until", nWalletUnlockTime / 1000)); + + return res; +} Value getnewpubkey(const Array& params, bool fHelp) { From 554b53df8c11bdcd05dae7b87d2447927ac3f83a Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Tue, 6 Mar 2018 19:50:42 -0800 Subject: [PATCH 18/28] refactor fdebug4 a bit --- src/bitcoinrpc.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index c6f8c15d01..7b486337ce 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1333,11 +1333,10 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s nRPCtimetotal = GetTimeMillis() - nRPCtimebegin; printf("RPCTime : Command %s -> Totaltime %" PRId64 "ms\n", strMethod.c_str(), nRPCtimetotal); - - return result; } - result = pcmd->actor(params, false); + else + result = pcmd->actor(params, false); return result; } From 02e00e3715240b7570aaf746cd33e0f2f8025371 Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Tue, 6 Mar 2018 20:01:47 -0800 Subject: [PATCH 19/28] add debug4 to rpc --- src/bitcoinrpc.cpp | 2 ++ src/bitcoinrpc.h | 1 + src/rpcblockchain.cpp | 17 +++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 7b486337ce..92f0d059e1 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -366,6 +366,7 @@ static const CRPCCommand vRPCCommands[] = { "debug10", &debug10, true, cat_developer }, { "debug2", &debug2, true, cat_developer }, { "debug3", &debug3, true, cat_developer }, + { "debug4", &debug4, true, cat_developer }, { "debugnet", &debugnet, true, cat_developer }, { "dportally", &dportally, false, cat_developer }, { "forcequorom", &forcequorom, false, cat_developer }, @@ -532,6 +533,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri if (strMethod == "debug10" && n > 0) ConvertTo<bool>(params[0]); if (strMethod == "debug2" && n > 0) ConvertTo<bool>(params[0]); if (strMethod == "debug3" && n > 0) ConvertTo<bool>(params[0]); + if (strMethod == "debug4" && n > 0) ConvertTo<bool>(params[0]); if (strMethod == "debugnet" && n > 0) ConvertTo<bool>(params[0]); if (strMethod == "getblockstats" && n > 0) ConvertTo<int64_t>(params[0]); if (strMethod == "getblockstats" && n > 1) ConvertTo<int64_t>(params[1]); diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 1c0c4662f0..3ae022a0d5 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -252,6 +252,7 @@ extern json_spirit::Value debug(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value debug10(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value debug2(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value debug3(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value debug4(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value debugnet(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value dportally(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value forcequorom(const json_spirit::Array& params, bool fHelp); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index a07d1e2713..d065533f29 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -2156,6 +2156,23 @@ Value debug3(const Array& params, bool fHelp) return res; } +Value debug4(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "debug4 <bool>\n" + "\n" + "<bool> -> Specify true or false\n" + "Enable or disable debug mode on the fly\n"); + + Object res; + + fDebug4 = params[0].get_bool(); + + res.push_back(Pair("Debug4", fDebug4 ? "Entering debug mode." : "Exiting debug mode.")); + + return res; +} Value debugnet(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) From da6f8e20f3f0bff42bddd0476447e56c14533e0d Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Wed, 7 Mar 2018 16:21:26 -0800 Subject: [PATCH 20/28] Start clean up of code --- src/bitcoinrpc.h | 16 ---------------- src/rpcblockchain.cpp | 3 +-- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 3ae022a0d5..a79bd170fe 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -330,20 +330,4 @@ extern json_spirit::Value showblock(const json_spirit::Array& params, bool fHelp extern json_spirit::Value vote(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value votedetails(const json_spirit::Array& params, bool fHelp); - - - - - - - - -//Gridcoin RPC Commands: - - -// Brod - -// iFoggz -//extern json_spirit::Value blockchain(const json_spirit::Array& params, bool fHelp); - #endif diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index d065533f29..832bb68b9a 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1089,8 +1089,7 @@ Value backupprivatekeys(const Array& params, bool fHelp) throw runtime_error( "backupprivatekeys\n" "\n" - "Backup wallet private keys to file\n" - "Wallet must be fully unlocked!\n"); + "Backup wallet private keys to file (Wallet must be fully unlocked!)\n"); string sErrors; string sTarget; From 03eb98981dced22a03a14e7a5edc8b43307b08de Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Wed, 7 Mar 2018 17:47:14 -0800 Subject: [PATCH 21/28] Add RPC_DEPRECATED json error --- src/bitcoinrpc.h | 1 + src/rpcblockchain.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index a79bd170fe..4f6614cfa5 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -50,6 +50,7 @@ enum RPCErrorCode RPC_INVALID_PARAMETER = -8, // Invalid, missing or duplicate parameter RPC_DATABASE_ERROR = -20, // Database error RPC_DESERIALIZATION_ERROR = -22, // Error parsing or validating structure in raw format + RPC_DEPRECATED = -23, // Use for deprecated commands // P2P client errors RPC_CLIENT_NOT_CONNECTED = -9, // Bitcoin is not connected diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 832bb68b9a..3654c82d52 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -3357,7 +3357,7 @@ Value votedetails(const Array& params, bool fHelp) Value execute(const Array& params, bool fHelp) { - throw runtime_error("execute function has been deprecated; run the command as previously done so but without execute\n"); + throw JSONRPCError(RPC_DEPRECATED, "execute function has been deprecated; run the command as previously done so but without execute"); } >>>>>>> latest changes @@ -4630,7 +4630,7 @@ std::string YesNo(bool f) Value listitem(const Array& params, bool fHelp) { - throw runtime_error("list is deprecated; Please run the command the same as previously without list\n"); + throw JSONRPCError(RPC_DEPRECATED, "list is deprecated; Please run the command the same as previously without list"); } // ppcoin: get information of sync-checkpoint From c147ceb9cbcd94e1b042de2ed2e82c0559791db1 Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Thu, 8 Mar 2018 13:17:00 -0800 Subject: [PATCH 22/28] cleanup --- src/bitcoinrpc.cpp | 12 ++++- src/rpcblockchain.cpp | 105 +++++++++++++++++++++++++++++++----------- src/rpcdump.cpp | 21 +++++++-- src/rpcmining.cpp | 3 +- src/rpcnet.cpp | 1 - 5 files changed, 106 insertions(+), 36 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 92f0d059e1..caf9cedb13 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -162,8 +162,17 @@ string CRPCTable::help(string strCommand, rpccategory category) const if (strMethod.find("label") != string::npos) continue; // Refactored rules for supporting of subcategories + if (pcmd->category == cat_null) + continue; + + if (strCommand.empty() && pcmd->category != category) + continue; + + if (!strCommand.empty() && pcmd->category != category) + continue; +/* if ( strCommand.empty() - && ( (pcmd->category != cat_null && pcmd->category != category) + && ( (pcmd->category == cat_null && pcmd->category != category) || (category != cat_null && strMethod == "help") ) ) @@ -174,6 +183,7 @@ string CRPCTable::help(string strCommand, rpccategory category) const ) ) continue; +*/ try { Array params; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 3654c82d52..2afd6fd516 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -365,11 +365,14 @@ Value showblock(const Array& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "showblock <index>\n" - "Returns all information about the block at <index>."); + "\n" + "<index> Block number\n" + "\n" + "Returns all information about the block at <index>"); int nHeight = params[0].get_int(); if (nHeight < 0 || nHeight > nBestHeight) - throw runtime_error("Block number out of range."); + throw runtime_error("Block number out of range\n"); LOCK(cs_main); @@ -391,7 +394,8 @@ Value getbestblockhash(const Array& params, bool fHelp) if (fHelp || params.size() != 0) throw runtime_error( "getbestblockhash\n" - "Returns the hash of the best block in the longest block chain.\n"); + "\n" + "Returns the hash of the best block in the longest block chain\n"); LOCK(cs_main); @@ -403,7 +407,8 @@ Value getblockcount(const Array& params, bool fHelp) if (fHelp || params.size() != 0) throw runtime_error( "getblockcount\n" - "Returns the number of blocks in the longest block chain.\n"); + "\n" + "Returns the number of blocks in the longest block chain\n"); LOCK(cs_main); @@ -416,7 +421,8 @@ Value getdifficulty(const Array& params, bool fHelp) if (fHelp || params.size() != 0) throw runtime_error( "getdifficulty\n" - "Returns the difficulty as a multiple of the minimum difficulty.\n"); + "\n" + "Returns the difficulty as a multiple of the minimum difficulty\n"); LOCK(cs_main); @@ -432,7 +438,10 @@ Value settxfee(const Array& params, bool fHelp) if (fHelp || params.size() < 1 || params.size() > 1 || AmountFromValue(params[0]) < MIN_TX_FEE) throw runtime_error( "settxfee <amount>\n" - "<amount> is a real and is rounded to the nearest 0.01\n"); + "\n" + "<amount> is a real and is rounded to the nearest 0.01\n" + "\n" + "Sets the txfee for transactions\n"); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -447,7 +456,8 @@ Value getrawmempool(const Array& params, bool fHelp) if (fHelp || params.size() != 0) throw runtime_error( "getrawmempool\n" - "Returns all transaction ids in memory pool."); + "\n" + "Returns all transaction ids in memory pool\n"); vector<uint256> vtxid; mempool.queryHashes(vtxid); @@ -464,7 +474,10 @@ Value getblockhash(const Array& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "getblockhash <index>\n" - "Returns hash of block in best-block-chain at <index>.\n"); + "\n" + "<index> Block number for requested hash\n" + "\n" + "Returns hash of block in best-block-chain at <index>\n"); int nHeight = params[0].get_int(); if (nHeight < 0 || nHeight > nBestHeight) throw runtime_error("Block number out of range."); @@ -481,9 +494,11 @@ Value getblock(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( - "getblock <hash> [txinfo]\n" - "txinfo optional to print more detailed tx info\n" - "Returns details of a block with given block-hash.\n"); + "getblock <hash> [bool:txinfo]\n" + "\n" + "[bool:txinfo] optional to print more detailed tx info\n" + "\n" + "Returns details of a block with given block-hash\n"); std::string strHash = params[0].get_str(); uint256 hash(strHash); @@ -504,15 +519,17 @@ Value getblockbynumber(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( - "getblockbynumber <number> [txinfo]\n" - "txinfo optional to print more detailed tx info\n" - "Returns details of a block with given block-number.\n"); + "getblockbynumber <number> [bool:txinfo]\n" + "\n" + "[bool:txinfo] optional to print more detailed tx info\n" + "\n" + "Returns details of a block with given block-number\n"); LOCK(cs_main); int nHeight = params[0].get_int(); if (nHeight < 0 || nHeight > nBestHeight) - throw runtime_error("Block number out of range."); + throw runtime_error("Block number out of range"); CBlock block; CBlockIndex* pblockindex = mapBlockIndex[hashBestChain]; @@ -1117,7 +1134,9 @@ Value burn2(const Array& params, bool fHelp) "<burnaddress> -> Address where the coins will be burned\n" "<burnamount> -> Amount of coins to be burned\n" "<burnaddress> -> Burn key to be used\n" - "<burndetails> -> Details of the burn\n"); + "<burndetails> -> Details of the burn\n" + "\n" + "Burn coins on the network\n"); Object res; std::string sAddress = params[0].get_str(); @@ -1129,30 +1148,30 @@ Value burn2(const Array& params, bool fHelp) if (!isValid) { - res.push_back(Pair("Error","Invalid GRC Burn Address.")); + res.push_back(Pair("Error", "Invalid GRC Burn Address")); return res; } if (dAmount == 0 || dAmount < 0) { - res.push_back(Pair("Error","Burn amount must be > 0.")); + res.push_back(Pair("Error", "Burn amount must be > 0")); return res; } if (sKey.empty() || sDetail.empty()) { - res.push_back(Pair("Error","Burn Key and Burn Detail must be populated.")); + res.push_back(Pair("Error", "Burn Key and Burn Detail must be populated")); return res; } std::string sContract = "<KEY>" + sKey + "</KEY><DETAIL>" + sDetail + "</DETAIL>"; - std::string sResult = BurnCoinsWithNewContract(true,"burn",sKey,sContract,AmountFromValue(1),dAmount,"",sAddress); + std::string sResult = BurnCoinsWithNewContract(true, "burn", sKey, sContract, AmountFromValue(1), dAmount, "", sAddress); - res.push_back(Pair("Burn_Response",sResult)); + res.push_back(Pair("Burn_Response", sResult)); return res; } @@ -1163,7 +1182,9 @@ Value encrypt(const Array& params, bool fHelp) throw runtime_error( "encrypt <walletpassphrase>\n" "\n" - "<walletpassphrase> -> The password of your encrypted wallet\n"); + "<walletpassphrase> -> The password of your encrypted wallet\n" + "\n" + "Encrypts a walletpassphrase\n"); Object res; //Encrypt a phrase @@ -1182,7 +1203,9 @@ Value newburnaddress(const Array& params, bool fHelp) throw runtime_error( "newburnaddress [burntemplate]\n" "\n" - "[burntemplate] -> Allow a vanity burn address\n"); + "[burntemplate] -> Allow a vanity burn address\n" + "\n" + "Creates a new burn address\n"); Object res; @@ -1238,7 +1261,9 @@ Value rain(const json_spirit::Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "rain Address<COL>Amount<ROW>...\n" + "rain [Array]\n" + "\n" + "[Array] -> Address<COL>Amount<ROW>...\n" "\n" "rains coins on the network\n"); @@ -1352,8 +1377,7 @@ Value advertisebeacon(const json_spirit::Array& params, bool fHelp) throw runtime_error( "advertisebeacon\n" "\n" - "Advertise a beacon\n" - "Requires wallet to be fully unlocked\n"); + "Advertise a beacon (Requires wallet to be fully unlocked)\n"); Object res; @@ -1401,7 +1425,8 @@ Value beaconstatus(const json_spirit::Array& params, bool fHelp) throw runtime_error( "beaconstatus [cpid]\n" "\n" - "[beacon] -> Optional parameter of cpid\n" + "[cpid] -> Optional parameter of cpid\n" + "\n" "Displays status of your beacon or specified beacon on the network\n"); Object res; @@ -1559,6 +1584,7 @@ Value explainmagnitude(const Array& params, bool fHelp) "explainmagnitude [bool:force]\n" "\n" "[force] -> Optional: Force a response (excessive requests can result in temporary ban from neural reponses)\n" + "\n" "Displays information for the current neural hashes in network\n"); Object res; @@ -1646,6 +1672,7 @@ Value magnitude(const json_spirit::Array& params, bool fHelp) "magnitude <cpid>\n" "\n" "<cpid> -> Required to be used on mainnet\n" + "\n" "Displays information for the magnitude of all cpids or specified in the network\n"); Array results; @@ -1897,6 +1924,7 @@ Value superblocks(const Array& params, bool fHelp) "superblocks [cpid]\n" "\n" "[cpid] -> Optional: Shows magnitude for a cpid for recent superblocks\n" + "\n" "Display data on recent superblocks\n"); Array res; @@ -2004,6 +2032,7 @@ Value addkey(const Array& params, bool fHelp) "<keytype> --> Specify keytype ex: project\n" "<keyname> --> Specify keyname ex: milky\n" "<keyvalue> -> Specify keyvalue ex: 1\n" + "\n" "Add a key to the network\n"); Object res; @@ -2090,6 +2119,7 @@ Value debug(const Array& params, bool fHelp) "debug <bool>\n" "\n" "<bool> -> Specify true or false\n" + "\n" "Enable or disable debug mode on the fly\n"); Object res; @@ -2126,6 +2156,7 @@ Value debug2(const Array& params, bool fHelp) "debug2 <bool>\n" "\n" "<bool> -> Specify true or false\n" + "\n" "Enable or disable debug mode on the fly\n"); Object res; @@ -2144,6 +2175,7 @@ Value debug3(const Array& params, bool fHelp) "debug3 <bool>\n" "\n" "<bool> -> Specify true or false\n" + "\n" "Enable or disable debug mode on the fly\n"); Object res; @@ -2162,6 +2194,7 @@ Value debug4(const Array& params, bool fHelp) "debug4 <bool>\n" "\n" "<bool> -> Specify true or false\n" + "\n" "Enable or disable debug mode on the fly\n"); Object res; @@ -2179,6 +2212,7 @@ Value debugnet(const Array& params, bool fHelp) "debugnet <bool>\n" "\n" "<bool> -> Specify true or false\n" + "\n" "Enable or disable debug mode on the fly\n"); Object res; @@ -2279,8 +2313,9 @@ Value genorgkey(const Array& params, bool fHelp) throw runtime_error( "genorgkey <passphrase> <orgranization>\n" "\n" - "<passphrase> -> Set passphrase to be used\n" + "<passphrase> ----> Set passphrase to be used\n" "<orgranization> -> Set orgranization name to be used\n" + "\n" "Generates an Org key\n"); Object res; @@ -2313,6 +2348,7 @@ Value getlistof(const Array& params, bool fHelp) "getlistof <keytype>\n" "\n" "<keytype> -> key of requested data\n" + "\n" "Displays data associated to a specified key type\n"); Object res; @@ -2349,6 +2385,7 @@ Value listdata(const Array& params, bool fHelp) "listdata <keytype>\n" "\n" "<keytype> -> key in cache\n" + "\n" "Displays data associated to a key stored in cache\n"); Object res; @@ -2507,6 +2544,7 @@ Value readdata(const Array& params, bool fHelp) "readdata <key>\n" "\n" "<key> -> generic key\n" + "\n" "Reads generic data from disk from a specified key\n"); Object res; @@ -2565,6 +2603,7 @@ Value refhash(const Array& params, bool fHelp) "refhash <walletaddress>\n" "\n" "<walletaddress> -> GRC address to test against\n" + "\n" "Tests to see if a GRC Address is a participant in neural network along with default wallet address\n"); Object res; @@ -2588,6 +2627,7 @@ Value sendblock(const Array& params, bool fHelp) "sendblock <blockhash>\n" "\n" "<blockhash> Blockhash of block to send to network\n" + "\n" "Sends a block to the network\n"); Object res; @@ -2608,6 +2648,7 @@ Value sendrawcontract(const Array& params, bool fHelp) "sendrawcontract <contract>\n" "\n" "<contract> -> custom contract\n" + "\n" "Send a raw contract in a transaction on the network\n"); Object res; @@ -2747,6 +2788,7 @@ Value testorgkey(const Array& params, bool fHelp) "\n" "<organization> -> Organization name\n" "<publickey> ----> Public key for testing\n" + "\n" "Test a orgkey created by genorgkey\n"); Object res; @@ -2817,6 +2859,7 @@ Value writedata(const Array& params, bool fHelp) "\n" "<key> ---> Key where value will be written\n" "<value> -> Value to be written to specified key\n" + "\n" "Writes a value to specified key\n"); Object res; @@ -2853,6 +2896,7 @@ Value addpoll(const Array& params, bool fHelp) "<answers> ---> The answers available for voter to choose from. Use - in between words and ; to seperate answers\n" "<sharetype> -> The share type of the poll; 1 = Magnitude 2 = Balance 3 = Magnitude + Balance 4 = CPID count 5 = Participant count\n" "<url> -------> The corresponding url for the poll\n" + "\n" "Add a poll to the network; Requires 100K GRC balance\n"); Object res; @@ -2973,6 +3017,7 @@ Value decryptphrase(const Array& params, bool fHelp) "decryptphrase <phrase>\n" "\n" "<phrase> -> Encrypted phrase to decrypt\n" + "\n" "Decrypts an encrypted phrase\n"); Object res; @@ -3014,6 +3059,7 @@ Value encryptphrase(const Array& params, bool fHelp) "encryptphrase <phrase>\n" "\n" "<phrase> Phase you wish to encrypt\n" + "\n" "Encrypt a phrase\n"); Object res; @@ -3083,6 +3129,7 @@ Value listpollresults(const Array& params, bool fHelp) "\n" "<pollname> ----> name of the poll\n" "[showexpired] -> Optional; Default false\n" + "\n" "Displays results for specified poll\n"); LOCK(cs_main); @@ -3222,6 +3269,7 @@ Value vote(const Array& params, bool fHelp) "\n" "<title -> Title of poll being voted on\n" "<answers> -> Answers chosen for specified poll seperated by ;\n" + "\n" "Vote on a specific poll with specified answers\n"); Object res; @@ -3331,6 +3379,7 @@ Value votedetails(const Array& params, bool fHelp) "votedetails <pollname>]n" "\n" "<pollname> Specified poll name\n" + "\n" "Displays vote details of a specified poll\n"); Array res; diff --git a/src/rpcdump.cpp b/src/rpcdump.cpp index 8aaf8a29cd..5e5bd4bf85 100644 --- a/src/rpcdump.cpp +++ b/src/rpcdump.cpp @@ -107,8 +107,12 @@ Value importprivkey(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 3) throw runtime_error( - "importprivkey <gridcoinprivkey> [label] [rescan=true]\n" - "Adds a private key (as returned by dumpprivkey) to your wallet.\n"); + "importprivkey <gridcoinprivkey> [label] [bool:rescan]\n" + "\n" + "[label] -----> Label for imported address\n" + "[bool:rescan] -> Optional; Default true\n" + "\n" + "Adds a private key (as returned by dumpprivkey) to your wallet\n"); string strSecret = params[0].get_str(); string strLabel = ""; @@ -165,7 +169,10 @@ Value importwallet(const Array& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "importwallet <filename>\n" - "Imports keys from a wallet dump file (see dumpwallet).\n"); + "\n" + "<filename> -> filename of the wallet to import\n" + "\n" + "Imports keys from a wallet dump file (see dumpwallet)\n"); ifstream file; file.open(params[0].get_str().c_str()); @@ -255,7 +262,9 @@ Value dumpprivkey(const Array& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "dumpprivkey <gridcoinaddress>\n" - "Reveals the private key corresponding to <gridcoinaddress>."); + "<gridcoinaddress> -> Address of requested key\n" + "\n" + "Reveals the private key corresponding to <gridcoinaddress>"); EnsureWalletIsUnlocked(); @@ -283,7 +292,9 @@ Value dumpwallet(const Array& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "dumpwallet <filename>\n" - "Dumps all wallet keys in a human-readable format.\n"); + "<filename> -> filename to dump wallet to\n" + "\n" + "Dumps all wallet keys in a human-readable format\n"); EnsureWalletIsUnlocked(); diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 982dca202d..f12e546c21 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -26,7 +26,8 @@ Value getmininginfo(const Array& params, bool fHelp) if (fHelp || params.size() != 0) throw runtime_error( "getmininginfo\n" - "Returns an object containing mining-related information.\n"); + "\n" + "Returns an object containing mining-related information\n"); LOCK2(cs_main, pwalletMain->cs_wallet); diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index f66d6b7e56..f8770637b1 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -497,7 +497,6 @@ Value getnetworkinfo(const Array& params, bool fHelp) res.push_back(Pair("mininput", ValueFromAmount(nMinimumInputValue))); res.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string()))); res.push_back(Pair("ip", addrSeenByPeer.ToStringIP())); - res.push_back(Pair("localaddresses", mapresults)); res.push_back(Pair("errors", GetWarnings("statusbar"))); return res; From 3260bed8588e0df96d4798a837ad759d9dc54b47 Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Sat, 10 Mar 2018 16:52:16 -0800 Subject: [PATCH 23/28] clean up + prep for help refactoring --- src/bitcoinrpc.cpp | 14 -- src/rpcblockchain.cpp | 11 +- src/rpcdump.cpp | 5 +- src/rpcnet.cpp | 81 +++---- src/rpcrawtransaction.cpp | 122 +++++----- src/rpcwallet.cpp | 457 ++++++++++++++++++++------------------ 6 files changed, 354 insertions(+), 336 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index caf9cedb13..f58a3feb48 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -170,20 +170,6 @@ string CRPCTable::help(string strCommand, rpccategory category) const if (!strCommand.empty() && pcmd->category != category) continue; -/* - if ( strCommand.empty() - && ( (pcmd->category == cat_null && pcmd->category != category) - || (category != cat_null && strMethod == "help") - ) - ) - continue; - if ( !strCommand.empty() - && ( pcmd->category == cat_null - || strMethod != strCommand - ) - ) - continue; -*/ try { Array params; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 2afd6fd516..384e6e1e2b 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -368,7 +368,7 @@ Value showblock(const Array& params, bool fHelp) "\n" "<index> Block number\n" "\n" - "Returns all information about the block at <index>"); + "Returns all information about the block at <index>\n"); int nHeight = params[0].get_int(); if (nHeight < 0 || nHeight > nBestHeight) @@ -385,10 +385,6 @@ Value showblock(const Array& params, bool fHelp) return blockToJSON(block, pblockindex, false); } - - - - Value getbestblockhash(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) @@ -415,7 +411,6 @@ Value getblockcount(const Array& params, bool fHelp) return nBestHeight; } - Value getdifficulty(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) @@ -432,7 +427,6 @@ Value getdifficulty(const Array& params, bool fHelp) return obj; } - Value settxfee(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 1 || AmountFromValue(params[0]) < MIN_TX_FEE) @@ -544,9 +538,6 @@ Value getblockbynumber(const Array& params, bool fHelp) return blockToJSON(block, pblockindex, params.size() > 1 ? params[1].get_bool() : false); } - - - void filecopy(FILE *dest, FILE *src) { const int size = 16384; diff --git a/src/rpcdump.cpp b/src/rpcdump.cpp index 5e5bd4bf85..cc32b871cf 100644 --- a/src/rpcdump.cpp +++ b/src/rpcdump.cpp @@ -109,7 +109,7 @@ Value importprivkey(const Array& params, bool fHelp) throw runtime_error( "importprivkey <gridcoinprivkey> [label] [bool:rescan]\n" "\n" - "[label] -----> Label for imported address\n" + "[label] -------> Optional; Label for imported address\n" "[bool:rescan] -> Optional; Default true\n" "\n" "Adds a private key (as returned by dumpprivkey) to your wallet\n"); @@ -264,7 +264,7 @@ Value dumpprivkey(const Array& params, bool fHelp) "dumpprivkey <gridcoinaddress>\n" "<gridcoinaddress> -> Address of requested key\n" "\n" - "Reveals the private key corresponding to <gridcoinaddress>"); + "Reveals the private key corresponding to <gridcoinaddress>\n"); EnsureWalletIsUnlocked(); @@ -292,6 +292,7 @@ Value dumpwallet(const Array& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "dumpwallet <filename>\n" + "\n" "<filename> -> filename to dump wallet to\n" "\n" "Dumps all wallet keys in a human-readable format\n"); diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index f8770637b1..2c67154a11 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -23,7 +23,8 @@ Value getconnectioncount(const Array& params, bool fHelp) if (fHelp || params.size() != 0) throw runtime_error( "getconnectioncount\n" - "Returns the number of connections to other nodes."); + "\n" + "Returns the number of connections to other node\n."); LOCK(cs_vNodes); @@ -91,10 +92,11 @@ Value addnode(const Array& params, bool fHelp) if (params.size() == 2) strCommand = params[1].get_str(); if (fHelp || params.size() != 2 || - (strCommand != "onetry" && strCommand != "add" && strCommand != "remove")) + (strCommand != "onetry" && strCommand != "add" && strCommand != "remove")) throw runtime_error( - "addnode <node> <add|remove|onetry>\n" - "Attempts add or remove <node> from the addnode list or try a connection to <node> once.\n"); + "addnode <node> <add|remove|onetry>\n" + "\n" + "Attempts add or remove <node> from the addnode list or try a connection to <node> once\n"); string strNode = params[0].get_str(); @@ -131,11 +133,12 @@ Value getaddednodeinfo(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( - "getaddednodeinfo <dns> [node]\n" - "Returns information about the given added node, or all added nodes\n" - "(note that onetry addnodes are not listed here)\n" - "If dns is false, only a list of added nodes will be provided,\n" - "otherwise connected information will also be available."); + "getaddednodeinfo <dns> [node]\n" + "\n" + "Returns information about the given added node, or all added nodes\n" + "(note that onetry addnodes are not listed here)\n" + "If dns is false, only a list of added nodes will be provided,\n" + "otherwise connected information will also be available\n"); bool fDns = params[0].get_bool(); @@ -245,16 +248,15 @@ bool AsyncNeuralRequest(std::string command_name,std::string cpid,int NodeLimit) return true; } - - Value ping(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) throw runtime_error( - "ping\n" - "Requests that a ping be sent to all other nodes, to measure ping time.\n" - "Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.\n" - "Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping."); + "ping\n" + "\n" + "Requests that a ping be sent to all other nodes, to measure ping time.\n" + "Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.\n" + "Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping\n"); // Request that each node send a ping during next message processing pass LOCK(cs_vNodes); @@ -282,8 +284,9 @@ Value getpeerinfo(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) throw runtime_error( - "getpeerinfo\n" - "Returns data about each connected network node."); + "getpeerinfo\n" + "\n" + "Returns data about each connected network node."); LOCK(cs_vNodes); @@ -329,15 +332,14 @@ Value getpeerinfo(const Array& params, bool fHelp) return ret; } - - Value getnettotals(const Array& params, bool fHelp) { if (fHelp || params.size() > 0) throw runtime_error( - "getnettotals\n" - "Returns information about network traffic, including bytes in, bytes out,\n" - "and current time."); + "getnettotals\n" + "\n" + "Returns information about network traffic, including bytes in, bytes out,\n" + "and current time\n"); Object obj; obj.push_back(Pair("totalbytesrecv", CNode::GetTotalBytesRecv())); @@ -357,14 +359,16 @@ Value sendalert(const Array& params, bool fHelp) if (fHelp || params.size() < 6) throw runtime_error( "sendalert <message> <privatekey> <minver> <maxver> <priority> <id> [cancelupto]\n" - "<message> is the alert text message\n" - "<privatekey> is hex string of alert master private key\n" - "<minver> is the minimum applicable internal client version\n" - "<maxver> is the maximum applicable internal client version\n" - "<priority> is integer priority number\n" - "<id> is the alert id\n" - "[cancelupto] cancels all alert id's up to this number\n" - "Returns true or false."); + "\n" + "<message> ----> is the alert text message\n" + "<privatekey> -> is hex string of alert master private key\n" + "<minver> -----> is the minimum applicable internal client version\n" + "<maxver> -----> is the maximum applicable internal client version\n" + "<priority> ---> is integer priority number\n" + "<id> ---------> is the alert id\n" + "[cancelupto] -> cancels all alert id's up to this number\n" + "\n" + "Returns true or false\n"); CAlert alert; CKey key; @@ -417,13 +421,15 @@ Value sendalert2(const Array& params, bool fHelp) throw runtime_error( // 0 1 2 3 4 5 6 "sendalert <privatekey> <id> <subverlist> <cancellist> <expire> <priority> <message>\n" - "<message> is the alert text message\n" - "<privatekey> is hex string of alert master private key\n" - "<subverlist> comma separated list of versions warning applies to\n" - "<priority> integer, >1000->visible\n" - "<id> is the unique alert number\n" - "<cancellist> comma separated ids of alerts to cancel\n" - "<expire> alert expiration in days\n" + "\n" + "<message> ---->is the alert text message\n" + "<privatekey> -> is hex string of alert master private key\n" + "<subverlist> -> comma separated list of versions warning applies to\n" + "<priority> ---> integer, >1000->visible\n" + "<id> ---------> is the unique alert number\n" + "<cancellist> -> comma separated ids of alerts to cancel\n" + "<expire> -----> alert expiration in days\n" + "\n" "Returns true or false."); CAlert alert; @@ -472,7 +478,6 @@ Value sendalert2(const Array& params, bool fHelp) return result; } - Value getnetworkinfo(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index ff496b22bf..408492d2d4 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -484,11 +484,12 @@ Value getrawtransaction(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( - "getrawtransaction <txid> [verbose=bool]\n" - "If verbose is false, returns a string that is\n" - "serialized, hex-encoded data for <txid>.\n" - "If verbose is true, returns an Object\n" - "with information about <txid>.\n"); + "getrawtransaction <txid> [verbose=bool]\n" + "\n" + "If verbose is false, returns a string that is\n" + "serialized, hex-encoded data for <txid>.\n" + "If verbose is true, returns an Object\n" + "with information about <txid>\n"); uint256 hash; hash.SetHex(params[0].get_str()); @@ -521,12 +522,13 @@ Value listunspent(const Array& params, bool fHelp) { if (fHelp || params.size() > 3) throw runtime_error( - "listunspent [minconf=1] [maxconf=9999999] [\"address\",...]\n" - "Returns array of unspent transaction outputs\n" - "with between minconf and maxconf (inclusive) confirmations.\n" - "Optionally filtered to only include txouts paid to specified addresses.\n" - "Results are an array of Objects, each of which has:\n" - "{txid, vout, scriptPubKey, amount, confirmations}\n"); + "listunspent [minconf=1] [maxconf=9999999] [\"address\",...]\n" + "\n" + "Returns array of unspent transaction outputs\n" + "with between minconf and maxconf (inclusive) confirmations.\n" + "Optionally filtered to only include txouts paid to specified addresses.\n" + "Results are an array of Objects, each of which has:\n" + "{txid, vout, scriptPubKey, amount, confirmations}\n"); RPCTypeCheck(params, list_of(int_type)(int_type)(array_type)); @@ -602,35 +604,35 @@ Value createrawtransaction(const Array& params, bool fHelp) { if (fHelp || params.size() != 2) throw runtime_error( - "createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,\"data\":\"hex\",...}\n" - "\nCreate a transaction spending the given inputs and creating new outputs.\n" - "Outputs can be addresses or data.\n" - "Returns hex-encoded raw transaction.\n" - "Note that the transaction's inputs are not signed, and\n" - "it is not stored in the wallet or transmitted to the network.\n" - "\nArguments:\n" - "1. \"transactions\" (string, required) A json array of json objects\n" - " [\n" - " {\n" - " \"txid\":\"id\", (string, required) The transaction id\n" - " \"vout\":n (numeric, required) The output number\n" - " }\n" - " ,...\n" - " ]\n" - "2. \"outputs\" (string, required) a json object with outputs\n" - " {\n" - " \"address\": x.xxx (numeric, required) The key is the bitcoin address, the value is the CURRENCY_UNIT amount\n" - " \"data\": \"hex\", (string, required) The key is \"data\", the value is hex encoded data\n" - " ...\n" - " }\n" - "\nResult:\n" - "\"transaction\" (string) hex string of the transaction\n" - "\nExamples\n" - "createrawtransaction \"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"{\\\"address\\\":0.01} " - "createrawtransaction \"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"{\\\"data\\\":\\\"00010203\\\"} " - "createrawtransaction \"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"address\\\":0.01} " - "createrawtransaction \"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"data\\\":\\\"00010203\\\"} \n" - ); + "createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,\"data\":\"hex\",...}\n" + "\nCreate a transaction spending the given inputs and creating new outputs.\n" + "Outputs can be addresses or data.\n" + "Returns hex-encoded raw transaction.\n" + "Note that the transaction's inputs are not signed, and\n" + "it is not stored in the wallet or transmitted to the network.\n" + "\nArguments:\n" + "1. \"transactions\" (string, required) A json array of json objects\n" + " [\n" + " {\n" + " \"txid\":\"id\", (string, required) The transaction id\n" + " \"vout\":n (numeric, required) The output number\n" + " }\n" + " ,...\n" + " ]\n" + "2. \"outputs\" (string, required) a json object with outputs\n" + " {\n" + " \"address\": x.xxx (numeric, required) The key is the bitcoin address, the value is the CURRENCY_UNIT amount\n" + " \"data\": \"hex\", (string, required) The key is \"data\", the value is hex encoded data\n" + " ...\n" + " }\n" + "\nResult:\n" + "\"transaction\" (string) hex string of the transaction\n" + "\nExamples\n" + "createrawtransaction \"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"{\\\"address\\\":0.01} " + "createrawtransaction \"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\" \"{\\\"data\\\":\\\"00010203\\\"} " + "createrawtransaction \"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"address\\\":0.01} " + "createrawtransaction \"[{\\\"txid\\\":\\\"myid\\\",\\\"vout\\\":0}]\", \"{\\\"data\\\":\\\"00010203\\\"} \n" + ); RPCTypeCheck(params, list_of(array_type)(obj_type)); Array inputs = params[0].get_array(); @@ -700,8 +702,9 @@ Value decoderawtransaction(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "decoderawtransaction <hex string>\n" - "Return a JSON object representing the serialized, hex-encoded transaction.\n"); + "decoderawtransaction <hex string>\n" + "\n" + "Return a JSON object representing the serialized, hex-encoded transaction\n"); RPCTypeCheck(params, list_of(str_type)); @@ -728,8 +731,9 @@ Value decodescript(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "decodescript <hex string>\n" - "Decode a hex-encoded script.\n"); + "decodescript <hex string>\n" + "\n" + "Decode a hex-encoded script.\n"); RPCTypeCheck(params, list_of(str_type)); @@ -751,18 +755,19 @@ Value signrawtransaction(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 4) throw runtime_error( - "signrawtransaction <hex string> [{\"txid\":txid,\"vout\":n,\"scriptPubKey\":hex},...] [<privatekey1>,...] [sighashtype=\"ALL\"]\n" - "Sign inputs for raw transaction (serialized, hex-encoded).\n" - "Second optional argument (may be null) is an array of previous transaction outputs that\n" - "this transaction depends on but may not yet be in the blockchain.\n" - "Third optional argument (may be null) is an array of base58-encoded private\n" - "keys that, if given, will be the only keys used to sign the transaction.\n" - "Fourth optional argument is a string that is one of six values; ALL, NONE, SINGLE or\n" - "ALL|ANYONECANPAY, NONE|ANYONECANPAY, SINGLE|ANYONECANPAY.\n" - "Returns json object with keys:\n" - " hex : raw transaction with signature(s) (hex-encoded string)\n" - " complete : 1 if transaction has a complete set of signature (0 if not)\n" - + HelpRequiringPassphrase()); + "signrawtransaction <hex string> [{\"txid\":txid,\"vout\":n,\"scriptPubKey\":hex},...] [<privatekey1>,...] [sighashtype=\"ALL\"]\n" + "\n" + "Sign inputs for raw transaction (serialized, hex-encoded).\n" + "Second optional argument (may be null) is an array of previous transaction outputs that\n" + "this transaction depends on but may not yet be in the blockchain.\n" + "Third optional argument (may be null) is an array of base58-encoded private\n" + "keys that, if given, will be the only keys used to sign the transaction.\n" + "Fourth optional argument is a string that is one of six values; ALL, NONE, SINGLE or\n" + "ALL|ANYONECANPAY, NONE|ANYONECANPAY, SINGLE|ANYONECANPAY.\n" + "Returns json object with keys:\n" + " hex : raw transaction with signature(s) (hex-encoded string)\n" + " complete : 1 if transaction has a complete set of signature (0 if not)\n" + + HelpRequiringPassphrase()); RPCTypeCheck(params, list_of(str_type)(array_type)(array_type)(str_type), true); @@ -943,8 +948,9 @@ Value sendrawtransaction(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 1) throw runtime_error( - "sendrawtransaction <hex string>\n" - "Submits raw transaction (serialized, hex-encoded) to local node and network.\n"); + "sendrawtransaction <hex string>\n" + "\n" + "Submits raw transaction (serialized, hex-encoded) to local node and network\n"); RPCTypeCheck(params, list_of(str_type)); diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 19847a52e8..448dbe75e2 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -101,8 +101,9 @@ Value getinfo(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) throw runtime_error( - "getinfo\n" - "Returns an object containing various state info."); + "getinfo\n" + "\n" + "Returns an object containing various state info."); proxyType proxy; GetProxy(NET_IPV4, proxy); @@ -170,8 +171,9 @@ Value getnewpubkey(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) throw runtime_error( - "getnewpubkey [account]\n" - "Returns new public key for coinbase generation.\n"); + "getnewpubkey [account]\n" + "\n" + "Returns new public key for coinbase generation.\n"); // Parse the account first so we don't generate a key if there's an error string strAccount; @@ -200,10 +202,11 @@ Value getnewaddress(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) throw runtime_error( - "getnewaddress [account]\n" - "Returns a new Gridcoin address for receiving payments. " - "If [account] is specified, it is added to the address book " - "so payments received with the address will be credited to [account].\n"); + "getnewaddress [account]\n" + "\n" + "Returns a new Gridcoin address for receiving payments. " + "If [account] is specified, it is added to the address book " + "so payments received with the address will be credited to [account].\n"); // Parse the account first so we don't generate a key if there's an error string strAccount; @@ -269,8 +272,9 @@ Value getaccountaddress(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "getaccountaddress <account>\n" - "Returns the current Gridcoin address for receiving payments to this account.\n"); + "getaccountaddress <account>\n" + "\n" + "Returns the current Gridcoin address for receiving payments to this account.\n"); // Parse the account first so we don't generate a key if there's an error string strAccount = AccountFromValue(params[0]); @@ -290,8 +294,9 @@ Value setaccount(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( - "setaccount <gridcoinaddress> <account>\n" - "Sets the account associated with the given address.\n"); + "setaccount <gridcoinaddress> <account>\n" + "\n" + "Sets the account associated with the given address.\n"); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -321,8 +326,9 @@ Value getaccount(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "getaccount <gridcoinaddress>\n" - "Returns the account associated with the given address.\n"); + "getaccount <gridcoinaddress>\n" + "\n" + "Returns the account associated with the given address.\n"); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -343,8 +349,9 @@ Value getaddressesbyaccount(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "getaddressesbyaccount <account>\n" - "Returns the list of addresses for the given account.\n"); + "getaddressesbyaccount <account>\n" + "\n" + "Returns the list of addresses for the given account.\n"); string strAccount = AccountFromValue(params[0]); @@ -367,9 +374,10 @@ Value sendtoaddress(const Array& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 4) throw runtime_error( - "sendtoaddress <gridcoinaddress> <amount> [comment] [comment-to]\n" - "<amount> is a real and is rounded to the nearest 0.000001\n" - + HelpRequiringPassphrase()); + "sendtoaddress <gridcoinaddress> <amount> [comment] [comment-to]\n" + "\n" + "<amount> is a real and is rounded to the nearest 0.000001\n" + + HelpRequiringPassphrase()); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -401,10 +409,11 @@ Value listaddressgroupings(const Array& params, bool fHelp) { if (fHelp) throw runtime_error( - "listaddressgroupings\n" - "Lists groups of addresses which have had their common ownership\n" - "made public by common use as inputs or as the resulting change\n" - "in past transactions\n"); + "listaddressgroupings\n" + "\n" + "Lists groups of addresses which have had their common ownership\n" + "made public by common use as inputs or as the resulting change\n" + "in past transactions\n"); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -433,8 +442,9 @@ Value signmessage(const Array& params, bool fHelp) { if (fHelp || params.size() != 2) throw runtime_error( - "signmessage <Gridcoinaddress> <message>\n" - "Sign a message with the private key of an address\n"); + "signmessage <Gridcoinaddress> <message>\n" + "\n" + "Sign a message with the private key of an address\n"); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -470,8 +480,9 @@ Value verifymessage(const Array& params, bool fHelp) { if (fHelp || params.size() != 3) throw runtime_error( - "verifymessage <Gridcoinaddress> <signature> <message>\n" - "Verify a signed message\n"); + "verifymessage <Gridcoinaddress> <signature> <message>\n" + "\n" + "Verify a signed message\n"); string strAddress = params[0].get_str(); string strSign = params[1].get_str(); @@ -509,8 +520,9 @@ Value getreceivedbyaddress(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( - "getreceivedbyaddress <Gridcoinaddress> [minconf=1]\n" - "Returns the total amount received by <Gridcoinaddress> in transactions with at least [minconf] confirmations.\n"); + "getreceivedbyaddress <Gridcoinaddress> [minconf=1]\n" + "\n" + "Returns the total amount received by <Gridcoinaddress> in transactions with at least [minconf] confirmations.\n"); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -561,8 +573,9 @@ Value getreceivedbyaccount(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( - "getreceivedbyaccount <account> [minconf=1]\n" - "Returns the total amount received by addresses with <account> in transactions with at least [minconf] confirmations.\n"); + "getreceivedbyaccount <account> [minconf=1]\n" + "\n" + "Returns the total amount received by addresses with <account> in transactions with at least [minconf] confirmations.\n"); accountingDeprecationCheck(); @@ -662,24 +675,25 @@ Value getbalance(const Array& params, bool fHelp) { if (fHelp || params.size() > 3) throw runtime_error( - "getbalance ( \"account\" minconf includeWatchonly )\n" - "\nIf account is not specified, returns the server's total available balance.\n" - "If account is specified, returns the balance in the account.\n" - "Note that the account \"\" is not the same as leaving the parameter out.\n" - "The server total may be different to the balance in the default \"\" account.\n" - "\nArguments:\n" - "1. \"account\" (string, optional) The selected account, or \"*\" for entire wallet. It may be the default account using \"\".\n" - "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n" - "3. includeWatchonly (bool, optional, default=false) Also include balance in watchonly addresses (see 'importaddress')\n" - "\nResult:\n" - "amount (numeric) The total amount in btc received for this account.\n" - "\nExamples:\n" - "\nThe total amount in the server across all accounts\n" - "\nThe total amount in the server across all accounts, with at least 5 confirmations\n" - "\nThe total amount in the default account with at least 1 confirmation\n" - "\nThe total amount in the account named tabby with at least 6 confirmations\n" - "\nAs a json rpc call\n" - ); + "getbalance ( \"account\" minconf includeWatchonly )\n" + "\n" + "\nIf account is not specified, returns the server's total available balance.\n" + "If account is specified, returns the balance in the account.\n" + "Note that the account \"\" is not the same as leaving the parameter out.\n" + "The server total may be different to the balance in the default \"\" account.\n" + "\nArguments:\n" + "1. \"account\" (string, optional) The selected account, or \"*\" for entire wallet. It may be the default account using \"\".\n" + "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n" + "3. includeWatchonly (bool, optional, default=false) Also include balance in watchonly addresses (see 'importaddress')\n" + "\nResult:\n" + "amount (numeric) The total amount in btc received for this account.\n" + "\nExamples:\n" + "\nThe total amount in the server across all accounts\n" + "\nThe total amount in the server across all accounts, with at least 5 confirmations\n" + "\nThe total amount in the default account with at least 1 confirmation\n" + "\nThe total amount in the account named tabby with at least 6 confirmations\n" + "\nAs a json rpc call\n" + ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -740,8 +754,9 @@ Value movecmd(const Array& params, bool fHelp) { if (fHelp || params.size() < 3 || params.size() > 5) throw runtime_error( - "move <fromaccount> <toaccount> <amount> [minconf=1] [comment]\n" - "Move from one account in your wallet to another.\n"); + "move <fromaccount> <toaccount> <amount> [minconf=1] [comment]\n" + "\n" + "Move from one account in your wallet to another.\n"); accountingDeprecationCheck(); @@ -795,9 +810,10 @@ Value sendfrom(const Array& params, bool fHelp) { if (fHelp || params.size() < 3 || params.size() > 6) throw runtime_error( - "sendfrom <fromaccount> <toGridcoinaddress> <amount> [minconf=1] [comment] [comment-to]\n" - "<amount> is a real and is rounded to the nearest 0.000001\n" - + HelpRequiringPassphrase()); + "sendfrom <fromaccount> <toGridcoinaddress> <amount> [minconf=1] [comment] [comment-to]\n" + "\n" + "<amount> is a real and is rounded to the nearest 0.000001\n" + + HelpRequiringPassphrase()); string strAccount = AccountFromValue(params[0]); @@ -839,9 +855,10 @@ Value sendmany(const Array& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 4) throw runtime_error( - "sendmany <fromaccount> {address:amount,...} [minconf=1] [comment]\n" - "amounts are double-precision floating point numbers\n" - + HelpRequiringPassphrase()); + "sendmany <fromaccount> {address:amount,...} [minconf=1] [comment]\n" + "\n" + "amounts are double-precision floating point numbers\n" + + HelpRequiringPassphrase()); string strAccount = AccountFromValue(params[0]); Object sendTo = params[1].get_obj(); @@ -907,10 +924,10 @@ Value addmultisigaddress(const Array& params, bool fHelp) if (fHelp || params.size() < 2 || params.size() > 3) { string msg = "addmultisigaddress <nrequired> <'[\"key\",\"key\"]'> [account]\n" - "\n" - "Add a nrequired-to-sign multisignature address to the wallet\n" - "each key is a Gridcoin address or hex-encoded public key\n" - "If [account] is specified, assign address to [account].\n"; + "\n" + "Add a nrequired-to-sign multisignature address to the wallet\n" + "each key is a Gridcoin address or hex-encoded public key\n" + "If [account] is specified, assign address to [account].\n"; throw runtime_error(msg); } @@ -984,9 +1001,9 @@ Value addredeemscript(const Array& params, bool fHelp) if (fHelp || params.size() < 1 || params.size() > 2) { string msg = "addredeemscript <redeemScript> [account]\n" - "\n" - "Add a P2SH address with a specified redeemScript to the wallet.\n" - "If [account] is specified, assign address to [account].\n"; + "\n" + "Add a P2SH address with a specified redeemScript to the wallet.\n" + "If [account] is specified, assign address to [account].\n"; throw runtime_error(msg); } @@ -1176,21 +1193,21 @@ Value listreceivedbyaddress(const Array& params, bool fHelp) { if (fHelp || params.size() > 3) throw runtime_error( - "listreceivedbyaddress ( minconf includeempty includeWatchonly)\n" - "\nList balances by receiving address.\n" - "\nArguments:\n" - "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n" - "2. includeempty (numeric, optional, dafault=false) Whether to include addresses that haven't received any payments.\n" - "3. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n" - "\nResult:\n" - "[\n" - " {\n" - " \"involvesWatchonly\" : \"true\", (bool) Only returned if imported addresses were involved in transaction\n" - " \"address\" : \"receivingaddress\", (string) The receiving address\n" - " \"account\" : \"accountname\", (string) The account of the receiving address. The default account is \"\".\n" - " \"amount\" : x.xxx, (numeric) The total amount in btc received by the address\n" - "\nExamples:\n" - ); + "listreceivedbyaddress ( minconf includeempty includeWatchonly)\n" + "\nList balances by receiving address.\n" + "\nArguments:\n" + "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n" + "2. includeempty (numeric, optional, dafault=false) Whether to include addresses that haven't received any payments.\n" + "3. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n" + "\nResult:\n" + "[\n" + " {\n" + " \"involvesWatchonly\" : \"true\", (bool) Only returned if imported addresses were involved in transaction\n" + " \"address\" : \"receivingaddress\", (string) The receiving address\n" + " \"account\" : \"accountname\", (string) The account of the receiving address. The default account is \"\".\n" + " \"amount\" : x.xxx, (numeric) The total amount in btc received by the address\n" + "\nExamples:\n" + ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -1201,20 +1218,20 @@ Value listreceivedbyaccount(const Array& params, bool fHelp) { if (fHelp || params.size() > 3) throw runtime_error( - "listreceivedbyaccount ( minconf includeempty includeWatchonly)\n" - "\nList balances by account.\n" - "\nArguments:\n" - "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n" - "2. includeempty (boolean, optional, default=false) Whether to include accounts that haven't received any payments.\n" - "3. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n" - "\nResult:\n" - "[\n" - " {\n" - " \"involvesWatchonly\" : \"true\", (bool) Only returned if imported addresses were involved in transaction\n" - " \"account\" : \"accountname\", (string) The account name of the receiving account\n" - " \"amount\" : x.xxx, (numeric) The total amount received by addresses with this account\n" - " \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n" - ); + "listreceivedbyaccount ( minconf includeempty includeWatchonly)\n" + "\nList balances by account.\n" + "\nArguments:\n" + "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n" + "2. includeempty (boolean, optional, default=false) Whether to include accounts that haven't received any payments.\n" + "3. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n" + "\nResult:\n" + "[\n" + " {\n" + " \"involvesWatchonly\" : \"true\", (bool) Only returned if imported addresses were involved in transaction\n" + " \"account\" : \"accountname\", (string) The account name of the receiving account\n" + " \"amount\" : x.xxx, (numeric) The total amount received by addresses with this account\n" + " \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n" + ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -1432,60 +1449,60 @@ Value listtransactions(const Array& params, bool fHelp) { if (fHelp || params.size() > 4) throw runtime_error( - "listtransactions ( \"account\" count from includeWatchonly)\n" - "\nReturns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'.\n" - "\nArguments:\n" - "1. \"account\" (string, optional) The account name. If not included, it will list all transactions for all accounts.\n" - " If \"\" is set, it will list transactions for the default account.\n" - "2. count (numeric, optional, default=10) The number of transactions to return\n" - "3. from (numeric, optional, default=0) The number of transactions to skip\n" - "4. includeWatchonly (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress')\n" - " If \"\" is set true, it will list sent transactions as well\n" - "\nResult:\n" - "[\n" - " {\n" - " \"account\":\"accountname\", (string) The account name associated with the transaction. \n" - " It will be \"\" for the default account.\n" - " \"address\":\"bitcoinaddress\", (string) The bitcoin address of the transaction. Not present for \n" - " move transactions (category = move).\n" - " \"category\":\"send|receive|move\", (string) The transaction category. 'move' is a local (off blockchain)\n" - " transaction between accounts, and not associated with an address,\n" - " transaction id or block. 'send' and 'receive' transactions are \n" - " associated with an address, transaction id and block details\n" - " \"amount\": x.xxx, (numeric) The amount in btc. This is negative for the 'send' category, and for the\n" - " 'move' category for moves outbound. It is positive for the 'receive' category,\n" - " and for the 'move' category for inbound funds.\n" - " \"fee\": x.xxx, (numeric) The amount of the fee in btc. This is negative and only available for the \n" - " 'send' category of transactions.\n" - " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and \n" - " 'receive' category of transactions.\n" - " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive'\n" - " category of transactions.\n" - " \"blockindex\": n, (numeric) The block index containing the transaction. Available for 'send' and 'receive'\n" - " category of transactions.\n" - " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n" - " \"walletconflicts\" : [\n" - " \"conflictid\", (string) Ids of transactions, including equivalent clones, that re-spend a txid input.\n" - " ],\n" - " \"respendsobserved\" : [\n" - " \"respendid\", (string) Ids of transactions, NOT equivalent clones, that re-spend a txid input. \"Double-spends.\"\n" - " ],\n" - " \"time\": xxx, (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT).\n" - " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (midnight Jan 1 1970 GMT). Available \n" - " for 'send' and 'receive' category of transactions.\n" - " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n" - " \"otheraccount\": \"accountname\", (string) For the 'move' category of transactions, the account the funds came \n" - " from (for receiving funds, positive amounts), or went to (for sending funds,\n" - " negative amounts).\n" - " }\n" - "]\n" - - "\nExamples:\n" - "\nList the most recent 10 transactions in the systems\n" - "\nList the most recent 10 transactions for the tabby account\n" - "\nList transactions 100 to 120 from the tabby account\n" - "\nAs a json rpc call\n" - ); + "listtransactions ( \"account\" count from includeWatchonly)\n" + "\nReturns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'.\n" + "\nArguments:\n" + "1. \"account\" (string, optional) The account name. If not included, it will list all transactions for all accounts.\n" + " If \"\" is set, it will list transactions for the default account.\n" + "2. count (numeric, optional, default=10) The number of transactions to return\n" + "3. from (numeric, optional, default=0) The number of transactions to skip\n" + "4. includeWatchonly (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress')\n" + " If \"\" is set true, it will list sent transactions as well\n" + "\nResult:\n" + "[\n" + " {\n" + " \"account\":\"accountname\", (string) The account name associated with the transaction. \n" + " It will be \"\" for the default account.\n" + " \"address\":\"bitcoinaddress\", (string) The bitcoin address of the transaction. Not present for \n" + " move transactions (category = move).\n" + " \"category\":\"send|receive|move\", (string) The transaction category. 'move' is a local (off blockchain)\n" + " transaction between accounts, and not associated with an address,\n" + " transaction id or block. 'send' and 'receive' transactions are \n" + " associated with an address, transaction id and block details\n" + " \"amount\": x.xxx, (numeric) The amount in btc. This is negative for the 'send' category, and for the\n" + " 'move' category for moves outbound. It is positive for the 'receive' category,\n" + " and for the 'move' category for inbound funds.\n" + " \"fee\": x.xxx, (numeric) The amount of the fee in btc. This is negative and only available for the \n" + " 'send' category of transactions.\n" + " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and \n" + " 'receive' category of transactions.\n" + " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive'\n" + " category of transactions.\n" + " \"blockindex\": n, (numeric) The block index containing the transaction. Available for 'send' and 'receive'\n" + " category of transactions.\n" + " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n" + " \"walletconflicts\" : [\n" + " \"conflictid\", (string) Ids of transactions, including equivalent clones, that re-spend a txid input.\n" + " ],\n" + " \"respendsobserved\" : [\n" + " \"respendid\", (string) Ids of transactions, NOT equivalent clones, that re-spend a txid input. \"Double-spends.\"\n" + " ],\n" + " \"time\": xxx, (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT).\n" + " \"timereceived\": xxx, (numeric) The time received in seconds since epoch (midnight Jan 1 1970 GMT). Available \n" + " for 'send' and 'receive' category of transactions.\n" + " \"comment\": \"...\", (string) If a comment is associated with the transaction.\n" + " \"otheraccount\": \"accountname\", (string) For the 'move' category of transactions, the account the funds came \n" + " from (for receiving funds, positive amounts), or went to (for sending funds,\n" + " negative amounts).\n" + " }\n" + "]\n" + + "\nExamples:\n" + "\nList the most recent 10 transactions in the systems\n" + "\nList the most recent 10 transactions for the tabby account\n" + "\nList transactions 100 to 120 from the tabby account\n" + "\nAs a json rpc call\n" + ); string strAccount = "*"; int nCount = 10; @@ -1556,14 +1573,15 @@ Value listaccounts(const Array& params, bool fHelp) { if (fHelp || params.size() > 2) throw runtime_error( - "listaccounts ( minconf includeWatchonly)\n" - "Returns Object that has account names as keys, account balances as values." - "1. minconf (numeric, optional, default=1) Only onclude transactions with at least this many confirmations\n" - "2. includeWatchonly (bool, optional, default=false) Include balances in watchonly addresses (see 'importaddress')\n" - "\nResult:\n" - "{ (json object where keys are account names, and values are numeric balances\n" - " \"account\": x.xxx, (numeric) The property name is the account name, and the value is the total balance for the account.\n" - ); + "listaccounts ( minconf includeWatchonly)\n" + "\n" + "Returns Object that has account names as keys, account balances as values." + "1. minconf (numeric, optional, default=1) Only onclude transactions with at least this many confirmations\n" + "2. includeWatchonly (bool, optional, default=false) Include balances in watchonly addresses (see 'importaddress')\n" + "\nResult:\n" + "{ (json object where keys are account names, and values are numeric balances\n" + " \"account\": x.xxx, (numeric) The property name is the account name, and the value is the total balance for the account.\n" + ); accountingDeprecationCheck(); @@ -1625,16 +1643,16 @@ Value listsinceblock(const Array& params, bool fHelp) { if (fHelp) throw runtime_error( - "listsinceblock ( \"blockhash\" target-confirmations includeWatchonly)\n" - "\nGet all transactions in blocks since block [blockhash], or all transactions if omitted\n" - "\nArguments:\n" - "1. \"blockhash\" (string, optional) The block hash to list transactions since\n" - "2. target-confirmations: (numeric, optional) The confirmations required, must be 1 or more\n" - "3. includeWatchonly: (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress')" - "\nResult:\n" - "{\n" - " \"transactions\": [\n" - ); + "listsinceblock ( \"blockhash\" target-confirmations includeWatchonly)\n" + "\nGet all transactions in blocks since block [blockhash], or all transactions if omitted\n" + "\nArguments:\n" + "1. \"blockhash\" (string, optional) The block hash to list transactions since\n" + "2. target-confirmations: (numeric, optional) The confirmations required, must be 1 or more\n" + "3. includeWatchonly: (bool, optional, default=false) Include transactions to watchonly addresses (see 'importaddress')" + "\nResult:\n" + "{\n" + " \"transactions\": [\n" + ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -1695,15 +1713,15 @@ Value gettransaction(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( - "gettransaction \"txid\"\n" - "\nGet detailed information about in-wallet transaction <txid>\n" - "\nArguments:\n" - "1. \"txid\" (string, required) The transaction id\n" - "2. \"includeWatchonly\" (bool, optional, default=false) Whether to include watchonly addresses in balance calculation and details[]\n" - "\nResult:\n" - "{\n" - " \"amount\" : x.xxx, (numeric) The transaction amount in grc\n" - ); + "gettransaction \"txid\"\n" + "\nGet detailed information about in-wallet transaction <txid>\n" + "\nArguments:\n" + "1. \"txid\" (string, required) The transaction id\n" + "2. \"includeWatchonly\" (bool, optional, default=false) Whether to include watchonly addresses in balance calculation and details[]\n" + "\nResult:\n" + "{\n" + " \"amount\" : x.xxx, (numeric) The transaction amount in grc\n" + ); uint256 hash; hash.SetHex(params[0].get_str()); @@ -1771,9 +1789,9 @@ Value backupwallet(const Array& params, bool fHelp) { if (fHelp || params.size() > 0) throw runtime_error( - "backupwallet\n" - "\n" - "Backup your wallet and config files.\n"); + "backupwallet\n" + "\n" + "Backup your wallet and config files.\n"); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -1790,9 +1808,9 @@ Value keypoolrefill(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) throw runtime_error( - "keypoolrefill [new-size]\n" - "Fills the keypool.\n" - + HelpRequiringPassphrase()); + "keypoolrefill [new-size]\n" + "Fills the keypool.\n" + + HelpRequiringPassphrase()); unsigned int nSize = max(GetArg("-keypool", 100), (int64_t)0); if (params.size() > 0) { @@ -1870,9 +1888,10 @@ Value walletpassphrase(const Array& params, bool fHelp) { if (pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 3)) throw runtime_error( - "walletpassphrase <passphrase> <timeout> [stakingonly]\n" - "Stores the wallet decryption key in memory for <timeout> seconds.\n" - "if [stakingonly] is true sending functions are disabled.\n"); + "walletpassphrase <passphrase> <timeout> [stakingonly]\n" + "\n" + "Stores the wallet decryption key in memory for <timeout> seconds.\n" + "if [stakingonly] is true sending functions are disabled.\n"); if (fHelp) return true; @@ -1923,8 +1942,9 @@ Value walletpassphrasechange(const Array& params, bool fHelp) { if (pwalletMain->IsCrypted() && (fHelp || params.size() != 2)) throw runtime_error( - "walletpassphrasechange <oldpassphrase> <newpassphrase>\n" - "Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>.\n"); + "walletpassphrasechange <oldpassphrase> <newpassphrase>\n" + "\n" + "Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>.\n"); if (fHelp) return true; @@ -1959,10 +1979,11 @@ Value walletlock(const Array& params, bool fHelp) { if (pwalletMain->IsCrypted() && (fHelp || params.size() != 0)) throw runtime_error( - "walletlock\n" - "Removes the wallet encryption key from memory, locking the wallet.\n" - "After calling this method, you will need to call walletpassphrase again\n" - "before being able to call any methods which require the wallet to be unlocked.\n"); + "walletlock\n" + "\n" + "Removes the wallet encryption key from memory, locking the wallet.\n" + "After calling this method, you will need to call walletpassphrase again\n" + "before being able to call any methods which require the wallet to be unlocked.\n"); if (fHelp) return true; @@ -1985,8 +2006,9 @@ Value encryptwallet(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "encryptwallet <passphrase>\n" - "Encrypts the wallet with <passphrase>.\n"); + "encryptwallet <passphrase>\n" + "\n" + "Encrypts the wallet with <passphrase>.\n"); if (pwalletMain->IsCrypted()) throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an encrypted wallet, but encryptwallet was called."); @@ -2054,8 +2076,9 @@ Value validateaddress(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "validateaddress <gridcoinaddress>\n" - "Return information about <gridcoinaddress>.\n"); + "validateaddress <gridcoinaddress>\n" + "\n" + "Return information about <gridcoinaddress>.\n"); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -2085,8 +2108,9 @@ Value validatepubkey(const Array& params, bool fHelp) { if (fHelp || !params.size() || params.size() > 2) throw runtime_error( - "validatepubkey <gridcoinpubkey>\n" - "Return information about <gridcoinpubkey>.\n"); + "validatepubkey <gridcoinpubkey>\n" + "\n" + "Return information about <gridcoinpubkey>.\n"); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -2126,11 +2150,12 @@ Value reservebalance(const Array& params, bool fHelp) { if (fHelp || params.size() > 2) throw runtime_error( - "reservebalance [<reserve> [amount]]\n" - "<reserve> is true or false to turn balance reserve on or off.\n" - "<amount> is a real and rounded to cent.\n" - "Set reserve amount not participating in network protection.\n" - "If no parameters provided current setting is printed.\n"); + "reservebalance [<reserve> [amount]]\n" + "\n" + "<reserve> is true or false to turn balance reserve on or off.\n" + "<amount> is a real and rounded to cent.\n" + "Set reserve amount not participating in network protection.\n" + "If no parameters provided current setting is printed.\n"); if (params.size() > 0) { @@ -2165,8 +2190,9 @@ Value checkwallet(const Array& params, bool fHelp) { if (fHelp || params.size() > 0) throw runtime_error( - "checkwallet\n" - "Check wallet for integrity.\n"); + "checkwallet\n" + "\n" + "Check wallet for integrity.\n"); int nMismatchSpent; int64_t nBalanceInQuestion; @@ -2188,8 +2214,9 @@ Value repairwallet(const Array& params, bool fHelp) { if (fHelp || params.size() > 0) throw runtime_error( - "repairwallet\n" - "Repair wallet if checkwallet reports any problem.\n"); + "repairwallet\n" + "\n" + "Repair wallet if checkwallet reports any problem.\n"); int nMismatchSpent; int64_t nBalanceInQuestion; @@ -2210,9 +2237,10 @@ Value resendtx(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) throw runtime_error( - "resendtx\n" - "Re-send unconfirmed transactions.\n" - ); + "resendtx\n" + "\n" + "Re-send unconfirmed transactions.\n" + ); ResendWalletTransactions(true); @@ -2224,9 +2252,10 @@ Value makekeypair(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) throw runtime_error( - "makekeypair [prefix]\n" - "Make a public/private key pair.\n" - "[prefix] is optional preferred prefix for the public key.\n"); + "makekeypair [prefix]\n" + "\n" + "Make a public/private key pair.\n" + "[prefix] is optional preferred prefix for the public key.\n"); string strPrefix = ""; if (params.size() > 0) @@ -2246,10 +2275,10 @@ Value burn(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( - "burn <amount> [hex string]\n" - "\n" - "<amount> is a real and is rounded to the nearest 0.00000001\n" - + HelpRequiringPassphrase()); + "burn <amount> [hex string]\n" + "\n" + "<amount> is a real and is rounded to the nearest 0.00000001\n" + + HelpRequiringPassphrase()); if (pwalletMain->IsLocked()) throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); From b35ea54c6857c5d5259ef9449a3d8cba82cfec91 Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Wed, 14 Mar 2018 14:08:22 -0700 Subject: [PATCH 24/28] Moved/changed/added locks --- src/rpcblockchain.cpp | 108 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 94 insertions(+), 14 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 384e6e1e2b..1b9e3173d3 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -437,7 +437,7 @@ Value settxfee(const Array& params, bool fHelp) "\n" "Sets the txfee for transactions\n"); - LOCK2(cs_main, pwalletMain->cs_wallet); + LOCK(cs_main); nTransactionFee = AmountFromValue(params[0]); nTransactionFee = (nTransactionFee / CENT) * CENT; // round to cent @@ -453,8 +453,14 @@ Value getrawmempool(const Array& params, bool fHelp) "\n" "Returns all transaction ids in memory pool\n"); + vector<uint256> vtxid; - mempool.queryHashes(vtxid); + + { + LOCK(mempool.cs); + + mempool.queryHashes(vtxid); + } Array a; for (auto const& hash : vtxid) @@ -474,8 +480,10 @@ Value getblockhash(const Array& params, bool fHelp) "Returns hash of block in best-block-chain at <index>\n"); int nHeight = params[0].get_int(); - if (nHeight < 0 || nHeight > nBestHeight) throw runtime_error("Block number out of range."); - if (fDebug10) LogPrintf("Getblockhash %f",(double)nHeight); + if (nHeight < 0 || nHeight > nBestHeight) + throw runtime_error("Block number out of range."); + if (fDebug10) + LogPrintf("Getblockhash %d", nHeight); LOCK(cs_main); @@ -497,11 +505,11 @@ Value getblock(const Array& params, bool fHelp) std::string strHash = params[0].get_str(); uint256 hash(strHash); - LOCK(cs_main); - if (mapBlockIndex.count(hash) == 0) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); + LOCK(cs_main); + CBlock block; CBlockIndex* pblockindex = mapBlockIndex[hash]; block.ReadFromDisk(pblockindex, true); @@ -519,12 +527,12 @@ Value getblockbynumber(const Array& params, bool fHelp) "\n" "Returns details of a block with given block-number\n"); - LOCK(cs_main); - int nHeight = params[0].get_int(); if (nHeight < 0 || nHeight > nBestHeight) throw runtime_error("Block number out of range"); + LOCK(cs_main); + CBlock block; CBlockIndex* pblockindex = mapBlockIndex[hashBestChain]; while (pblockindex->nHeight > nHeight) @@ -1405,6 +1413,8 @@ Value beaconreport(const Array& params, bool fHelp) "\n" "Displays list of valid beacons in the network\n"); + LOCK(cs_main); + Array res = GetJSONBeaconReport(); return res; @@ -1429,6 +1439,8 @@ Value beaconstatus(const json_spirit::Array& params, bool fHelp) if (params.size() > 0) sCPID = params[0].get_str(); + LOCK(cs_main); + std::string sPubKey = GetBeaconPublicKey(sCPID, false); std::string sPrivKey = GetStoredBeaconPrivateKey(sCPID); int64_t iBeaconTimestamp = BeaconTimeStamp(sCPID, false); @@ -1506,6 +1518,8 @@ Value cpids(const Array& params, bool fHelp) //Dump vectors: + LOCK(cs_main); + if (mvCPIDs.size() < 1) HarvestCPIDs(false); @@ -1548,6 +1562,9 @@ Value currentneuralhash(const Array& params, bool fHelp) Object res; double popularity = 0; + + LOCK(cs_main); + std::string consensus_hash = GetCurrentNeuralNetworkSupermajorityHash(popularity); res.push_back(Pair("Popular",consensus_hash)); @@ -1563,6 +1580,8 @@ Value currentneuralreport(const Array& params, bool fHelp) "\n" "Displays information for the current neural hashes in network\n"); + LOCK(cs_main); + Array res = GetJSONCurrentNeuralNetworkReport(); return res; @@ -1585,6 +1604,8 @@ Value explainmagnitude(const Array& params, bool fHelp) if (params.size() > 0) bForce = params[0].get_bool(); + LOCK(cs_main); + if (bForce) { if (msNeuralResponse.length() < 25) @@ -1632,6 +1653,8 @@ Value lifetime(const Array& params, bool fHelp) c.push_back(Pair("Lifetime Payments Report", Narr)); results.push_back(c); + LOCK(cs_main); + CBlockIndex* pindex = pindexGenesisBlock; while (pindex->nHeight < pindexBest->nHeight) @@ -1673,7 +1696,11 @@ Value magnitude(const json_spirit::Array& params, bool fHelp) if (params.size() > 1) cpid = params[0].get_str(); - results = MagnitudeReport(cpid); + { + LOCK(cs_main); + + results = MagnitudeReport(cpid); + } if (results.size() > 1000) { @@ -1709,8 +1736,11 @@ Value mymagnitude(const Array& params, bool fHelp) } else - results = MagnitudeReport(msPrimaryCPID); + { + LOCK(cs_main); + results = MagnitudeReport(msPrimaryCPID); + } return results; } @@ -1761,6 +1791,8 @@ Value neuralreport(const Array& params, bool fHelp) "\n" "Displays neural report for the network\n"); + LOCK(cs_main); + Array res = GetJSONNeuralNetworkReport(); return res; @@ -1776,6 +1808,8 @@ Value proveownership(const Array& params, bool fHelp) Object res; + LOCK(cs_main); + HarvestCPIDs(true); GetNextProject(true); @@ -1818,6 +1852,8 @@ Value resetcpids(const Array& params, bool fHelp) Object res; + LOCK(cs_main); + ReadConfigFile(mapArgs, mapMultiArgs); HarvestCPIDs(true); GetNextProject(true); @@ -1840,6 +1876,8 @@ Value rsa(const Array& params, bool fHelp) throw runtime_error( "PrimaryCPID is empty or INVESTOR; No RSA available for this condition\n"); + LOCK(cs_main); + res = MagnitudeReport(msPrimaryCPID); return res; @@ -1857,6 +1895,9 @@ Value rsaweight(const Array& params, bool fHelp) double out_magnitude = 0; double out_owed = 0; + + LOCK(cs_main); + int64_t RSAWEIGHT = GetRSAWeightByCPID(GlobalCPUMiningCPID.cpid); out_magnitude = GetUntrustedMagnitude(GlobalCPUMiningCPID.cpid, out_owed); @@ -1877,6 +1918,8 @@ Value staketime(const Array& params, bool fHelp) Object res; + LOCK2(cs_main, pwalletMain->cs_wallet); + std::string cpid = GlobalCPUMiningCPID.cpid; std::string GRCAddress = DefaultWalletAddress(); GetEarliestStakeTime(GRCAddress, cpid); @@ -1925,6 +1968,8 @@ Value superblocks(const Array& params, bool fHelp) if (params.size() > 0) cpid = params[0].get_str(); + LOCK(cs_main); + res = SuperblockReport(cpid); return res; @@ -1942,6 +1987,8 @@ Value syncdpor2(const Array& params, bool fHelp) std::string sOut = ""; + LOCK(cs_main); + bool bFull = GetCountOf("beacon") < 50 ? true : false; LoadAdminMessages(bFull, sOut); @@ -1960,6 +2007,8 @@ Value upgradedbeaconreport(const Array& params, bool fHelp) "\n" "Display upgraded beacon report of the network\n"); + LOCK(cs_main); + Array aUpgBR = GetUpgradedBeaconReport(); return aUpgBR; @@ -1975,6 +2024,8 @@ Value validcpids(const Array& params, bool fHelp) Array res; + LOCK(cs_main); + //Dump vectors: if (mvCPIDs.size() < 1) HarvestCPIDs(false); @@ -2225,6 +2276,8 @@ Value dportally(const Array& params, bool fHelp) Object res; + LOCK(cs_main); + TallyMagnitudesInSuperblock(); res.push_back(Pair("Done", "Done")); @@ -2259,6 +2312,8 @@ Value gatherneuralhashes(const Array& params, bool fHelp) Object res; + LOCK(cs_main); + GatherNeuralHashes(); res.push_back(Pair("Sent", ".")); @@ -2347,6 +2402,9 @@ Value getlistof(const Array& params, bool fHelp) std::string sType = params[0].get_str(); res.push_back(Pair("Key Type", sType)); + + LOCK(cs_main); + res.push_back(Pair("Data", GetListOf(sType))); return res; @@ -2362,6 +2420,8 @@ Value getnextproject(const Array& params, bool fHelp) Object res; + LOCK(cs_main); + GetNextProject(true); res.push_back(Pair("GetNext", 1)); @@ -2385,6 +2445,8 @@ Value listdata(const Array& params, bool fHelp) res.push_back(Pair("Key Type", sType)); + LOCK(cs_main); + for(const auto& item : ReadCacheSection(sType)) res.push_back(Pair(item.first, item.second.value)); @@ -2403,6 +2465,8 @@ Value memorizekeys(const Array& params, bool fHelp) std::string sOut; + LOCK(cs_main); + LoadAdminMessages(true, sOut); res.push_back(Pair("Results", sOut)); @@ -2420,6 +2484,8 @@ Value network(const Array& params, bool fHelp) Array res; + LOCK(cs_main); + for(map<string,StructCPID>::iterator ii=mvNetwork.begin(); ii!=mvNetwork.end(); ++ii) { StructCPID stNet = mvNetwork[(*ii).first]; @@ -2483,6 +2549,8 @@ Value projects(const Array& params, bool fHelp) Array res; + LOCK(cs_main); + for (const auto& item : ReadCacheSection("project")) { Object entry; @@ -2521,6 +2589,8 @@ Value readconfig(const Array& params, bool fHelp) Object res; + LOCK(cs_main); + ReadConfigFile(mapArgs, mapMultiArgs); res.push_back(Pair("readconfig", 1)); @@ -2632,6 +2702,7 @@ Value sendblock(const Array& params, bool fHelp) return res; } + Value sendrawcontract(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) @@ -2682,6 +2753,8 @@ Value superblockaverage(const Array& params, bool fHelp) Object res; + LOCK(cs_main); + std::string superblock = ReadCache("superblock", "all").value; double out_beacon_count = 0; double out_participant_count = 0; @@ -2711,6 +2784,8 @@ Value tally(const Array& params, bool fHelp) Object res; + LOCK(cs_main); + bNetAveragesLoaded_retired = false; TallyResearchAverages_v9(); @@ -2729,6 +2804,8 @@ Value tallyneural(const Array& params, bool fHelp) Object res; + LOCK(cs_main); + ComputeNeuralNetworkSupermajorityHashes(); UpdateNeuralNetworkQuorumData(); @@ -2805,6 +2882,8 @@ Value unusual(const Array& params, bool fHelp) Object res; + LOCK(cs_main); + UnusualActivityReport(); res.push_back(Pair("UAR", 1)); @@ -2837,6 +2916,8 @@ Value versionreport(const Array& params, bool fHelp) "\n" "Displays a report on various versions recently stake on the network\n"); + LOCK(cs_main); + Array myNeuralJSON = GetJSONVersionReport(); return myNeuralJSON; @@ -2911,9 +2992,6 @@ Value addpoll(const Array& params, bool fHelp) else { - - LOCK2(cs_main, pwalletMain->cs_wallet); - double nBalance = GetTotalBalance(); if (nBalance < 100000) @@ -3275,7 +3353,7 @@ Value vote(const Array& params, bool fHelp) return res; } - LOCK2(cs_main, pwalletMain->cs_wallet); + LOCK(cs_main, pwalletMain->cs_wallet); //Verify the Existence of the poll, the acceptability of the answer, and the expiration of the poll: (EXIST, EXPIRED, ACCEPTABLE) //If polltype == 1, use magnitude, if 2 use Balance, if 3 use hybrid: @@ -3387,6 +3465,8 @@ Value votedetails(const Array& params, bool fHelp) else { + LOCK(cs_main); + Array myVotes = GetJsonVoteDetailsReport(Title); res.push_back(myVotes); From 7af41a3f5d7453a85f189ac8b29ac0c75c211805 Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Wed, 14 Mar 2018 14:14:15 -0700 Subject: [PATCH 25/28] Moved/changed locks --- src/rpcnet.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 2c67154a11..5b684537ca 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -288,12 +288,15 @@ Value getpeerinfo(const Array& params, bool fHelp) "\n" "Returns data about each connected network node."); - LOCK(cs_vNodes); - vector<CNodeStats> vstats; - CopyNodeStats(vstats); - Array ret; + + { + LOCK(cs_vNodes); + + CopyNodeStats(vstats); + } + GatherNeuralHashes(); for (auto const& stats : vstats) { From d5e1bd46647c5c38106ad3e810d655aed0aee6e8 Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Wed, 14 Mar 2018 14:22:16 -0700 Subject: [PATCH 26/28] Adjustments --- src/rpcrawtransaction.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 408492d2d4..0e95726b16 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -559,7 +559,7 @@ Value listunspent(const Array& params, bool fHelp) vector<COutput> vecOutputs; - LOCK2(cs_main, pwalletMain->cs_wallet); + LOCK(pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false,NULL,false); for (auto const& out : vecOutputs) @@ -638,8 +638,6 @@ Value createrawtransaction(const Array& params, bool fHelp) Array inputs = params[0].get_array(); Object sendTo = params[1].get_obj(); - LOCK2(cs_main, pwalletMain->cs_wallet); - CTransaction rawTx; for (auto const& input : inputs) @@ -954,7 +952,7 @@ Value sendrawtransaction(const Array& params, bool fHelp) RPCTypeCheck(params, list_of(str_type)); - LOCK(cs_main); + LOCK2(cs_main, pwalletMain->cs_wallet); // parse hex string from parameter vector<unsigned char> txData(ParseHex(params[0].get_str())); From ed7b6a0ecd5c87cd408aa9cea48c05f4d800f8d0 Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Wed, 14 Mar 2018 20:55:00 -0700 Subject: [PATCH 27/28] fixed compiler conflicts --- src/bitcoinrpc.cpp | 2 -- src/bitcoinrpc.h | 2 -- src/rpcblockchain.cpp | 78 +++++++++---------------------------------- 3 files changed, 16 insertions(+), 66 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index f58a3feb48..6e1f340f48 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -368,7 +368,6 @@ static const CRPCCommand vRPCCommands[] = { "forcequorom", &forcequorom, false, cat_developer }, { "gatherneuralhashes", &gatherneuralhashes, false, cat_developer }, { "genboinckey", &genboinckey, false, cat_developer }, - { "genorgkey", &genorgkey, false, cat_developer }, { "getblockstats", &rpc_getblockstats, false, cat_developer }, { "getlistof", &getlistof, false, cat_developer }, { "getnextproject", &getnextproject, false, cat_developer }, @@ -394,7 +393,6 @@ static const CRPCCommand vRPCCommands[] = #ifdef WIN32 { "testnewcontract", &testnewcontract, false, cat_developer }, #endif - { "testorgkey", &testorgkey, false, cat_developer }, { "unusual", &unusual, false, cat_developer }, { "updatequoromdata", &updatequoromdata, false, cat_developer }, { "versionreport", &versionreport, false, cat_developer }, diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 4f6614cfa5..d2718f5291 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -259,7 +259,6 @@ extern json_spirit::Value dportally(const json_spirit::Array& params, bool fHelp extern json_spirit::Value forcequorom(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value gatherneuralhashes(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value genboinckey(const json_spirit::Array& params, bool fHelp); -extern json_spirit::Value genorgkey(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value rpc_getblockstats(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getlistof(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getnextproject(const json_spirit::Array& params, bool fHelp); @@ -285,7 +284,6 @@ extern json_spirit::Value tallyneural(const json_spirit::Array& params, bool fHe #ifdef WIN32 extern json_spirit::Value testnewcontract(const json_spirit::Array& params, bool fHelp); #endif -extern json_spirit::Value testorgkey(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value unusual(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value updatequoromdata(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value versionreport(const json_spirit::Array& params, bool fhelp); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 1b9e3173d3..1bc011e1f8 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1484,7 +1484,19 @@ Value beaconstatus(const json_spirit::Array& params, bool fHelp) if (!sPubKey.empty()) { - std::string sSignature = SignBlockWithCPID(sCPID,hashBlock.GetHex()); + bool bResult; + std::string sSignature; + std::string sError; + + bResult = SignBlockWithCPID(sCPID, hashBlock.GetHex(), sSignature, sError); + + if (!bResult) + { + sErr += "Failed to sign block with cpid "; + sErr += sError; + sErr += ";"; + } + bool fResult = VerifyCPIDSignature(sCPID, hashBlock.GetHex(), sSignature); res.push_back(Pair("Block Signing Test Results", fResult)); @@ -2353,40 +2365,6 @@ Value genboinckey(const Array& params, bool fHelp) return res; } -Value genorgkey(const Array& params, bool fHelp) -{ - if (fHelp || params.size() != 2) - throw runtime_error( - "genorgkey <passphrase> <orgranization>\n" - "\n" - "<passphrase> ----> Set passphrase to be used\n" - "<orgranization> -> Set orgranization name to be used\n" - "\n" - "Generates an Org key\n"); - - Object res; - - std::string sParam1 = params[0].get_str(); - std::string sParam2 = params[1].get_str(); - std::string sboinchashargs = LegacyDefaultBoincHashArgs(); - - res.push_back(Pair("Passphrase", sParam1)); - res.push_back(Pair("OrgName", sParam2)); - - if (sParam1 != sboinchashargs) - res.push_back(Pair("Error", "Admin must be logged in")); - - else - { - std::string modulus = sboinchashargs.substr(0, 12); - std::string key = sParam2 + "," + AdvancedCryptWithSalt(modulus, sParam2); - - res.push_back(Pair("OrgKey", key)); - } - - return res; -} - Value getlistof(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) @@ -2787,7 +2765,8 @@ Value tally(const Array& params, bool fHelp) LOCK(cs_main); bNetAveragesLoaded_retired = false; - TallyResearchAverages_v9(); + CBlockIndex* tallyIndex = FindTallyTrigger(pindexBest); + TallyResearchAverages_v9(tallyIndex); res.push_back(Pair("Tally Network Averages", 1)); @@ -2848,30 +2827,6 @@ Value testnewcontract(const Array& params, bool fHelp) } #endif -Value testorgkey(const Array& params, bool fHelp) -{ - if (fHelp || params.size() != 2) - throw runtime_error( - "testorgkey <organization> <publickey>\n" - "\n" - "<organization> -> Organization name\n" - "<publickey> ----> Public key for testing\n" - "\n" - "Test a orgkey created by genorgkey\n"); - - Object res; - - std::string sParam1 = params[0].get_str(); - std::string sParam2 = params[1].get_str(); - std::string key = sParam1 + "," + AdvancedDecryptWithSalt(sParam2, sParam1); - - res.push_back(Pair("Org", sParam1)); - res.push_back(Pair("Key", sParam2)); - res.push_back(Pair("PubKey", key)); - - return res; -} - Value unusual(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) @@ -3353,7 +3308,7 @@ Value vote(const Array& params, bool fHelp) return res; } - LOCK(cs_main, pwalletMain->cs_wallet); + LOCK2(cs_main, pwalletMain->cs_wallet); //Verify the Existence of the poll, the acceptability of the answer, and the expiration of the poll: (EXIST, EXPIRED, ACCEPTABLE) //If polltype == 1, use magnitude, if 2 use Balance, if 3 use hybrid: @@ -3479,7 +3434,6 @@ Value execute(const Array& params, bool fHelp) { throw JSONRPCError(RPC_DEPRECATED, "execute function has been deprecated; run the command as previously done so but without execute"); } ->>>>>>> latest changes Array SuperblockReport(std::string cpid) { From 7aa7ec89e36a839199ed9d325fe73dc562e8bd74 Mon Sep 17 00:00:00 2001 From: Paul Jensen <eastendmumbles@gmail.com> Date: Thu, 15 Mar 2018 15:28:28 -0700 Subject: [PATCH 28/28] fix help <command>; fix win32 compiliation errors --- src/bitcoinrpc.cpp | 3 ++- src/rpcblockchain.cpp | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 6e1f340f48..81fd4610d3 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -168,8 +168,9 @@ string CRPCTable::help(string strCommand, rpccategory category) const if (strCommand.empty() && pcmd->category != category) continue; - if (!strCommand.empty() && pcmd->category != category) + if (!strCommand.empty() && pcmd->name != strCommand) continue; + try { Array params; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 1bc011e1f8..51c0483bf8 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1789,8 +1789,6 @@ Value neuralhash(const Array& params, bool fHelp) res.push_back(Pair("Popular", consensus_hash)); - results.push_back(entry); - return res; } #endif @@ -2162,7 +2160,7 @@ Value currentcontractaverage(const Array& params, bool fHelp) res.push_back(Pair("Length", (int)contract.length())); res.push_back(Pair("Wallet Neural Hash", neural_hash)); - results.push_back(entry); + return res; } #endif