YA crazy bitcoin project
This project is maintained by Rusty Russell
One big item on my todo list was JSON-RPC. This is what bitcoind uses, so it makes sense for pettycoin to do the same. You can see the bitcoin JSON API here.
Unfortunately, the bitcoin one is a bit of an organic mess. For example, JSON only has doubles, so they decided to represent amounts in bitcoin, not satoshi, leading to a source of problems. It also conflates the different tasks of bitcoind: it’s a wallet, as well as a way for wallets to interact with the bitcoin network.
So my API is quite different, and I wrote a specific tool “pettycoin-query” which interacts with the daemon via a UNIX domain socket (which has fewer worries that using RPC over SSL).
The jsmn library is just 200 lines of C, and minimally sufficient: it took me a while to realize that the jsmntok_t “size” member is the number of children in the array or object, each of which could contain multiple tokens!
So I wrote wrappers to handle the things I needed [EDIT: including more the next week, refs fixed]. You can see the results here, in particular:
There’s also a json_delve() which takes a guide string like “.somemember[6]” and returns NULL if ‘somemember’ doesn’t exist, or isn’t an array, or doesn’t have 7 elements. It’s much less C-ish than the other two.
Comments