RavenProject / Ravencoin

Ravencoin Core integration/staging tree
https://www.ravencoin.org
MIT License
1.08k stars 673 forks source link

sendfromaddress optional parameters error "JSON value is not a string as expected (code -1)" #1179

Open hnugz opened 2 years ago

hnugz commented 2 years ago

Describe the issue

The sendfromaddress RPC help displays multiple optional parameters along with the following examples:

Examples:

raven-cli sendfromaddress "1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd" "1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd" 0.1 raven-cli sendfromaddress "1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd" "1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd" 0.1 "donation" "seans outpost" raven-cli sendfromaddress "1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd" "1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd" 0.1 "" "" true

Example 1 without the optional "comment", "comment_to", and "subtractfeeamount" parameters executes successfully. Examples 2 and 3 with the optional parameters fail with the error, "JSON value is not a string as expected (code -1)".

Can you reliably reproduce the issue?

If so, please list the steps to reproduce below:

  1. Open the Debug window console in the RavenCore wallet
  2. Review the options listed by the "help sendfromaddress" command
  3. Copy the third example command and replace the 1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd addresses with valid ones
  4. Attempt to execute the command (with valid addresses substituted) and review the resulting error: sendfromaddress "1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd" "1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd" 0.1 "" "" true

Expected behaviour

The RPC command should execute as expected based upon the examples.

Actual behaviour

A JSON error is returned.

What version of Ravencoin are you using?

Raven Core version v4.3.2.1-25a2dbf41 (64-bit)

Any extra information that might be useful in the debugging process.

Looking at a similar command, sendtoaddress, the optional parameters work as expected. Comparing optional parameter entries for sendfromaddress and sendtoaddress in rpcwallet.cpp, sendfromaddress is checking params[3] for is not null but params[2] for not an empty string . Looking at sendtoaddress which works successfully, it checks the same params[2] both times. Should sendfromaddress also be comparing the same parameter and putting params[3] in the "comment" rather than params[2]?

From sendfromaddress:

    // Wallet comments
    CWalletTx wtx;
    if (!request.params[3].isNull() && !request.params[2].get_str().empty())
        wtx.mapValue["comment"] = request.params[2].get_str();
    if (!request.params[4].isNull() && !request.params[3].get_str().empty())
        wtx.mapValue["to"]      = request.params[3].get_str();

From sendtoaddress:

    // Wallet comments
    CWalletTx wtx;
    if (!request.params[2].isNull() && !request.params[2].get_str().empty())
        wtx.mapValue["comment"] = request.params[2].get_str();
    if (!request.params[3].isNull() && !request.params[3].get_str().empty())
        wtx.mapValue["to"]      = request.params[3].get_str();
michaelmcshinsky commented 1 year ago

Created a PR to fix this: https://github.com/RavenProject/Ravencoin/pull/1223