From 2de7d4684cd1879e61cd716416a51e664e2369c6 Mon Sep 17 00:00:00 2001 From: mdimon Date: Thu, 27 Sep 2018 03:31:53 +0700 Subject: [PATCH 1/5] add smart-contract methods --- src/Makefile.am | 1 + src/Makefile.test.include | 1 + src/rpccontracts.cpp | 309 ++++++++++++++++++++++++++++++++ src/rpcserver.cpp | 12 ++ src/rpcserver.h | 11 ++ src/test/rpccontracts_tests.cpp | 58 ++++++ 6 files changed, 392 insertions(+) create mode 100644 src/rpccontracts.cpp create mode 100644 src/test/rpccontracts_tests.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 15b3e7e..8608409 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -204,6 +204,7 @@ libbitcoin_server_a_SOURCES = \ rpcmisc.cpp \ rpcnet.cpp \ rpcrawtransaction.cpp \ + rpccontracts.cpp \ rpcserver.cpp \ script/sigcache.cpp \ timedata.cpp \ diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 838bc7e..7624405 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -59,6 +59,7 @@ BITCOIN_TESTS =\ test/netbase_tests.cpp \ test/pmt_tests.cpp \ test/rpc_tests.cpp \ + test/rpccontracts_tests.cpp \ test/sanity_tests.cpp \ test/script_P2SH_tests.cpp \ test/script_tests.cpp \ diff --git a/src/rpccontracts.cpp b/src/rpccontracts.cpp new file mode 100644 index 0000000..896145c --- /dev/null +++ b/src/rpccontracts.cpp @@ -0,0 +1,309 @@ +// Copyright (c) 2018 The GIANT developers + +#include "base58.h" +#include "rpcserver.h" + +#include + +using namespace boost; +using namespace boost::assign; +using namespace json_spirit; +using namespace std; + +Value ContractDeploy(const CBitcoinAddress& address, string code, double prioritet) +{ + return 0; +} + +Value ContractCall(bool readonly, double prioritet,const CBitcoinAddress& address, string methodName, Array args) +{ + return 0; +} + +Value ContractAddress(string strHex) +{ + return 0; +} + +Value ContractInfo(const CBitcoinAddress& address, bool calculateProperties, bool callReadonlyMethods) +{ + return 0; +} + +Value ContractCode(const CBitcoinAddress& address) +{ + return 0; +} + +Value ContractBalance(const CBitcoinAddress& address) +{ + return 0; +} + +Value ContractStatus(const CBitcoinAddress& address) +{ + return 0; +} + +Value ContractDeployEstimate(string code, double prioritet, uint64_t loopCount) +{ + return 0; +} + +Value ContractCallEstimate(const CBitcoinAddress& address, const string& methodName, double prioritet, uint64_t loopCount) +{ + return 0; +} + +Value ContractCallEstimate() +{ + return 0; +} + +Value contractdeploy(const Array& params, bool fHelp) +{ + if (fHelp || params.size() < 1 || params.size() > 3) + throw runtime_error( + "contractdeploy \"address\" \"code\" \"prioritet:\"\n" + "\nArguments:\n" + "\naddress - (string) public key through which indication the private key for the signature of transaction will be chosen\n" + "\ncode - (string) smart contract code\n" + "\nprioritet - (double) the weight influencing the size of the commission burned for warm the smart contract" + "\nCreates transaction which deploit the smart contract and sends it to mempool\n" + "\nResult:\n" + "\n if transaction was added to mempool - that the method will return a transaction hash\n" + "\nExamples:\n" + + HelpExampleCli("contractdeploy", "") + HelpExampleRpc("contractdeploy", "")); + + RPCTypeCheck(params, list_of(str_type)(str_type)(real_type)); + + CBitcoinAddress address(params[0].get_str()); + if (bool isValid = address.IsValid()) + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + + std::string code = params[1].get_str(); + + double prioritet = params[2].get_real(); + if (prioritet < 1.0) + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong prioritet"); + + return ContractDeploy(address, code, prioritet); +} + +Value contractcall(const Array& params, bool fHelp) +{ + if (fHelp || params.size() < 1 || params.size() > 5) + throw runtime_error( + "contractcall \"readonly\" \"prioritet:\" \"address\" \"methodName\" \"args\" \n" + "\nArguments:\n" + "\nreadonly - (bool: true|false) if readonly=true and in a call of a method goes\n" + " attempt that to change in a blockchain (for example to change a variable\n" + " in the smart contract) there will be a mistake\n" + "\nprioritet - (double) the weight influencing the size of the commission burned for warm the smart contract" + "\naddress - (string) public key through which indication the private key for the signature of transaction will be chosen\n" + "\nmethodName - (string) name of a method\n" + "\nargs - (array) method call parameter" + "\nResult:\n" + "\nif the readonly=true method that returns value which will return a smart contract method\n" + "\nif the readonly=false method and transaction it is successfully added that the transaction hash will return\n" + "\nExamples:\n" + + HelpExampleCli("contractcall", "") + HelpExampleRpc("contractcall", "")); + + RPCTypeCheck(params, list_of(bool_type)(real_type)(str_type)(str_type)(array_type)); + + bool readonly = params[0].get_bool(); + + double prioritet = params[1].get_real(); + if (prioritet < 1.0) + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong prioritet"); + + CBitcoinAddress address(params[2].get_str()); + if (bool isValid = address.IsValid()) + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + + string methodName = params[3].get_str(); + + Array args = params[4].get_array(); + + return ContractCall(readonly, prioritet, address, methodName, args); +} + +Value contractaddress(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "contractaddress \"txid\"\n" + "\nArguments:\n" + "\ntxid - (string) transaction hash, line 64 symbols long\n" + "\nReturns the smart contract address on a transaction hash\n" + "\nResult:\n" + "\n the transaction address if the contract is found\n" + "\nExamples:\n" + + HelpExampleCli("contractaddress", "") + HelpExampleRpc("contractaddress", "")); + + RPCTypeCheck(params, list_of(str_type)); + + string strHex = params[0].get_str(); + + return ContractAddress(strHex); +} + +Value contractinfo(const Array& params, bool fHelp) +{ + if (fHelp || params.size() < 1 || params.size() > 3) + throw runtime_error( + "contractinfo \"address\" \"calculateProperties\" \"callReadonlyMethods\" \n" + "\nArguments:\n" + "\naddress - (string) public key through which indication the private key for the signature of transaction will be chosen\n" + "\ncalculateProperties - (bool) if true that are calculated values of all fields. If that false isn't specified\n" + "\ncallReadonlyMethods - (bool) if true that are calculated values of all readonly of methods. If that false isn't specified\n" + "\nReturns information on the smart contract on his address\n" + "\nResult:\n" + "\ndata on the smart contract\n" + "\nExamples:\n" + + HelpExampleCli("contractinfo", "") + HelpExampleRpc("contractinfo", "")); + + RPCTypeCheck(params, list_of(str_type)(bool_type)(bool_type)); + + CBitcoinAddress address(params[0].get_str()); + if (bool isValid = address.IsValid()) + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + + bool calculateProperties = params[1].get_bool(); + + bool callReadonlyMethods = params[2].get_bool(); + + return ContractInfo( address, calculateProperties, callReadonlyMethods); +} + +Value contractcode(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "contractcode \"address\"\n" + "\nArguments:\n" + "\naddress - (string) the contract address, the line containing the valid address of the smart contract\n" + "\nReturn a smart contract code to his address\n" + "\nResult:\n" + "\n smart contract code as he is kept in transaction\n" + "\nExamples:\n" + + HelpExampleCli("contractcode", "") + HelpExampleRpc("contractcode", "")); + + RPCTypeCheck(params, list_of(str_type)); + + CBitcoinAddress address(params[0].get_str()); + if (bool isValid = address.IsValid()) + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + + return ContractCode(address); +} + +Value contractbalance(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "contractbalance \"address\"\n" + "\nArguments:\n" + "\naddress - (string) the contract address, the line containing the valid address of the smart contract\n" + "\nReturn balance of the smart contract to his address\n" + "\nResult:\n" + "\nbalance of the contract\n" + "\nExamples:\n" + + HelpExampleCli("contractbalance", "") + HelpExampleRpc("contractbalance", "")); + + RPCTypeCheck(params, list_of(str_type)); + + CBitcoinAddress address(params[0].get_str()); + if (bool isValid = address.IsValid()) + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + + return ContractBalance(address); +} + +Value contractstatus(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "contractstatus \"address\"\n" + "\nArguments:\n" + "\naddress - (string) the contract address, the line containing the valid address of the smart contract\n" + "\nReturn a state it (is active, removed, suspended) the smart contract to his address\n" + "\nResult:\n" + "\ncondition of the contract\n" + "\nExamples:\n" + + HelpExampleCli("contractstatus", "") + HelpExampleRpc("contractstatus", "")); + + RPCTypeCheck(params, list_of(str_type)); + + CBitcoinAddress address(params[0].get_str()); + if (bool isValid = address.IsValid()) + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + + return ContractStatus(address); +} + +Value contractdeployestimate(const Array& params, bool fHelp) +{ + if (fHelp || params.size() < 1 || params.size() > 3) + throw runtime_error( + "contractdeployestimate \"code\" \"prioritet:\" \"loopCount\"\n" + "\nArguments:\n" + "\ncode - (string) smart contract code\n" + "\nprioritet - (double) the weight influencing the size of the commission burned for warm the smart contract" + "\nloopCount (uint64_t) quantity of cycles for calculation of the commission, by default value 1" + "\nEstimates smart contract deploy cost\n" + "\nResult:\n" + "\nvalue of the commission and plan of implementation of the smart contract\n" + "\nExamples:\n" + + HelpExampleCli("contractdeployestimate", "") + HelpExampleRpc("contractdeployestimate", "")); + + RPCTypeCheck(params, list_of(str_type)(real_type)(int_type)); + + string code = params[0].get_str(); + + double prioritet = params[1].get_real(); + if (prioritet < 1.0) + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong prioritet"); + + uint64_t loopCount = params[2].get_uint64(); + + return ContractDeployEstimate(code, prioritet, loopCount); +} + +Value contractcallestimate(const Array& params, bool fHelp) +{ + if (fHelp || params.size() < 1 || params.size() > 4) + throw runtime_error( + "contractcallestimate \"address\" \"methodName\" \"prioritet:\" \"loopCount\"\n" + "\nArguments:\n" + "\naddress - (string) the contract address, the line containing the valid address of the smart contract\n" + "\nmethodName - (string) smart contract method" + "\nprioritet - (double) the weight influencing the size of the commission burned for warm the smart contract" + "\nloopCount (uint64_t) quantity of cycles for calculation of the commission, by default value 1" + "\nEstimates the smart contract method call cost (not readonly)\n" + "\nResult:\n" + "\nvalue of the commission and plan of performance of a method of the smart contract\n" + "\nExamples:\n" + + HelpExampleCli("contractcallestimate", "") + HelpExampleRpc("contractcallestimate", "")); + + RPCTypeCheck(params, list_of(str_type)(str_type)(real_type)(int_type)); + + CBitcoinAddress address(params[0].get_str()); + if (bool isValid = address.IsValid()) + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + + string methodName = params[1].get_str(); + + double prioritet = params[2].get_real(); + if (prioritet < 1.0) + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong prioritet"); + + uint64_t loopCount = params[3].get_uint64(); + + return ContractCallEstimate(address, methodName, prioritet, loopCount); +} + +Value contractcount(const Array& params, bool fHelp) +{ + return ContractCallEstimate(); +} \ No newline at end of file diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 29740c2..c53326d 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -276,6 +276,18 @@ static const CRPCCommand vRPCCommands[] = {"mining", "submitblock", &submitblock, true, true, false}, {"mining", "reservebalance", &reservebalance, true, true, false}, + /* Giant Contracts*/ + {"rpccontracts", "contractdeploy", &contractdeploy, true, true, false}, + {"rpccontracts", "contractcall", &contractcall, true, true, false}, + {"rpccontracts", "contractaddress", &contractaddress, true, true, false}, + {"rpccontracts", "contractinfo", &contractinfo, true, true, false}, + {"rpccontracts", "contractcode", &contractcode, true, true, false}, + {"rpccontracts", "contractbalance", &contractbalance, true, true, false}, + {"rpccontracts", "contractstatus", &contractstatus, true, true, false}, + {"rpccontracts", "contractdeployestimate", &contractdeployestimate, true, true, false}, + {"rpccontracts", "contractcallestimate", &contractcallestimate, true, true, false}, + {"rpccontracts", "contractcount", &contractcount, true, true, false}, + #ifdef ENABLE_WALLET /* Coin generation */ {"generating", "getgenerate", &getgenerate, true, false, false}, diff --git a/src/rpcserver.h b/src/rpcserver.h index f992ddc..a7a36ba 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -223,6 +223,17 @@ extern json_spirit::Value decodescript(const json_spirit::Array& params, bool fH 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 contractdeploy(const json_spirit::Array& params, bool fHelp); // in rpccontracts.cpp +extern json_spirit::Value contractcall(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value contractaddress(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value contractinfo(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value contractcode(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value contractbalance(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value contractstatus(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value contractdeployestimate(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value contractcallestimate(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value contractcount(const json_spirit::Array& params, bool fHelp); + extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp extern json_spirit::Value getbestblockhash(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getdifficulty(const json_spirit::Array& params, bool fHelp); diff --git a/src/test/rpccontracts_tests.cpp b/src/test/rpccontracts_tests.cpp new file mode 100644 index 0000000..b92c61f --- /dev/null +++ b/src/test/rpccontracts_tests.cpp @@ -0,0 +1,58 @@ +// Copyright (c) 2018 The GIANT developers + +#include "rpcserver.h" +#include "rpcclient.h" + +#include "base58.h" +#include "netbase.h" + +#include +#include + +using namespace std; +using namespace json_spirit; + +Value CallContRPC(string args) +{ + vector vArgs; + boost::split(vArgs, args, boost::is_any_of(" \t")); + string strMethod = vArgs[0]; + vArgs.erase(vArgs.begin()); + Array params = RPCConvertValues(strMethod, vArgs); + + rpcfn_type method = tableRPC[strMethod]->actor; + try { + Value result = (*method)(params, false); + return result; + } + catch (Object& objError) + { + throw runtime_error(find_value(objError, "message").get_str()); + } +} + + +BOOST_AUTO_TEST_SUITE(rpccontracts_test) + +BOOST_AUTO_TEST_CASE(rpc_contractsparams) +{ + BOOST_CHECK_THROW(CallContRPC("contractdeploy"), runtime_error); + + BOOST_CHECK_THROW(CallContRPC("contractcall"), runtime_error); + + BOOST_CHECK_THROW(CallContRPC("contractaddress"), runtime_error); + + BOOST_CHECK_THROW(CallContRPC("contractinfo"), runtime_error); + + BOOST_CHECK_THROW(CallContRPC("contractcode"), runtime_error); + + BOOST_CHECK_THROW(CallContRPC("contractbalance"), runtime_error); + + BOOST_CHECK_THROW(CallContRPC("contractstatus"), runtime_error); + + BOOST_CHECK_THROW(CallContRPC("contractdeployestimate"), runtime_error); + + BOOST_CHECK_THROW(CallContRPC("contractcallestimate"), runtime_error); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From b0c35f40fbda4f65ef445c1a30fb6ce28d80b920 Mon Sep 17 00:00:00 2001 From: mdimon Date: Thu, 11 Oct 2018 01:55:39 +0700 Subject: [PATCH 2/5] upgrade smart-contract methods --- .gitignore | 1 + src/rpccontracts.cpp | 302 ++++++++++++++++++++++++++++++------------- 2 files changed, 213 insertions(+), 90 deletions(-) diff --git a/.gitignore b/.gitignore index 7ebdbae..0301a8c 100644 --- a/.gitignore +++ b/.gitignore @@ -57,6 +57,7 @@ src/qt/moc_*.cpp src/qt/test/moc_*.cpp *.moc src/config/* +depends/* # Test generated files src/test/data/*.h \ No newline at end of file diff --git a/src/rpccontracts.cpp b/src/rpccontracts.cpp index 896145c..470ebc3 100644 --- a/src/rpccontracts.cpp +++ b/src/rpccontracts.cpp @@ -2,6 +2,7 @@ #include "base58.h" #include "rpcserver.h" +#include "net.h" #include @@ -10,22 +11,22 @@ using namespace boost::assign; using namespace json_spirit; using namespace std; -Value ContractDeploy(const CBitcoinAddress& address, string code, double prioritet) +Value ContractDeploy(const CBitcoinAddress& addressObject, string jscode, const double prioritet) { return 0; } -Value ContractCall(bool readonly, double prioritet,const CBitcoinAddress& address, string methodName, Array args) +Value ContractCall(bool readonly, const double& prioritet,const CBitcoinAddress& addressObject, const string& methodName, const Array& args) { return 0; } -Value ContractAddress(string strHex) +Value ContractAddress(const string& strHex) { return 0; } -Value ContractInfo(const CBitcoinAddress& address, bool calculateProperties, bool callReadonlyMethods) +Value ContractInfo(const CBitcoinAddress& addressObject, bool calculateProperties, bool callReadonlyMethods) { return 0; } @@ -45,87 +46,142 @@ Value ContractStatus(const CBitcoinAddress& address) return 0; } -Value ContractDeployEstimate(string code, double prioritet, uint64_t loopCount) +Value ContractDeployEstimate(string jscode, const double& prioritet, uint64_t loopCount) { return 0; } -Value ContractCallEstimate(const CBitcoinAddress& address, const string& methodName, double prioritet, uint64_t loopCount) +Value ContractCallEstimate(const CBitcoinAddress& addressObject, const string& methodName, const double& prioritet, uint64_t loopCount) { return 0; } -Value ContractCallEstimate() +Value ContractCount() { return 0; } Value contractdeploy(const Array& params, bool fHelp) { - if (fHelp || params.size() < 1 || params.size() > 3) + if (fHelp || params.size() != 1) throw runtime_error( - "contractdeploy \"address\" \"code\" \"prioritet:\"\n" - "\nArguments:\n" - "\naddress - (string) public key through which indication the private key for the signature of transaction will be chosen\n" - "\ncode - (string) smart contract code\n" - "\nprioritet - (double) the weight influencing the size of the commission burned for warm the smart contract" - "\nCreates transaction which deploit the smart contract and sends it to mempool\n" - "\nResult:\n" - "\n if transaction was added to mempool - that the method will return a transaction hash\n" - "\nExamples:\n" + - HelpExampleCli("contractdeploy", "") + HelpExampleRpc("contractdeploy", "")); - - RPCTypeCheck(params, list_of(str_type)(str_type)(real_type)); - - CBitcoinAddress address(params[0].get_str()); - if (bool isValid = address.IsValid()) + "contractdeploy \"address\" \"jscode\" \"prioritet:\"\n" + "\nCreates transaction which deploit the smart contract and sends it to mempool\n" + "\nArguments:\n" + " {\n" + " \"address\":\"address\", - (string) public key through which indication the private key for the signature of transaction will be chosen\n" + " \"jscode\":\"jscode\", - (string) smart contract code\n" + " \"prioritet\": prioritet - (double) the weight influencing the size of the commission burned for warm the smart contract\n" + " }\n" + "\nResult:\n" + "\n if transaction was added to mempool - that the method will return a transaction hash\n" + " }\n" + " ]\n" + ); + + RPCTypeCheck(params, list_of(obj_type)); + + Object deployInfo = params[0].get_obj(); + string address; + string jscode; + double prioritet = 1; + + BOOST_FOREACH(const Pair& s, deployInfo) { + if (s.name_ == "address") { + address = s.value_.get_str(); + } else if (s.name_ == "jscode") { + jscode = s.value_.get_str(); + } else if (s.name_ == "prioritet") { + prioritet = s.value_.get_real(); + } + }; + + if (address.empty()) { throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } + CBitcoinAddress addressObject(address); + if (!addressObject.IsValid()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } - std::string code = params[1].get_str(); + if (jscode.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid JScode"); + } - double prioritet = params[2].get_real(); - if (prioritet < 1.0) - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong prioritet"); + if (prioritet < 1) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong parametr prioritet"); + } - return ContractDeploy(address, code, prioritet); + return ContractDeploy(addressObject, jscode, prioritet); } Value contractcall(const Array& params, bool fHelp) { - if (fHelp || params.size() < 1 || params.size() > 5) + if (fHelp || params.size() != 1) throw runtime_error( "contractcall \"readonly\" \"prioritet:\" \"address\" \"methodName\" \"args\" \n" "\nArguments:\n" - "\nreadonly - (bool: true|false) if readonly=true and in a call of a method goes\n" - " attempt that to change in a blockchain (for example to change a variable\n" - " in the smart contract) there will be a mistake\n" - "\nprioritet - (double) the weight influencing the size of the commission burned for warm the smart contract" - "\naddress - (string) public key through which indication the private key for the signature of transaction will be chosen\n" - "\nmethodName - (string) name of a method\n" - "\nargs - (array) method call parameter" + " {\n" + " \"readonly\": true/false,- (bool: true|false) if readonly=true and in a call of a method goes\n" + " attempt that to change in a blockchain (for example to change a variable\n" + " in the smart contract) there will be a mistake\n" + " \"prioritet\": prioritet, - (double) the weight influencing the size of the commission burned for warm the smart contract" + " \"address\": \"address\", - (string) public key through which indication the private key for the signature of transaction will be chosen\n" + " \"methodName\": \"methodName\", - (string) name of a method\n" + " \"args\": args - (array) method call parameter" + " }\n" "\nResult:\n" "\nif the readonly=true method that returns value which will return a smart contract method\n" "\nif the readonly=false method and transaction it is successfully added that the transaction hash will return\n" "\nExamples:\n" + HelpExampleCli("contractcall", "") + HelpExampleRpc("contractcall", "")); - RPCTypeCheck(params, list_of(bool_type)(real_type)(str_type)(str_type)(array_type)); - - bool readonly = params[0].get_bool(); - - double prioritet = params[1].get_real(); - if (prioritet < 1.0) - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong prioritet"); - - CBitcoinAddress address(params[2].get_str()); - if (bool isValid = address.IsValid()) + RPCTypeCheck(params, list_of(obj_type)); + + Object callInfo = params[0].get_obj(); + bool readonly; + double prioritet = 1; + string address; + string methodName; + Array args; + + BOOST_FOREACH(const Pair& c, callInfo) { + if (c.name_ == "readonly") { + readonly = c.value_.get_bool(); + } else if (c.name_ == "prioritet") { + prioritet = c.value_.get_real(); + } else if (c.name_ == "address") { + address = c.value_.get_str(); + } else if (c.name_ == "prioritet") { + prioritet = c.value_.get_real(); + } else if (c.name_ == "methodName") { + methodName = c.value_.get_str(); + } else if (c.name_ == "args") { + args = c.value_.get_array(); + } + }; + + if (prioritet < 1) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong parametr prioritet"); + } + + if (address.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } + CBitcoinAddress addressObject(address); + if (!addressObject.IsValid()) { throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } - string methodName = params[3].get_str(); + if (methodName.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong methodName parametr"); + } - Array args = params[4].get_array(); + if (args.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong args parametr"); + } - return ContractCall(readonly, prioritet, address, methodName, args); + return ContractCall(readonly, prioritet, addressObject, methodName, args); } Value contractaddress(const Array& params, bool fHelp) @@ -150,30 +206,47 @@ Value contractaddress(const Array& params, bool fHelp) Value contractinfo(const Array& params, bool fHelp) { - if (fHelp || params.size() < 1 || params.size() > 3) + if (fHelp || params.size() != 1) throw runtime_error( "contractinfo \"address\" \"calculateProperties\" \"callReadonlyMethods\" \n" "\nArguments:\n" - "\naddress - (string) public key through which indication the private key for the signature of transaction will be chosen\n" - "\ncalculateProperties - (bool) if true that are calculated values of all fields. If that false isn't specified\n" - "\ncallReadonlyMethods - (bool) if true that are calculated values of all readonly of methods. If that false isn't specified\n" + " {\n" + " \"address\": \"address\", - (string) public key through which indication the private key for the signature of transaction will be chosen\n" + " \"calculateProperties\": true, - (bool) if true that are calculated values of all fields. If that false isn't specified\n" + " \"callReadonlyMethods\": true - (bool) if true that are calculated values of all readonly of methods. If that false isn't specified\n" + " }\n" "\nReturns information on the smart contract on his address\n" "\nResult:\n" "\ndata on the smart contract\n" "\nExamples:\n" + HelpExampleCli("contractinfo", "") + HelpExampleRpc("contractinfo", "")); - RPCTypeCheck(params, list_of(str_type)(bool_type)(bool_type)); + RPCTypeCheck(params, list_of(obj_type)); - CBitcoinAddress address(params[0].get_str()); - if (bool isValid = address.IsValid()) - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + Object contInfo = params[0].get_obj(); + string address; + bool calculateProperties = false; + bool callReadonlyMethods = false; - bool calculateProperties = params[1].get_bool(); + BOOST_FOREACH(const Pair& a, contInfo) { + if (a.name_ == "address") { + address = a.value_.get_str(); + } else if (a.name_ == "calculateProperties") { + calculateProperties = a.value_.get_bool(); + } else if (a.name_ == "callReadonlyMethods") { + callReadonlyMethods = a.value_.get_bool(); + } + }; - bool callReadonlyMethods = params[2].get_bool(); + if (address.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } + CBitcoinAddress addressObject(address); + if (!addressObject.IsValid()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } - return ContractInfo( address, calculateProperties, callReadonlyMethods); + return ContractInfo( addressObject, calculateProperties, callReadonlyMethods); } Value contractcode(const Array& params, bool fHelp) @@ -192,7 +265,7 @@ Value contractcode(const Array& params, bool fHelp) RPCTypeCheck(params, list_of(str_type)); CBitcoinAddress address(params[0].get_str()); - if (bool isValid = address.IsValid()) + if (bool isValid = !(address.IsValid())) throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); return ContractCode(address); @@ -214,7 +287,7 @@ Value contractbalance(const Array& params, bool fHelp) RPCTypeCheck(params, list_of(str_type)); CBitcoinAddress address(params[0].get_str()); - if (bool isValid = address.IsValid()) + if (bool isValid = !(address.IsValid())) throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); return ContractBalance(address); @@ -236,7 +309,7 @@ Value contractstatus(const Array& params, bool fHelp) RPCTypeCheck(params, list_of(str_type)); CBitcoinAddress address(params[0].get_str()); - if (bool isValid = address.IsValid()) + if (bool isValid = !(address.IsValid())) throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); return ContractStatus(address); @@ -244,66 +317,115 @@ Value contractstatus(const Array& params, bool fHelp) Value contractdeployestimate(const Array& params, bool fHelp) { - if (fHelp || params.size() < 1 || params.size() > 3) + if (fHelp || params.size() != 1) throw runtime_error( "contractdeployestimate \"code\" \"prioritet:\" \"loopCount\"\n" "\nArguments:\n" - "\ncode - (string) smart contract code\n" - "\nprioritet - (double) the weight influencing the size of the commission burned for warm the smart contract" - "\nloopCount (uint64_t) quantity of cycles for calculation of the commission, by default value 1" + " {\n" + " \"jscode\": \"jscode\", - (string) smart contract code\n" + " \"prioritet\": prioritet, - (double) the weight influencing the size of the commission burned for warm the smart contract" + " \"loopCount\": loopCount (uint64_t) quantity of cycles for calculation of the commission, by default value 1" + " }\n" "\nEstimates smart contract deploy cost\n" "\nResult:\n" "\nvalue of the commission and plan of implementation of the smart contract\n" "\nExamples:\n" + HelpExampleCli("contractdeployestimate", "") + HelpExampleRpc("contractdeployestimate", "")); - RPCTypeCheck(params, list_of(str_type)(real_type)(int_type)); + RPCTypeCheck(params, list_of(obj_type)); + + Object deployestimateInfo = params[0].get_obj(); + string jscode; + double prioritet = 1; + uint64_t loopCount =1; - string code = params[0].get_str(); + BOOST_FOREACH(const Pair& b, deployestimateInfo) { + if (b.name_ == "jscode") { + jscode = b.value_.get_str(); + } else if (b.name_ == "prioritet") { + prioritet = b.value_.get_real(); + } else if (b.name_ == "loopCount") { + loopCount = b.value_.get_uint64(); + } + }; - double prioritet = params[1].get_real(); - if (prioritet < 1.0) - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong prioritet"); + if (jscode.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid JScode"); + } - uint64_t loopCount = params[2].get_uint64(); + if (prioritet < 1) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong parametr prioritet"); + } - return ContractDeployEstimate(code, prioritet, loopCount); + if (loopCount < 1) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong parametr loopCount"); + } + + return ContractDeployEstimate(jscode, prioritet, loopCount); } Value contractcallestimate(const Array& params, bool fHelp) { - if (fHelp || params.size() < 1 || params.size() > 4) + if (fHelp || params.size() != 1) throw runtime_error( "contractcallestimate \"address\" \"methodName\" \"prioritet:\" \"loopCount\"\n" "\nArguments:\n" - "\naddress - (string) the contract address, the line containing the valid address of the smart contract\n" - "\nmethodName - (string) smart contract method" - "\nprioritet - (double) the weight influencing the size of the commission burned for warm the smart contract" - "\nloopCount (uint64_t) quantity of cycles for calculation of the commission, by default value 1" + " {\n" + " \"address\": \"address\", - (string) the contract address, the line containing the valid address of the smart contract\n" + " \"methodName\": \"methodName\", - (string) smart contract method" + " \"prioritet\": prioritet, - (double) the weight influencing the size of the commission burned for warm the smart contract" + " \"loopCount\": loopCount (uint64_t) quantity of cycles for calculation of the commission, by default value 1" + " }\n" "\nEstimates the smart contract method call cost (not readonly)\n" "\nResult:\n" "\nvalue of the commission and plan of performance of a method of the smart contract\n" "\nExamples:\n" + HelpExampleCli("contractcallestimate", "") + HelpExampleRpc("contractcallestimate", "")); - RPCTypeCheck(params, list_of(str_type)(str_type)(real_type)(int_type)); - - CBitcoinAddress address(params[0].get_str()); - if (bool isValid = address.IsValid()) + RPCTypeCheck(params, list_of(obj_type)); + + Object callestimateInfo = params[0].get_obj(); + string address; + string methodName; + double prioritet = 1; + uint64_t loopCount =1; + + BOOST_FOREACH(const Pair& d, callestimateInfo) { + if (d.name_ == "address") { + address = d.value_.get_str(); + } else if (d.name_ == "methodName") { + methodName = d.value_.get_str(); + } else if (d.name_ == "prioritet") { + prioritet = d.value_.get_real(); + } else if (d.name_ == "loopCount") { + loopCount = d.value_.get_uint64(); + } + }; + + if (address.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } + CBitcoinAddress addressObject(address); + if (!addressObject.IsValid()) { throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } - string methodName = params[1].get_str(); + if (methodName.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong methodName parametr"); + } - double prioritet = params[2].get_real(); - if (prioritet < 1.0) - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong prioritet"); + if (prioritet < 1) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong parametr prioritet"); + } - uint64_t loopCount = params[3].get_uint64(); + if (loopCount < 1) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong parametr loopCount"); + } - return ContractCallEstimate(address, methodName, prioritet, loopCount); + return ContractCallEstimate(addressObject, methodName, prioritet, loopCount); } Value contractcount(const Array& params, bool fHelp) { - return ContractCallEstimate(); + return ContractCount(); } \ No newline at end of file From 76344adf1638d4d5ba97988620a1dc6fbb4a9f3a Mon Sep 17 00:00:00 2001 From: mdimon Date: Sun, 28 Oct 2018 07:00:46 +0700 Subject: [PATCH 3/5] add tests smart-contract methods, upgrade smart-contract methods --- src/rpcclient.cpp | 9 +++ src/rpccontracts.cpp | 103 ++++++++++++++++++++------------ src/test/rpccontracts_tests.cpp | 77 ++++++++++++++++++++++-- 3 files changed, 147 insertions(+), 42 deletions(-) diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 4f2abc4..c92b5d7 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -106,6 +106,15 @@ static const CRPCConvertParam vRPCConvertParams[] = {"setstakesplitthreshold", 0}, {"autocombinerewards", 0}, {"autocombinerewards", 1}, + {"contractdeploy", 0}, + {"contractcall", 0}, + {"contractaddress", 0}, + {"contractinfo", 0}, + {"contractcode", 0}, + {"contractbalance", 0}, + {"contractstatus", 0}, + {"contractdeployestimate", 0}, + {"contractcallestimate", 0}, {"autocombinerewards", 2}}; class CRPCConvertTable diff --git a/src/rpccontracts.cpp b/src/rpccontracts.cpp index 470ebc3..8ecbf97 100644 --- a/src/rpccontracts.cpp +++ b/src/rpccontracts.cpp @@ -3,17 +3,18 @@ #include "base58.h" #include "rpcserver.h" #include "net.h" +#include "util.h" -#include +#include "json/json_spirit_utils.h" +#include "json/json_spirit_value.h" using namespace boost; -using namespace boost::assign; using namespace json_spirit; using namespace std; Value ContractDeploy(const CBitcoinAddress& addressObject, string jscode, const double prioritet) { - return 0; + return 0; } Value ContractCall(bool readonly, const double& prioritet,const CBitcoinAddress& addressObject, const string& methodName, const Array& args) @@ -65,7 +66,7 @@ Value contractdeploy(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "contractdeploy \"address\" \"jscode\" \"prioritet:\"\n" + "contractdeploy '{\"address\":\"address\",\"jscode\":\"code\",\"prioritet\":123}'\n" "\nCreates transaction which deploit the smart contract and sends it to mempool\n" "\nArguments:\n" " {\n" @@ -79,8 +80,6 @@ Value contractdeploy(const Array& params, bool fHelp) " ]\n" ); - RPCTypeCheck(params, list_of(obj_type)); - Object deployInfo = params[0].get_obj(); string address; string jscode; @@ -119,7 +118,7 @@ Value contractcall(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "contractcall \"readonly\" \"prioritet:\" \"address\" \"methodName\" \"args\" \n" + "contractcall '{\"readonly\":true/false,\"prioritet\":123,\"address\":\"address\",\"methodName\":\"methodName\",\"args\":[\"args\"]}' \n" "\nArguments:\n" " {\n" " \"readonly\": true/false,- (bool: true|false) if readonly=true and in a call of a method goes\n" @@ -136,8 +135,6 @@ Value contractcall(const Array& params, bool fHelp) "\nExamples:\n" + HelpExampleCli("contractcall", "") + HelpExampleRpc("contractcall", "")); - RPCTypeCheck(params, list_of(obj_type)); - Object callInfo = params[0].get_obj(); bool readonly; double prioritet = 1; @@ -152,8 +149,6 @@ Value contractcall(const Array& params, bool fHelp) prioritet = c.value_.get_real(); } else if (c.name_ == "address") { address = c.value_.get_str(); - } else if (c.name_ == "prioritet") { - prioritet = c.value_.get_real(); } else if (c.name_ == "methodName") { methodName = c.value_.get_str(); } else if (c.name_ == "args") { @@ -188,7 +183,7 @@ Value contractaddress(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "contractaddress \"txid\"\n" + "contractaddress '{\"txid\":\"txid\"}'\n" "\nArguments:\n" "\ntxid - (string) transaction hash, line 64 symbols long\n" "\nReturns the smart contract address on a transaction hash\n" @@ -197,9 +192,14 @@ Value contractaddress(const Array& params, bool fHelp) "\nExamples:\n" + HelpExampleCli("contractaddress", "") + HelpExampleRpc("contractaddress", "")); - RPCTypeCheck(params, list_of(str_type)); + Object addressInfo = params[0].get_obj(); + string strHex; - string strHex = params[0].get_str(); + BOOST_FOREACH(const Pair& d, addressInfo) { + if (d.name_ == "txid") { + strHex = d.value_.get_str(); + } + }; return ContractAddress(strHex); } @@ -208,12 +208,12 @@ Value contractinfo(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "contractinfo \"address\" \"calculateProperties\" \"callReadonlyMethods\" \n" + "contractinfo '{\"address\":\"address\",\"calculateProperties\":true/false,\"callReadonlyMethods\":true/false}' \n" "\nArguments:\n" " {\n" - " \"address\": \"address\", - (string) public key through which indication the private key for the signature of transaction will be chosen\n" - " \"calculateProperties\": true, - (bool) if true that are calculated values of all fields. If that false isn't specified\n" - " \"callReadonlyMethods\": true - (bool) if true that are calculated values of all readonly of methods. If that false isn't specified\n" + " \"address\":\"address\", - (string) public key through which indication the private key for the signature of transaction will be chosen\n" + " \"calculateProperties\":true, - (bool) if true that are calculated values of all fields. If that false isn't specified\n" + " \"callReadonlyMethods\":true - (bool) if true that are calculated values of all readonly of methods. If that false isn't specified\n" " }\n" "\nReturns information on the smart contract on his address\n" "\nResult:\n" @@ -221,8 +221,6 @@ Value contractinfo(const Array& params, bool fHelp) "\nExamples:\n" + HelpExampleCli("contractinfo", "") + HelpExampleRpc("contractinfo", "")); - RPCTypeCheck(params, list_of(obj_type)); - Object contInfo = params[0].get_obj(); string address; bool calculateProperties = false; @@ -253,7 +251,7 @@ Value contractcode(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "contractcode \"address\"\n" + "contractcode '{\"address\":\"address\"}'\n" "\nArguments:\n" "\naddress - (string) the contract address, the line containing the valid address of the smart contract\n" "\nReturn a smart contract code to his address\n" @@ -262,11 +260,22 @@ Value contractcode(const Array& params, bool fHelp) "\nExamples:\n" + HelpExampleCli("contractcode", "") + HelpExampleRpc("contractcode", "")); - RPCTypeCheck(params, list_of(str_type)); + Object codeInfo = params[0].get_obj(); + string address; - CBitcoinAddress address(params[0].get_str()); - if (bool isValid = !(address.IsValid())) + BOOST_FOREACH(const Pair& cc, codeInfo) { + if (cc.name_ == "address") { + address = cc.value_.get_str(); + } + }; + + if (address.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } + CBitcoinAddress addressObject(address); + if (!addressObject.IsValid()) { throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } return ContractCode(address); } @@ -275,7 +284,7 @@ Value contractbalance(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "contractbalance \"address\"\n" + "contractbalance '{\"address\":\"address\"}'\n" "\nArguments:\n" "\naddress - (string) the contract address, the line containing the valid address of the smart contract\n" "\nReturn balance of the smart contract to his address\n" @@ -284,11 +293,22 @@ Value contractbalance(const Array& params, bool fHelp) "\nExamples:\n" + HelpExampleCli("contractbalance", "") + HelpExampleRpc("contractbalance", "")); - RPCTypeCheck(params, list_of(str_type)); + Object balanceInfo = params[0].get_obj(); + string address; + + BOOST_FOREACH(const Pair& cb, balanceInfo) { + if (cb.name_ == "address") { + address = cb.value_.get_str(); + } + }; - CBitcoinAddress address(params[0].get_str()); - if (bool isValid = !(address.IsValid())) + if (address.empty()) { throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } + CBitcoinAddress addressObject(address); + if (!addressObject.IsValid()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } return ContractBalance(address); } @@ -297,7 +317,7 @@ Value contractstatus(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "contractstatus \"address\"\n" + "contractstatus '{\"address\":\"address\"}'\n" "\nArguments:\n" "\naddress - (string) the contract address, the line containing the valid address of the smart contract\n" "\nReturn a state it (is active, removed, suspended) the smart contract to his address\n" @@ -306,11 +326,22 @@ Value contractstatus(const Array& params, bool fHelp) "\nExamples:\n" + HelpExampleCli("contractstatus", "") + HelpExampleRpc("contractstatus", "")); - RPCTypeCheck(params, list_of(str_type)); + Object statusInfo = params[0].get_obj(); + string address; - CBitcoinAddress address(params[0].get_str()); - if (bool isValid = !(address.IsValid())) + BOOST_FOREACH(const Pair& g, statusInfo) { + if (g.name_ == "address") { + address = g.value_.get_str(); + } + }; + + if (address.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } + CBitcoinAddress addressObject(address); + if (!addressObject.IsValid()) { throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } return ContractStatus(address); } @@ -319,7 +350,7 @@ Value contractdeployestimate(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "contractdeployestimate \"code\" \"prioritet:\" \"loopCount\"\n" + "contractdeployestimate '{\"jscode\":\"code\",\"prioritet\":123,\"loopCount\":1}'\n" "\nArguments:\n" " {\n" " \"jscode\": \"jscode\", - (string) smart contract code\n" @@ -332,8 +363,6 @@ Value contractdeployestimate(const Array& params, bool fHelp) "\nExamples:\n" + HelpExampleCli("contractdeployestimate", "") + HelpExampleRpc("contractdeployestimate", "")); - RPCTypeCheck(params, list_of(obj_type)); - Object deployestimateInfo = params[0].get_obj(); string jscode; double prioritet = 1; @@ -368,7 +397,7 @@ Value contractcallestimate(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "contractcallestimate \"address\" \"methodName\" \"prioritet:\" \"loopCount\"\n" + "contractcallestimate '{\"address\":\"address\",\"methodName\":\"methodName\",\"prioritet\":123,\"loopCount\":1}'\n" "\nArguments:\n" " {\n" " \"address\": \"address\", - (string) the contract address, the line containing the valid address of the smart contract\n" @@ -382,8 +411,6 @@ Value contractcallestimate(const Array& params, bool fHelp) "\nExamples:\n" + HelpExampleCli("contractcallestimate", "") + HelpExampleRpc("contractcallestimate", "")); - RPCTypeCheck(params, list_of(obj_type)); - Object callestimateInfo = params[0].get_obj(); string address; string methodName; diff --git a/src/test/rpccontracts_tests.cpp b/src/test/rpccontracts_tests.cpp index b92c61f..3d7a1e8 100644 --- a/src/test/rpccontracts_tests.cpp +++ b/src/test/rpccontracts_tests.cpp @@ -9,6 +9,8 @@ #include #include +#define BOOST_TEST_MODULE rpccontracts_test + using namespace std; using namespace json_spirit; @@ -31,28 +33,95 @@ Value CallContRPC(string args) } } - -BOOST_AUTO_TEST_SUITE(rpccontracts_test) - -BOOST_AUTO_TEST_CASE(rpc_contractsparams) +string adv = "\"address\":\"GeKm65nBdbZs9MRKd858u3SrFR3yNGNV5q\""; // valid giant address +string adiv = "\"address\":\"1eKm65nBdbZs9MRKd858u3SrFR3yNGNV5q\""; // invalid giant address +string jscv = "\"jscode\":\"codejs1\""; // valid js code +string jsciv = ""; // invalid parametr js code +string prv = "\"prioritet\":1"; // valid parametr prioritet 1< +string priv = "\"prioritet\":0.1"; // invalid parametr prioritet <1 +string mNv = "\"methodName\":\"methodName1\""; +string mNiv = ""; +string argsv = "\"args\":[\"args\"]"; +string argsiv = ""; +string rov = "\"readonly\":true"; +string calProv = "\"calculateProperties\":true"; +string calRoMetv = "\"callReadonlyMethods\":true"; +string lCv = "\"loopCount\":1"; // valid parametr loopCount 1< +string lCiv = "\"loopCount\":0.1"; // invalid parametr loopCount <1 + +BOOST_AUTO_TEST_SUITE(rpccontracts_tests) + +BOOST_AUTO_TEST_CASE(rpc_contractdeploy) { BOOST_CHECK_THROW(CallContRPC("contractdeploy"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractdeploy ") + "{" + adiv + "," + jscv + "," + prv + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractdeploy ") + "{" + adv + "," + jsciv + "," + prv + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractdeploy ") + "{" + adv + "," + jscv + "," + priv + "}"), runtime_error); + BOOST_CHECK(CallContRPC(string("contractdeploy ") + "{" + adv + "," + jscv + "," + prv + "}") == 0); +} +BOOST_AUTO_TEST_CASE(rpc_contractcall) +{ BOOST_CHECK_THROW(CallContRPC("contractcall"), runtime_error); + BOOST_CHECK(CallContRPC(string("contractcall ") + "{" + rov + "," + prv + "," + adv + "," + mNv + "," + argsv + "}") == 0); + BOOST_CHECK_THROW(CallContRPC(string("contractcall ") + "{" + priv + "," + adv + "," + mNv + "," + argsv + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractcall ") + "{" + rov + "," + prv + "," + adiv + "," + mNv + "," + argsv + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractcall ") + "{" + rov + "," + prv + "," + adv + "," + mNiv + "," + argsv + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractcall ") + "{" + rov + "," + prv + "," + adv + "," + mNv + "," + argsiv + "}"), runtime_error); +} +BOOST_AUTO_TEST_CASE(rpc_contractaddress) +{ BOOST_CHECK_THROW(CallContRPC("contractaddress"), runtime_error); +} +BOOST_AUTO_TEST_CASE(rpc_contractinfo) +{ BOOST_CHECK_THROW(CallContRPC("contractinfo"), runtime_error); + BOOST_CHECK(CallContRPC(string("contractinfo ") + "{" + adv + "," + calProv + "," + calRoMetv + "}") == 0); + BOOST_CHECK(CallContRPC(string("contractinfo ") + "{" + adv + "}") == 0); + BOOST_CHECK_THROW(CallContRPC(string("contractinfo ") + "{" + adiv + "," + calProv + "," + calRoMetv + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractinfo ") + "{" + adiv + "}"), runtime_error); +} +BOOST_AUTO_TEST_CASE(rpc_contractcode) +{ BOOST_CHECK_THROW(CallContRPC("contractcode"), runtime_error); + BOOST_CHECK(CallContRPC(string("contractcode ") + "{" + adv + "}") == 0); + BOOST_CHECK_THROW(CallContRPC(string("contractcode ") + "{" + adiv + "}"), runtime_error); +} +BOOST_AUTO_TEST_CASE(rpc_contractbalance) +{ BOOST_CHECK_THROW(CallContRPC("contractbalance"), runtime_error); + BOOST_CHECK(CallContRPC(string("contractbalance ") + "{" + adv + "}") == 0); + BOOST_CHECK_THROW(CallContRPC(string("contractbalance ") + "{" + adiv + "}"), runtime_error); +} +BOOST_AUTO_TEST_CASE(rpc_contractstatus) +{ BOOST_CHECK_THROW(CallContRPC("contractstatus"), runtime_error); + BOOST_CHECK(CallContRPC(string("contractstatus ") + "{" + adv + "}") == 0); + BOOST_CHECK_THROW(CallContRPC(string("contractstatus ") + "{" + adiv + "}"), runtime_error); +} +BOOST_AUTO_TEST_CASE(rpc_contractdeployestimate) +{ BOOST_CHECK_THROW(CallContRPC("contractdeployestimate"), runtime_error); + BOOST_CHECK(CallContRPC(string("contractdeployestimate ") + "{" + jscv + "," + prv + "," + lCv + "}") == 0); + BOOST_CHECK_THROW(CallContRPC(string("contractdeployestimate ") + "{" + jsciv + "," + prv + "," + lCv + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractdeployestimate ") + "{" + jscv + "," + priv + "," + lCv + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractdeployestimate ") + "{" + jscv + "," + prv + "," + lCiv + "}"), runtime_error); +} +BOOST_AUTO_TEST_CASE(rpc_contractcallestimate) +{ BOOST_CHECK_THROW(CallContRPC("contractcallestimate"), runtime_error); + BOOST_CHECK(CallContRPC(string("contractcallestimate ") + "{" + adv + "," + mNv + "," + prv + "," + lCv + "}") == 0); + BOOST_CHECK_THROW(CallContRPC(string("contractcallestimate ") + "{" + adiv + "," + mNv + "," + prv + "," + lCv + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractcallestimate ") + "{" + adv + "," + mNiv + "," + prv + "," + lCv + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractcallestimate ") + "{" + adv + "," + mNv + "," + priv + "," + lCv + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractcallestimate ") + "{" + adv + "," + mNv + "," + prv + "," + lCiv + "}"), runtime_error); } BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From 0ed7c75d627db3f96128aee93f7671478bd1a917 Mon Sep 17 00:00:00 2001 From: mdimon Date: Tue, 30 Oct 2018 21:24:15 +0700 Subject: [PATCH 4/5] upgrade smartcontract method and test --- src/rpccontracts.cpp | 52 +++++++++++--------- src/test/rpccontracts_tests.cpp | 86 ++++++++++++++++----------------- 2 files changed, 71 insertions(+), 67 deletions(-) diff --git a/src/rpccontracts.cpp b/src/rpccontracts.cpp index 8ecbf97..e63250e 100644 --- a/src/rpccontracts.cpp +++ b/src/rpccontracts.cpp @@ -95,14 +95,6 @@ Value contractdeploy(const Array& params, bool fHelp) } }; - if (address.empty()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); - } - CBitcoinAddress addressObject(address); - if (!addressObject.IsValid()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); - } - if (jscode.empty()) { throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid JScode"); } @@ -111,6 +103,14 @@ Value contractdeploy(const Array& params, bool fHelp) throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong parametr prioritet"); } + if (address.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } + CBitcoinAddress addressObject(address); + if (!addressObject.IsValid()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } + return ContractDeploy(addressObject, jscode, prioritet); } @@ -160,14 +160,6 @@ Value contractcall(const Array& params, bool fHelp) throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong parametr prioritet"); } - if (address.empty()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); - } - CBitcoinAddress addressObject(address); - if (!addressObject.IsValid()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); - } - if (methodName.empty()) { throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong methodName parametr"); } @@ -176,6 +168,14 @@ Value contractcall(const Array& params, bool fHelp) throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong args parametr"); } + if (address.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } + CBitcoinAddress addressObject(address); + if (!addressObject.IsValid()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } + return ContractCall(readonly, prioritet, addressObject, methodName, args); } @@ -201,6 +201,10 @@ Value contractaddress(const Array& params, bool fHelp) } }; + if (strHex.size() != 64) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid txid transaction"); + } + return ContractAddress(strHex); } @@ -429,14 +433,6 @@ Value contractcallestimate(const Array& params, bool fHelp) } }; - if (address.empty()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); - } - CBitcoinAddress addressObject(address); - if (!addressObject.IsValid()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); - } - if (methodName.empty()) { throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong methodName parametr"); } @@ -449,6 +445,14 @@ Value contractcallestimate(const Array& params, bool fHelp) throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong parametr loopCount"); } + if (address.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } + CBitcoinAddress addressObject(address); + if (!addressObject.IsValid()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + } + return ContractCallEstimate(addressObject, methodName, prioritet, loopCount); } diff --git a/src/test/rpccontracts_tests.cpp b/src/test/rpccontracts_tests.cpp index 3d7a1e8..655e69b 100644 --- a/src/test/rpccontracts_tests.cpp +++ b/src/test/rpccontracts_tests.cpp @@ -33,95 +33,95 @@ Value CallContRPC(string args) } } -string adv = "\"address\":\"GeKm65nBdbZs9MRKd858u3SrFR3yNGNV5q\""; // valid giant address -string adiv = "\"address\":\"1eKm65nBdbZs9MRKd858u3SrFR3yNGNV5q\""; // invalid giant address -string jscv = "\"jscode\":\"codejs1\""; // valid js code -string jsciv = ""; // invalid parametr js code -string prv = "\"prioritet\":1"; // valid parametr prioritet 1< -string priv = "\"prioritet\":0.1"; // invalid parametr prioritet <1 -string mNv = "\"methodName\":\"methodName1\""; -string mNiv = ""; -string argsv = "\"args\":[\"args\"]"; -string argsiv = ""; -string rov = "\"readonly\":true"; -string calProv = "\"calculateProperties\":true"; -string calRoMetv = "\"callReadonlyMethods\":true"; -string lCv = "\"loopCount\":1"; // valid parametr loopCount 1< -string lCiv = "\"loopCount\":0.1"; // invalid parametr loopCount <1 +string sAddressValid = "\"address\":\"GeKm65nBdbZs9MRKd858u3SrFR3yNGNV5q\""; +string sAddressInvalid = "\"address\":\"1eKm65nBdbZs9MRKd858u3SrFR3yNGNV5q\""; +string sPrioritetValid = "\"prioritet\":1"; +string sPrioritetInvalid = "\"prioritet\":0.1"; +string sMethodNameValid = "\"methodName\":\"methodName1\""; +string sMethodNameInvalid = ""; +string sArgsValid = "\"args\":[\"args\"]"; +string sArgsInvalid = ""; +string sReadOnlyValid = "\"readonly\":true"; +string sCalculateProperties = "\"calculateProperties\":true"; +string sCallReadOnlyMethodsValid = "\"callReadonlyMethods\":true"; +string sLoopCountValid = "\"loopCount\":1"; +string sLoopCountInvalid = "\"loopCount\":0.1"; +string sJsCode = "\"jscode\":\"Hello+,World!\""; +string sTxidInvalid = "\"txid\":\"a3b807410df0b60fcb9736768df5823938b2f838694939ba45f3c0a1bff150ed1\""; BOOST_AUTO_TEST_SUITE(rpccontracts_tests) BOOST_AUTO_TEST_CASE(rpc_contractdeploy) { BOOST_CHECK_THROW(CallContRPC("contractdeploy"), runtime_error); - BOOST_CHECK_THROW(CallContRPC(string("contractdeploy ") + "{" + adiv + "," + jscv + "," + prv + "}"), runtime_error); - BOOST_CHECK_THROW(CallContRPC(string("contractdeploy ") + "{" + adv + "," + jsciv + "," + prv + "}"), runtime_error); - BOOST_CHECK_THROW(CallContRPC(string("contractdeploy ") + "{" + adv + "," + jscv + "," + priv + "}"), runtime_error); - BOOST_CHECK(CallContRPC(string("contractdeploy ") + "{" + adv + "," + jscv + "," + prv + "}") == 0); + BOOST_CHECK_THROW(CallContRPC(string("contractdeploy ") + "{" + sAddressInvalid + "," + sJsCode + "," + sPrioritetValid + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractdeploy ") + "{" + sAddressValid + "," + sJsCode + "," + sPrioritetInvalid + "}"), runtime_error); + BOOST_CHECK(CallContRPC(string("contractdeploy ") + "{" + sAddressValid + "," + sJsCode + "," + sPrioritetValid + "}") == 0); } BOOST_AUTO_TEST_CASE(rpc_contractcall) { BOOST_CHECK_THROW(CallContRPC("contractcall"), runtime_error); - BOOST_CHECK(CallContRPC(string("contractcall ") + "{" + rov + "," + prv + "," + adv + "," + mNv + "," + argsv + "}") == 0); - BOOST_CHECK_THROW(CallContRPC(string("contractcall ") + "{" + priv + "," + adv + "," + mNv + "," + argsv + "}"), runtime_error); - BOOST_CHECK_THROW(CallContRPC(string("contractcall ") + "{" + rov + "," + prv + "," + adiv + "," + mNv + "," + argsv + "}"), runtime_error); - BOOST_CHECK_THROW(CallContRPC(string("contractcall ") + "{" + rov + "," + prv + "," + adv + "," + mNiv + "," + argsv + "}"), runtime_error); - BOOST_CHECK_THROW(CallContRPC(string("contractcall ") + "{" + rov + "," + prv + "," + adv + "," + mNv + "," + argsiv + "}"), runtime_error); + BOOST_CHECK(CallContRPC(string("contractcall ") + "{" + sReadOnlyValid + "," + sPrioritetValid + "," + sAddressValid + "," + sMethodNameValid + "," + sArgsValid + "}") == 0); + BOOST_CHECK_THROW(CallContRPC(string("contractcall ") + "{" + sPrioritetInvalid + "," + sAddressValid + "," + sMethodNameValid + "," + sArgsValid + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractcall ") + "{" + sReadOnlyValid + "," + sPrioritetValid + "," + sAddressInvalid + "," + sMethodNameValid + "," + sArgsValid + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractcall ") + "{" + sReadOnlyValid + "," + sPrioritetValid + "," + sAddressValid + "," + sMethodNameInvalid + "," + sArgsValid + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractcall ") + "{" + sReadOnlyValid + "," + sPrioritetValid + "," + sAddressValid + "," + sMethodNameValid + "," + sArgsInvalid + "}"), runtime_error); } BOOST_AUTO_TEST_CASE(rpc_contractaddress) { BOOST_CHECK_THROW(CallContRPC("contractaddress"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractaddress ") + "{" + sTxidInvalid + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractaddress ") + "{" + "}"), runtime_error); } BOOST_AUTO_TEST_CASE(rpc_contractinfo) { BOOST_CHECK_THROW(CallContRPC("contractinfo"), runtime_error); - BOOST_CHECK(CallContRPC(string("contractinfo ") + "{" + adv + "," + calProv + "," + calRoMetv + "}") == 0); - BOOST_CHECK(CallContRPC(string("contractinfo ") + "{" + adv + "}") == 0); - BOOST_CHECK_THROW(CallContRPC(string("contractinfo ") + "{" + adiv + "," + calProv + "," + calRoMetv + "}"), runtime_error); - BOOST_CHECK_THROW(CallContRPC(string("contractinfo ") + "{" + adiv + "}"), runtime_error); + BOOST_CHECK(CallContRPC(string("contractinfo ") + "{" + sAddressValid + "," + sCalculateProperties + "," + sCallReadOnlyMethodsValid + "}") == 0); + BOOST_CHECK(CallContRPC(string("contractinfo ") + "{" + sAddressValid + "}") == 0); + BOOST_CHECK_THROW(CallContRPC(string("contractinfo ") + "{" + sAddressInvalid + "," + sCalculateProperties + "," + sCallReadOnlyMethodsValid + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractinfo ") + "{" + sAddressInvalid + "}"), runtime_error); } BOOST_AUTO_TEST_CASE(rpc_contractcode) { BOOST_CHECK_THROW(CallContRPC("contractcode"), runtime_error); - BOOST_CHECK(CallContRPC(string("contractcode ") + "{" + adv + "}") == 0); - BOOST_CHECK_THROW(CallContRPC(string("contractcode ") + "{" + adiv + "}"), runtime_error); + BOOST_CHECK(CallContRPC(string("contractcode ") + "{" + sAddressValid + "}") == 0); + BOOST_CHECK_THROW(CallContRPC(string("contractcode ") + "{" + sAddressInvalid + "}"), runtime_error); } BOOST_AUTO_TEST_CASE(rpc_contractbalance) { BOOST_CHECK_THROW(CallContRPC("contractbalance"), runtime_error); - BOOST_CHECK(CallContRPC(string("contractbalance ") + "{" + adv + "}") == 0); - BOOST_CHECK_THROW(CallContRPC(string("contractbalance ") + "{" + adiv + "}"), runtime_error); + BOOST_CHECK(CallContRPC(string("contractbalance ") + "{" + sAddressValid + "}") == 0); + BOOST_CHECK_THROW(CallContRPC(string("contractbalance ") + "{" + sAddressInvalid + "}"), runtime_error); } BOOST_AUTO_TEST_CASE(rpc_contractstatus) { BOOST_CHECK_THROW(CallContRPC("contractstatus"), runtime_error); - BOOST_CHECK(CallContRPC(string("contractstatus ") + "{" + adv + "}") == 0); - BOOST_CHECK_THROW(CallContRPC(string("contractstatus ") + "{" + adiv + "}"), runtime_error); + BOOST_CHECK(CallContRPC(string("contractstatus ") + "{" + sAddressValid + "}") == 0); + BOOST_CHECK_THROW(CallContRPC(string("contractstatus ") + "{" + sAddressInvalid + "}"), runtime_error); } BOOST_AUTO_TEST_CASE(rpc_contractdeployestimate) { BOOST_CHECK_THROW(CallContRPC("contractdeployestimate"), runtime_error); - BOOST_CHECK(CallContRPC(string("contractdeployestimate ") + "{" + jscv + "," + prv + "," + lCv + "}") == 0); - BOOST_CHECK_THROW(CallContRPC(string("contractdeployestimate ") + "{" + jsciv + "," + prv + "," + lCv + "}"), runtime_error); - BOOST_CHECK_THROW(CallContRPC(string("contractdeployestimate ") + "{" + jscv + "," + priv + "," + lCv + "}"), runtime_error); - BOOST_CHECK_THROW(CallContRPC(string("contractdeployestimate ") + "{" + jscv + "," + prv + "," + lCiv + "}"), runtime_error); + BOOST_CHECK(CallContRPC(string("contractdeployestimate ") + "{" + sJsCode + "," + sPrioritetValid + "," + sLoopCountValid + "}") == 0); + BOOST_CHECK_THROW(CallContRPC(string("contractdeployestimate ") + "{" + sJsCode + "," + sPrioritetInvalid + "," + sLoopCountValid + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractdeployestimate ") + "{" + sJsCode + "," + sPrioritetValid + "," + sLoopCountInvalid + "}"), runtime_error); } BOOST_AUTO_TEST_CASE(rpc_contractcallestimate) { BOOST_CHECK_THROW(CallContRPC("contractcallestimate"), runtime_error); - BOOST_CHECK(CallContRPC(string("contractcallestimate ") + "{" + adv + "," + mNv + "," + prv + "," + lCv + "}") == 0); - BOOST_CHECK_THROW(CallContRPC(string("contractcallestimate ") + "{" + adiv + "," + mNv + "," + prv + "," + lCv + "}"), runtime_error); - BOOST_CHECK_THROW(CallContRPC(string("contractcallestimate ") + "{" + adv + "," + mNiv + "," + prv + "," + lCv + "}"), runtime_error); - BOOST_CHECK_THROW(CallContRPC(string("contractcallestimate ") + "{" + adv + "," + mNv + "," + priv + "," + lCv + "}"), runtime_error); - BOOST_CHECK_THROW(CallContRPC(string("contractcallestimate ") + "{" + adv + "," + mNv + "," + prv + "," + lCiv + "}"), runtime_error); + BOOST_CHECK(CallContRPC(string("contractcallestimate ") + "{" + sAddressValid + "," + sMethodNameValid + "," + sPrioritetValid + "," + sLoopCountValid + "}") == 0); + BOOST_CHECK_THROW(CallContRPC(string("contractcallestimate ") + "{" + sAddressInvalid + "," + sMethodNameValid + "," + sPrioritetValid + "," + sLoopCountValid + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractcallestimate ") + "{" + sAddressValid + "," + sMethodNameInvalid + "," + sPrioritetValid + "," + sLoopCountValid + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractcallestimate ") + "{" + sAddressValid + "," + sMethodNameValid + "," + sPrioritetInvalid + "," + sLoopCountValid + "}"), runtime_error); + BOOST_CHECK_THROW(CallContRPC(string("contractcallestimate ") + "{" + sAddressValid + "," + sMethodNameValid + "," + sPrioritetValid + "," + sLoopCountInvalid + "}"), runtime_error); } BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From 683ffa1f638cf5ace6340682a532bf0d09465e02 Mon Sep 17 00:00:00 2001 From: mdimon Date: Mon, 5 Nov 2018 18:48:57 +0700 Subject: [PATCH 5/5] update method smart-contract --- src/rpccontracts.cpp | 274 +++++++++++++++++++++---------------------- 1 file changed, 137 insertions(+), 137 deletions(-) diff --git a/src/rpccontracts.cpp b/src/rpccontracts.cpp index e63250e..62a0e24 100644 --- a/src/rpccontracts.cpp +++ b/src/rpccontracts.cpp @@ -12,47 +12,47 @@ using namespace boost; using namespace json_spirit; using namespace std; -Value ContractDeploy(const CBitcoinAddress& addressObject, string jscode, const double prioritet) +Value ContractDeploy(const CBitcoinAddress& oAddressObject, const string &sJsCode, const double dPrioritet) { return 0; } -Value ContractCall(bool readonly, const double& prioritet,const CBitcoinAddress& addressObject, const string& methodName, const Array& args) +Value ContractCall(bool bReadOnly, const double dPrioritet,const CBitcoinAddress& oAddressObject, const string& sMethodName, const Array& aArgs) { return 0; } -Value ContractAddress(const string& strHex) +Value ContractAddress(const string& sStrHex) { return 0; } -Value ContractInfo(const CBitcoinAddress& addressObject, bool calculateProperties, bool callReadonlyMethods) +Value ContractInfo(const CBitcoinAddress& oAddressObject, bool bCalculateProperties, bool bCallReadonlyMethods) { return 0; } -Value ContractCode(const CBitcoinAddress& address) +Value ContractCode(const CBitcoinAddress& oAddressObject) { return 0; } -Value ContractBalance(const CBitcoinAddress& address) +Value ContractBalance(const CBitcoinAddress& oAddressObject) { return 0; } -Value ContractStatus(const CBitcoinAddress& address) +Value ContractStatus(const CBitcoinAddress& oAddressObject) { return 0; } -Value ContractDeployEstimate(string jscode, const double& prioritet, uint64_t loopCount) +Value ContractDeployEstimate(const string &sJsCode, const double dPrioritet, uint64_t uiLoopCount) { return 0; } -Value ContractCallEstimate(const CBitcoinAddress& addressObject, const string& methodName, const double& prioritet, uint64_t loopCount) +Value ContractCallEstimate(const CBitcoinAddress& oAddressObject, const string& sMethodName, const double dPrioritet, uint64_t uiLoopCount) { return 0; } @@ -80,38 +80,38 @@ Value contractdeploy(const Array& params, bool fHelp) " ]\n" ); - Object deployInfo = params[0].get_obj(); - string address; - string jscode; - double prioritet = 1; + Object oDeployInfo = params[0].get_obj(); + string sAddress; + string sJsCode; + double dPrioritet = 1; - BOOST_FOREACH(const Pair& s, deployInfo) { + BOOST_FOREACH(const Pair& s, oDeployInfo) { if (s.name_ == "address") { - address = s.value_.get_str(); + sAddress = s.value_.get_str(); } else if (s.name_ == "jscode") { - jscode = s.value_.get_str(); + sJsCode = s.value_.get_str(); } else if (s.name_ == "prioritet") { - prioritet = s.value_.get_real(); + dPrioritet = s.value_.get_real(); } }; - if (jscode.empty()) { + if (sJsCode.empty()) { throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid JScode"); } - if (prioritet < 1) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong parametr prioritet"); + if (dPrioritet < 1) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong prioritet"); } - if (address.empty()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + if (sAddress.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address"); } - CBitcoinAddress addressObject(address); - if (!addressObject.IsValid()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + CBitcoinAddress oAddressObject(sAddress); + if (!oAddressObject.IsValid()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address"); } - return ContractDeploy(addressObject, jscode, prioritet); + return ContractDeploy(oAddressObject, sJsCode, dPrioritet); } Value contractcall(const Array& params, bool fHelp) @@ -135,48 +135,48 @@ Value contractcall(const Array& params, bool fHelp) "\nExamples:\n" + HelpExampleCli("contractcall", "") + HelpExampleRpc("contractcall", "")); - Object callInfo = params[0].get_obj(); - bool readonly; - double prioritet = 1; - string address; - string methodName; - Array args; + Object oCallInfo = params[0].get_obj(); + bool bReadOnly; + double dPrioritet = 1; + string sAddress; + string sMethodName; + Array aArgs; - BOOST_FOREACH(const Pair& c, callInfo) { + BOOST_FOREACH(const Pair& c, oCallInfo) { if (c.name_ == "readonly") { - readonly = c.value_.get_bool(); + bReadOnly = c.value_.get_bool(); } else if (c.name_ == "prioritet") { - prioritet = c.value_.get_real(); + dPrioritet = c.value_.get_real(); } else if (c.name_ == "address") { - address = c.value_.get_str(); + sAddress = c.value_.get_str(); } else if (c.name_ == "methodName") { - methodName = c.value_.get_str(); + sMethodName = c.value_.get_str(); } else if (c.name_ == "args") { - args = c.value_.get_array(); + aArgs = c.value_.get_array(); } }; - if (prioritet < 1) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong parametr prioritet"); + if (dPrioritet < 1) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong prioritet"); } - if (methodName.empty()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong methodName parametr"); + if (sMethodName.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong methodName parameter"); } - if (args.empty()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong args parametr"); + if (aArgs.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong args parameter"); } - if (address.empty()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + if (sAddress.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address"); } - CBitcoinAddress addressObject(address); - if (!addressObject.IsValid()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + CBitcoinAddress oAddressObject(sAddress); + if (!oAddressObject.IsValid()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address"); } - return ContractCall(readonly, prioritet, addressObject, methodName, args); + return ContractCall(bReadOnly, dPrioritet, oAddressObject, sMethodName, aArgs); } Value contractaddress(const Array& params, bool fHelp) @@ -192,20 +192,20 @@ Value contractaddress(const Array& params, bool fHelp) "\nExamples:\n" + HelpExampleCli("contractaddress", "") + HelpExampleRpc("contractaddress", "")); - Object addressInfo = params[0].get_obj(); - string strHex; + Object oAddressInfo = params[0].get_obj(); + string sStrHex; - BOOST_FOREACH(const Pair& d, addressInfo) { + BOOST_FOREACH(const Pair& d, oAddressInfo) { if (d.name_ == "txid") { - strHex = d.value_.get_str(); + sStrHex = d.value_.get_str(); } }; - if (strHex.size() != 64) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid txid transaction"); + if (sStrHex.size() != 64) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid txid"); } - return ContractAddress(strHex); + return ContractAddress(sStrHex); } Value contractinfo(const Array& params, bool fHelp) @@ -225,30 +225,30 @@ Value contractinfo(const Array& params, bool fHelp) "\nExamples:\n" + HelpExampleCli("contractinfo", "") + HelpExampleRpc("contractinfo", "")); - Object contInfo = params[0].get_obj(); - string address; - bool calculateProperties = false; - bool callReadonlyMethods = false; + Object oContInfo = params[0].get_obj(); + string sAddress; + bool bCalculateProperties = false; + bool bCallReadonlyMethods = false; - BOOST_FOREACH(const Pair& a, contInfo) { + BOOST_FOREACH(const Pair& a, oContInfo) { if (a.name_ == "address") { - address = a.value_.get_str(); + sAddress = a.value_.get_str(); } else if (a.name_ == "calculateProperties") { - calculateProperties = a.value_.get_bool(); + bCalculateProperties = a.value_.get_bool(); } else if (a.name_ == "callReadonlyMethods") { - callReadonlyMethods = a.value_.get_bool(); + bCallReadonlyMethods = a.value_.get_bool(); } }; - if (address.empty()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + if (sAddress.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address"); } - CBitcoinAddress addressObject(address); - if (!addressObject.IsValid()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + CBitcoinAddress oAddressObject(sAddress); + if (!oAddressObject.IsValid()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address"); } - return ContractInfo( addressObject, calculateProperties, callReadonlyMethods); + return ContractInfo( oAddressObject, bCalculateProperties, bCallReadonlyMethods); } Value contractcode(const Array& params, bool fHelp) @@ -264,24 +264,24 @@ Value contractcode(const Array& params, bool fHelp) "\nExamples:\n" + HelpExampleCli("contractcode", "") + HelpExampleRpc("contractcode", "")); - Object codeInfo = params[0].get_obj(); - string address; + Object oCodeInfo = params[0].get_obj(); + string sAddress; - BOOST_FOREACH(const Pair& cc, codeInfo) { + BOOST_FOREACH(const Pair& cc, oCodeInfo) { if (cc.name_ == "address") { - address = cc.value_.get_str(); + sAddress = cc.value_.get_str(); } }; - if (address.empty()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + if (sAddress.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address"); } - CBitcoinAddress addressObject(address); - if (!addressObject.IsValid()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + CBitcoinAddress oAddressObject(sAddress); + if (!oAddressObject.IsValid()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address"); } - return ContractCode(address); + return ContractCode(oAddressObject); } Value contractbalance(const Array& params, bool fHelp) @@ -297,24 +297,24 @@ Value contractbalance(const Array& params, bool fHelp) "\nExamples:\n" + HelpExampleCli("contractbalance", "") + HelpExampleRpc("contractbalance", "")); - Object balanceInfo = params[0].get_obj(); - string address; + Object oBalanceInfo = params[0].get_obj(); + string sAddress; - BOOST_FOREACH(const Pair& cb, balanceInfo) { + BOOST_FOREACH(const Pair& cb, oBalanceInfo) { if (cb.name_ == "address") { - address = cb.value_.get_str(); + sAddress = cb.value_.get_str(); } }; - if (address.empty()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + if (sAddress.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address"); } - CBitcoinAddress addressObject(address); - if (!addressObject.IsValid()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + CBitcoinAddress oAddressObject(sAddress); + if (!oAddressObject.IsValid()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address"); } - return ContractBalance(address); + return ContractBalance(oAddressObject); } Value contractstatus(const Array& params, bool fHelp) @@ -330,24 +330,24 @@ Value contractstatus(const Array& params, bool fHelp) "\nExamples:\n" + HelpExampleCli("contractstatus", "") + HelpExampleRpc("contractstatus", "")); - Object statusInfo = params[0].get_obj(); - string address; + Object oStatusInfo = params[0].get_obj(); + string sAddress; - BOOST_FOREACH(const Pair& g, statusInfo) { + BOOST_FOREACH(const Pair& g, oStatusInfo) { if (g.name_ == "address") { - address = g.value_.get_str(); + sAddress = g.value_.get_str(); } }; - if (address.empty()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + if (sAddress.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address"); } - CBitcoinAddress addressObject(address); - if (!addressObject.IsValid()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + CBitcoinAddress oAddressObject(sAddress); + if (!oAddressObject.IsValid()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address"); } - return ContractStatus(address); + return ContractStatus(oAddressObject); } Value contractdeployestimate(const Array& params, bool fHelp) @@ -367,34 +367,34 @@ Value contractdeployestimate(const Array& params, bool fHelp) "\nExamples:\n" + HelpExampleCli("contractdeployestimate", "") + HelpExampleRpc("contractdeployestimate", "")); - Object deployestimateInfo = params[0].get_obj(); - string jscode; - double prioritet = 1; - uint64_t loopCount =1; + Object oDeployEstimateInfo = params[0].get_obj(); + string sJsCode; + double dPrioritet = 1; + uint64_t uiLoopCount =1; - BOOST_FOREACH(const Pair& b, deployestimateInfo) { + BOOST_FOREACH(const Pair& b, oDeployEstimateInfo) { if (b.name_ == "jscode") { - jscode = b.value_.get_str(); + sJsCode = b.value_.get_str(); } else if (b.name_ == "prioritet") { - prioritet = b.value_.get_real(); + dPrioritet = b.value_.get_real(); } else if (b.name_ == "loopCount") { - loopCount = b.value_.get_uint64(); + uiLoopCount = b.value_.get_uint64(); } }; - if (jscode.empty()) { + if (sJsCode.empty()) { throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid JScode"); } - if (prioritet < 1) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong parametr prioritet"); + if (dPrioritet < 1) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong prioritet"); } - if (loopCount < 1) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong parametr loopCount"); + if (uiLoopCount < 1) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong parameter LoopCount"); } - return ContractDeployEstimate(jscode, prioritet, loopCount); + return ContractDeployEstimate(sJsCode, dPrioritet, uiLoopCount); } Value contractcallestimate(const Array& params, bool fHelp) @@ -415,45 +415,45 @@ Value contractcallestimate(const Array& params, bool fHelp) "\nExamples:\n" + HelpExampleCli("contractcallestimate", "") + HelpExampleRpc("contractcallestimate", "")); - Object callestimateInfo = params[0].get_obj(); - string address; - string methodName; - double prioritet = 1; - uint64_t loopCount =1; + Object oCallEstimateInfo = params[0].get_obj(); + string sAddress; + string sMethodName; + double dPrioritet = 1; + uint64_t uiLoopCount =1; - BOOST_FOREACH(const Pair& d, callestimateInfo) { + BOOST_FOREACH(const Pair& d, oCallEstimateInfo) { if (d.name_ == "address") { - address = d.value_.get_str(); + sAddress = d.value_.get_str(); } else if (d.name_ == "methodName") { - methodName = d.value_.get_str(); + sMethodName = d.value_.get_str(); } else if (d.name_ == "prioritet") { - prioritet = d.value_.get_real(); + dPrioritet = d.value_.get_real(); } else if (d.name_ == "loopCount") { - loopCount = d.value_.get_uint64(); + uiLoopCount = d.value_.get_uint64(); } }; - if (methodName.empty()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong methodName parametr"); + if (sMethodName.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong MethodName parameter"); } - if (prioritet < 1) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong parametr prioritet"); + if (dPrioritet < 1) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong prioritet"); } - if (loopCount < 1) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong parametr loopCount"); + if (uiLoopCount < 1) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Wrong parameter LoopCount"); } - if (address.empty()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + if (sAddress.empty()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address"); } - CBitcoinAddress addressObject(address); - if (!addressObject.IsValid()) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address transaction"); + CBitcoinAddress oAddressObject(sAddress); + if (!oAddressObject.IsValid()) { + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Invalid address"); } - return ContractCallEstimate(addressObject, methodName, prioritet, loopCount); + return ContractCallEstimate(oAddressObject, sMethodName, dPrioritet, uiLoopCount); } Value contractcount(const Array& params, bool fHelp)