Author

Topic: New RPC- Paramaters are not parsed correctly (Read 116 times)

brand new
Activity: 0
Merit: 0
We offer pressure transducers 0-10 bar  to 100 bar for all kinds of industries. Apart from pressure transducers, we supply temperature transmitters, ultrasonic and radar level sensors, flowmeters, and VFD panels for different applications.

https://www.controltechme.com/pressure-transducers/
newbie
Activity: 29
Merit: 6
Ignore my last message, the error occurred because my for loop, when I deleted it, the error disappeared.
Thank you for your kind help!
newbie
Activity: 29
Merit: 6
I never thought even looking there!
Now he notify me about another error:

Code:
error code: -1
error message:
JSON value is not a string as expected

Do I need to sign my strings somewhere??
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
It appears that the bitcoin-cli client is not performing any type conversion unless you specifically code it in this file and is passing encoding everything to the JSONRPC as string. Try adding your method in the vRPCConvertParams array along with the parameter number and name like so: {"mycustomrpc", 0, Param1"}, {"mycustomrpc", 3, Param4"}.

The file src/rpc/client.cpp contains a function that calls Univalue.read() on the string value to autodetect the type.
newbie
Activity: 29
Merit: 6
This is the updated code:

Code:
for (int i = 0; i < request.params.size(); i++) {
        std::cout << "param value: " << request.params[i].get_str() << " param type: " <<
            request.params[i].getType() << std::endl;
    }
    std::cout << "inside function" << std:: endl;
    const int64_t num_blocks{request.params[0].get_int64()};
    const uint64_t max_tries{request.params[3].isNull() ? DEFAULT_MAX_TRIES : request.params[3].get_int64()};

For me the getType() function redirects to UniValue class at:
https://github.com/bitcoin/bitcoin/blob/master/src/univalue/include/univalue.h#L64
Type 3 is VSTR according to the VType enum
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
So I inspected the source code and found this enumeration of types that corresponds to RPCArg types: https://github.com/bitcoin/bitcoin/blob/7fcf53f7b4524572d1d0c9a5fdc388e87eb02416/src/rpc/util.h#L119-L130

And "3" stands for "NUM", as they start counting from zero. That explains why your string parameters are not being parsed properly.

So to be clear, you said:

When I'm printing the parsed values at the beginning this the output I'm receiving:
Code:
param value: 1 param type: 3
param value: abc param type: 3
param value: abc param type: 3


Are you printing these values after the code block you posted? It seems so, because I don't see how get_int64() and get_str() would generate this exception. In that case, on which line does the debugger catches the error?
newbie
Activity: 29
Merit: 6
I'm not trying to pass a JSON at all.
This is the CLI call from the terminal:

Code:
./bitcoin-cli --datadir= mycustomrpc 1 abc abc

When I'm printing the parsed values at the beginning this the output I'm receiving:
Code:
param value: 1 param type: 3
param value: abc param type: 3
param value: abc param type: 3
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
Well that sounds like a JSON formatting problem. Have you verified that your client program is properly escaping double quotes and braces?
newbie
Activity: 29
Merit: 6
This is the beginning of the function, it fails in the parsing parameters

Code:
const int64_t num_blocks{request.params[0].get_int64()};
const uint64_t max_tries{request.params[3].isNull() ? DEFAULT_MAX_TRIES : request.params[3].get_int64()};
std::string str1 = request.params[2].get_str();
CTxDestination destination = DecodeDestination(request.params[1].get_str());
...
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
Well then, where is the rest of the source code for your custom RPC since that's where the execution is happening, and not in the RPCHelpMan?
newbie
Activity: 29
Merit: 6
I checked it in the debugger and it says it for the first parameter.
In addition when I'm changing the first parameter to string, I got another error for the third parameter:

Code:
error: Error parsing JSON: "abc"
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
Check this line:

Code:
"Param4", RPCArg::Type::NUM, /* default */ ToString(1000), "How many iterations to try."

The type of this parameter is NUM but its default value is a stringified version of the number 1000.
newbie
Activity: 29
Merit: 6
I wrote a new RPC and my parameters are not parsed correctly.
This is the definition of the RPCHelpMan:

Code:
return RPCHelpMan{"mycustomrpc",
                "\nchange definitions(before the RPC call returns)\n",
                {
                    {"Param1", RPCArg::Type::NUM, RPCArg::Optional::NO, ""},
                    {"Param2", RPCArg::Type::STR, RPCArg::Optional::NO, ""},
                    {"Param3", RPCArg::Type::STR, RPCArg::Optional::NO, ""},
                    {"Param4", RPCArg::Type::NUM, /* default */ ToString(1000), "How many iterations to try."}
                },
                RPCResult{
                    RPCResult::Type::ARR, "", "",
                    {
                        {RPCResult::Type::STR_HEX, "", "param"},
                    }},
                RPCExamples{
            "\nChange definitions to bitcoin core\n"
            + HelpExampleCli("mycustomrpc", "param1 \"param2\" \"param3\" ")
                },
        [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue

When I'm running this command from my CLI, I got this error:

Code:
error code: -1
error message:
JSON value is not an integer as expected

Can someone tell me what's wrong in the function definition?
Jump to: