Bitcoin Forum
May 04, 2024, 12:01:36 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: JSON RPC named parameters?  (Read 1446 times)
Ayakashi (OP)
Newbie
*
Offline Offline

Activity: 43
Merit: 0


View Profile WWW
November 21, 2013, 10: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
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.
1714824096
Hero Member
*
Offline Offline

Posts: 1714824096

View Profile Personal Message (Offline)

Ignore
1714824096
Reply with quote  #2

1714824096
Report to moderator
1714824096
Hero Member
*
Offline Offline

Posts: 1714824096

View Profile Personal Message (Offline)

Ignore
1714824096
Reply with quote  #2

1714824096
Report to moderator
1714824096
Hero Member
*
Offline Offline

Posts: 1714824096

View Profile Personal Message (Offline)

Ignore
1714824096
Reply with quote  #2

1714824096
Report to moderator
wumpus
Hero Member
*****
qt
Offline Offline

Activity: 812
Merit: 1022

No Maps for These Territories


View Profile
November 22, 2013, 01:34:49 PM
 #2

The positional order is important, you cannot use named parameters.

Bitcoin Core developer [PGP] Warning: For most, coin loss is a larger risk than coin theft. A disk can die any time. Regularly back up your wallet through FileBackup Wallet to an external storage or the (encrypted!) cloud. Use a separate offline wallet for storing larger amounts.
Ayakashi (OP)
Newbie
*
Offline Offline

Activity: 43
Merit: 0


View Profile WWW
November 22, 2013, 06: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.
kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1024



View Profile
November 23, 2013, 01:30:19 AM
 #4

*

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
wumpus
Hero Member
*****
qt
Offline Offline

Activity: 812
Merit: 1022

No Maps for These Territories


View Profile
November 23, 2013, 10: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.


Bitcoin Core developer [PGP] Warning: For most, coin loss is a larger risk than coin theft. A disk can die any time. Regularly back up your wallet through FileBackup Wallet to an external storage or the (encrypted!) cloud. Use a separate offline wallet for storing larger amounts.
Ayakashi (OP)
Newbie
*
Offline Offline

Activity: 43
Merit: 0


View Profile WWW
November 23, 2013, 10:18:55 PM
 #6

Thanks John, that clears it up nicely.  Also appreciate the link to the right source page... very helpful.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!