MCPcopy Create free account
hub / github.com/LUX-Core/lux / callcontract

Function callcontract

src/rpcwallet.cpp:2842–2903  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////// // lux

Source from the content-addressed store, hash-verified

2840
2841////////////////////////////////////////////////////////////////////// // lux
2842UniValue callcontract(const UniValue& params, bool fHelp)
2843{
2844 if (fHelp || params.size() < 2)
2845 throw runtime_error(
2846 "callcontract \"address\" \"data\" ( address )\n"
2847 "\nArgument:\n"
2848 "1. \"address\" (string, required) The account address\n"
2849 "2. \"data\" (string, required) The data hex string\n"
2850 "3. address (string, optional) The sender address hex string\n"
2851 "4. gasLimit (string, optional) The gas limit for executing the contract\n"
2852 );
2853
2854 if (chainActive.Height() < Params().FirstSCBlock()) {
2855 throw JSONRPCError(RPC_VERIFY_ERROR, "Smart contracts hardfork is not active yet. Activation block number - " + std::to_string(Params().FirstSCBlock()));
2856 }
2857
2858 LOCK(cs_main);
2859
2860 std::string strAddr = params[0].get_str();
2861 std::string data = params[1].get_str();
2862
2863 if(data.size() % 2 != 0 || !regex_match(data, hexData))
2864 throw JSONRPCError(RPC_TYPE_ERROR, "Invalid data (data not hex)");
2865
2866 if(strAddr.size() != 40 || !regex_match(strAddr, hexData))
2867 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Incorrect address");
2868
2869 dev::Address addrAccount(strAddr);
2870 if(!globalState->addressInUse(addrAccount))
2871 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Address does not exist");
2872
2873 dev::Address senderAddress;
2874 if(params.size() == 3){
2875 CTxDestination luxSenderAddress = DecodeDestination(params[2].get_str());
2876 if(IsValidDestination(luxSenderAddress)) {
2877 CKeyID *keyid = boost::get<CKeyID>(&luxSenderAddress);
2878
2879 senderAddress = dev::Address(HexStr(valtype(keyid->begin(),keyid->end())));
2880 }else{
2881 senderAddress = dev::Address(params[2].get_str());
2882 }
2883
2884 }
2885 uint64_t gasLimit=0;
2886 if(params.size() == 4){
2887 gasLimit = params[3].get_int();
2888 }
2889
2890
2891 std::vector<ResultExecute> execResults = CallContract(addrAccount, ParseHex(data), senderAddress, gasLimit);
2892
2893 if(fRecordLogOpcodes){
2894 writeVMlog(execResults);
2895 }
2896
2897 UniValue result(UniValue::VOBJ);
2898 result.push_back(Pair("address", strAddr));
2899 result.push_back(Pair("executionResult", executionResultToJSON(execResults[0].execRes)));

Callers

nothing calls this directly

Calls 15

JSONRPCErrorFunction · 0.85
DecodeDestinationFunction · 0.85
IsValidDestinationFunction · 0.85
HexStrFunction · 0.85
CallContractFunction · 0.85
ParseHexFunction · 0.85
writeVMlogFunction · 0.85
PairFunction · 0.85
executionResultToJSONFunction · 0.85
transactionReceiptToJSONFunction · 0.85
HeightMethod · 0.80
FirstSCBlockMethod · 0.80

Tested by

no test coverage detected