liorko87 (OP)
Newbie
Offline
Activity: 29
Merit: 6
|
|
May 31, 2021, 08:22:32 AM Merited by NotATether (2) |
|
I wrote a new RPC and my parameters are not parsed correctly. This is the definition of the RPCHelpMan: 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: error code: -1 error message: JSON value is not an integer as expected
Can someone tell me what's wrong in the function definition?
|
|
|
|
|
|
|
|
|
The trust scores you see are subjective; they will change depending on who you have in your trust list.
|
|
|
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
|
|
|
NotATether
Legendary
Offline
Activity: 1596
Merit: 6728
bitcoincleanup.com / bitmixlist.org
|
|
May 31, 2021, 08:25:42 AM |
|
Check this line: "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.
|
. .BLACKJACK ♠ FUN. | | | ███▄██████ ██████████████▀ ████████████ █████████████████ ████████████████▄▄ ░█████████████▀░▀▀ ██████████████████ ░██████████████ █████████████████▄ ░██████████████▀ ████████████ ███████████████░██ ██████████ | | CRYPTO CASINO & SPORTS BETTING | | │ | | │ | ▄▄███████▄▄ ▄███████████████▄ ███████████████████ █████████████████████ ███████████████████████ █████████████████████████ █████████████████████████ █████████████████████████ ███████████████████████ █████████████████████ ███████████████████ ▀███████████████▀ ███████████████████ | | .
|
|
|
|
liorko87 (OP)
Newbie
Offline
Activity: 29
Merit: 6
|
|
May 31, 2021, 08:27:57 AM |
|
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: error: Error parsing JSON: "abc"
|
|
|
|
NotATether
Legendary
Offline
Activity: 1596
Merit: 6728
bitcoincleanup.com / bitmixlist.org
|
|
May 31, 2021, 08:30:20 AM |
|
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?
|
. .BLACKJACK ♠ FUN. | | | ███▄██████ ██████████████▀ ████████████ █████████████████ ████████████████▄▄ ░█████████████▀░▀▀ ██████████████████ ░██████████████ █████████████████▄ ░██████████████▀ ████████████ ███████████████░██ ██████████ | | CRYPTO CASINO & SPORTS BETTING | | │ | | │ | ▄▄███████▄▄ ▄███████████████▄ ███████████████████ █████████████████████ ███████████████████████ █████████████████████████ █████████████████████████ █████████████████████████ ███████████████████████ █████████████████████ ███████████████████ ▀███████████████▀ ███████████████████ | | .
|
|
|
|
liorko87 (OP)
Newbie
Offline
Activity: 29
Merit: 6
|
|
May 31, 2021, 08:33:01 AM |
|
This is the beginning of the function, it fails in the parsing parameters 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()); ...
|
|
|
|
NotATether
Legendary
Offline
Activity: 1596
Merit: 6728
bitcoincleanup.com / bitmixlist.org
|
|
May 31, 2021, 08:46:20 AM |
|
Well that sounds like a JSON formatting problem. Have you verified that your client program is properly escaping double quotes and braces?
|
. .BLACKJACK ♠ FUN. | | | ███▄██████ ██████████████▀ ████████████ █████████████████ ████████████████▄▄ ░█████████████▀░▀▀ ██████████████████ ░██████████████ █████████████████▄ ░██████████████▀ ████████████ ███████████████░██ ██████████ | | CRYPTO CASINO & SPORTS BETTING | | │ | | │ | ▄▄███████▄▄ ▄███████████████▄ ███████████████████ █████████████████████ ███████████████████████ █████████████████████████ █████████████████████████ █████████████████████████ ███████████████████████ █████████████████████ ███████████████████ ▀███████████████▀ ███████████████████ | | .
|
|
|
|
liorko87 (OP)
Newbie
Offline
Activity: 29
Merit: 6
|
|
May 31, 2021, 08:50:26 AM |
|
I'm not trying to pass a JSON at all. This is the CLI call from the terminal: ./bitcoin-cli --datadir=<path_to_my_datadir> mycustomrpc 1 abc abc
When I'm printing the parsed values at the beginning this the output I'm receiving: param value: 1 param type: 3 param value: abc param type: 3 param value: abc param type: 3
|
|
|
|
NotATether
Legendary
Offline
Activity: 1596
Merit: 6728
bitcoincleanup.com / bitmixlist.org
|
|
May 31, 2021, 09:47:19 AM |
|
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-L130And "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: 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?
|
. .BLACKJACK ♠ FUN. | | | ███▄██████ ██████████████▀ ████████████ █████████████████ ████████████████▄▄ ░█████████████▀░▀▀ ██████████████████ ░██████████████ █████████████████▄ ░██████████████▀ ████████████ ███████████████░██ ██████████ | | CRYPTO CASINO & SPORTS BETTING | | │ | | │ | ▄▄███████▄▄ ▄███████████████▄ ███████████████████ █████████████████████ ███████████████████████ █████████████████████████ █████████████████████████ █████████████████████████ ███████████████████████ █████████████████████ ███████████████████ ▀███████████████▀ ███████████████████ | | .
|
|
|
|
liorko87 (OP)
Newbie
Offline
Activity: 29
Merit: 6
|
|
May 31, 2021, 10:14:39 AM |
|
This is the updated 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#L64Type 3 is VSTR according to the VType enum
|
|
|
|
NotATether
Legendary
Offline
Activity: 1596
Merit: 6728
bitcoincleanup.com / bitmixlist.org
|
|
May 31, 2021, 11:06:27 AM |
|
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.
|
. .BLACKJACK ♠ FUN. | | | ███▄██████ ██████████████▀ ████████████ █████████████████ ████████████████▄▄ ░█████████████▀░▀▀ ██████████████████ ░██████████████ █████████████████▄ ░██████████████▀ ████████████ ███████████████░██ ██████████ | | CRYPTO CASINO & SPORTS BETTING | | │ | | │ | ▄▄███████▄▄ ▄███████████████▄ ███████████████████ █████████████████████ ███████████████████████ █████████████████████████ █████████████████████████ █████████████████████████ ███████████████████████ █████████████████████ ███████████████████ ▀███████████████▀ ███████████████████ | | .
|
|
|
|
liorko87 (OP)
Newbie
Offline
Activity: 29
Merit: 6
|
|
May 31, 2021, 11:22:53 AM |
|
I never thought even looking there! Now he notify me about another error: error code: -1 error message: JSON value is not a string as expected
Do I need to sign my strings somewhere??
|
|
|
|
liorko87 (OP)
Newbie
Offline
Activity: 29
Merit: 6
|
|
May 31, 2021, 11:50:37 AM |
|
Ignore my last message, the error occurred because my for loop, when I deleted it, the error disappeared. Thank you for your kind help!
|
|
|
|
|