Bitcoin Forum
November 20, 2017, 11:13:34 PM *
News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: JSON RPC named parameters?  (Read 1345 times)
Ayakashi
Jr. Member
*
Offline Offline

Activity: 43


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

Coinxchange Philippines: http://www.coinxchange.ph
1511219614
Hero Member
*
Offline Offline

Posts: 1511219614

View Profile Personal Message (Offline)

Ignore
1511219614
Reply with quote  #2

1511219614
Report to moderator
1511219614
Hero Member
*
Offline Offline

Posts: 1511219614

View Profile Personal Message (Offline)

Ignore
1511219614
Reply with quote  #2

1511219614
Report to moderator
Join ICO Now A blockchain platform for effective freelancing
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1511219614
Hero Member
*
Offline Offline

Posts: 1511219614

View Profile Personal Message (Offline)

Ignore
1511219614
Reply with quote  #2

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

Activity: 812

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
Jr. Member
*
Offline Offline

Activity: 43


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.

Coinxchange Philippines: http://www.coinxchange.ph
kjj
Legendary
*
Offline Offline

Activity: 1302



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

*

p2pcoin: a USB/CD/PXE p2pool miner - 1N8ZXx2cuMzqBYSK72X4DAy1UdDbZQNPLf - todo
I routinely ignore posters with paid advertising in their sigs.  You should too.
wumpus
Hero Member
*****
qt
Offline Offline

Activity: 812

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
Jr. Member
*
Offline Offline

Activity: 43


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.

Coinxchange Philippines: http://www.coinxchange.ph
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!