Author

Topic: JSON RPC named parameters? (Read 1469 times)

newbie
Activity: 43
Merit: 0
November 23, 2013, 05:18:55 PM
#6
Thanks John, that clears it up nicely.  Also appreciate the link to the right source page... very helpful.
hero member
Activity: 812
Merit: 1022
No Maps for These Territories
November 23, 2013, 05:31:42 AM
#5
Suppose I want to get the balance for all accounts in a wallet.  This request works as expected, returning the combined balance from all accounts with a confirmation count of more than 1 (the default):

{"jsonrpc":"2.0","id":"1","method":"getbalance","params":[]}

But, suppose I wanted to get a combined balance for the wallet for all accounts with a confirmation count of more than 2?
Optional arguments can only be left out at the end. This is similar to the C++ convention.

You need to provide the default value for former arguments if you want to change latter arguments from their default.
(sometimes this is "", sometimes "*", sometimes null, this depends on the specific command)

But it's not very consistent.

For example in the case of getbalance, the zero-argument case takes a shortcut that calls pwalletMain->GetBalance() directly, which doesn't take a minimum amount of confirmations.

https://github.com/bitcoin/bitcoin/blob/master/src/rpcwallet.cpp#L705

You can however provide "*" as account name, which will do a GetBalance-like computation over all acccounts.

kjj
legendary
Activity: 1302
Merit: 1026
November 22, 2013, 08:30:19 PM
#4
*
newbie
Activity: 43
Merit: 0
November 22, 2013, 01:24:51 PM
#3
Thanks John.

This introduces some questions when optional parameters are not supplied.  I'm sure I'm not fully grasping yet how to deal with these and I'd appreciate any feedback.

Consider the following example:

Suppose I want to get the balance for all accounts in a wallet.  This request works as expected, returning the combined balance from all accounts with a confirmation count of more than 1 (the default):

{"jsonrpc":"2.0","id":"1","method":"getbalance","params":[]}

But, suppose I wanted to get a combined balance for the wallet for all accounts with a confirmation count of more than 2?

{"jsonrpc":"2.0","id":"1","method":"getbalance","params":[null, 2]} - this fails
{"jsonrpc":"2.0","id":"1","method":"getbalance","params":[,2]} - this fails
{"jsonrpc":"2.0","id":"1","method":"getbalance","params":[2]} - this fails
{"jsonrpc":"2.0","id":"1","method":"getbalance","params":["", 2]} - this succeeds, but it doesn't deliver what we want, because it's really returning the default "" account and not a combined total for all accounts.

I can't figure out any other combinations to supply.  Any pointers appreciated.
hero member
Activity: 812
Merit: 1022
No Maps for These Territories
November 22, 2013, 08:34:49 AM
#2
The positional order is important, you cannot use named parameters.
newbie
Activity: 43
Merit: 0
November 21, 2013, 05:09:35 PM
#1
I'm doing some work building yet another language-specific wrapper for BitcoinD's JSON-RPC requests.  I'm working from the wiki documentation at https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list.

I'm trying to understand the proper and best way to provide both required and optional parameters.

For example, this request body is valid and produces the response that I expect:
{"jsonrpc":"2.0","id":"1","method":"gettransaction","params":["315a1e40465591c5cbbbeab3318c57fb1b2cfa21e9f8ad297dcf1bc58d560dcd"]}

However, the parameter in this case is not named.  In this specific method, it's not such of a big deal since there is only one required parameter. But if you look at some of the more complex calls that have multiple parameters such as listreceivedbyaccount or move, sendmany, etc. it would seem that naming parameters would be more important.

By naming parameters, I'm talking about supplying both the parameter name and it's value to the server. 

Something like this, although this *does not work* (so don't use it):
{"jsonrpc":"2.0","id":"1","method":"gettransaction","params":[{"txid":"315a1e40465591c5cbbbeab3318c57fb1b2cfa21e9f8ad297dcf1bc58d560dcd"}]}

Have I just got the expected format wrong?  Is there any way to provide the specific parameter name and value to the server to be very specific? Or is it just positional order that is important?

thanks
Jump to: