Bitcoin Forum

Bitcoin => Project Development => Topic started by: windpath on July 09, 2015, 02:04:13 AM



Title: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: windpath on July 09, 2015, 02:04:13 AM
Originally planned on holding off on releasing this until all the API commands were integrated, but with the recent large increase in transaction volume, an Alpha release with what is ready seemed appropriate.

In particular estimatefee (http://chainquery.com/bitcoin-api/estimatefee) and getmempoolinfo (http://chainquery.com/bitcoin-api/getmempoolinfo) are now publicly available through your browser, along with 25 other API commands.

When all the Bitcoin Core 0.10.2 commands are complete the whole thing will be released on GitHub as open source.

So without further ado, http://ChainQuery.com/bitcoin-api

Currently supported commands:

  • decoderawtransaction (http://chainquery.com/bitcoin-api/decoderawtransaction)
  • decodescript (http://chainquery.com/bitcoin-api/decodescript)
  • estimatefee (http://chainquery.com/bitcoin-api/estimatefee)
  • estimatepriority (http://chainquery.com/bitcoin-api/estimatepriority)
  • getbalance (http://chainquery.com/bitcoin-api/getbalance)
  • getbestblockhash (http://chainquery.com/bitcoin-api/getbestblockhash)
  • getblock (http://chainquery.com/bitcoin-api/getblock)
  • getblockchaininfo (http://chainquery.com/bitcoin-api/getblockchaininfo)
  • getblockcount (http://chainquery.com/bitcoin-api/getblockcount)
  • getblockhash (http://chainquery.com/bitcoin-api/getblockhash)
  • getblocktemplate (http://chainquery.com/bitcoin-api/getblocktemplate)
  • getchaintips (http://chainquery.com/bitcoin-api/getchaintips)
  • getconnectioncount (http://chainquery.com/bitcoin-api/getconnectioncount)
  • getdifficulty (http://chainquery.com/bitcoin-api/getdifficulty)
  • getgenerate (http://chainquery.com/bitcoin-api/getgenerate)
  • gethashespersec (http://chainquery.com/bitcoin-api/gethashespersec)
  • getinfo (http://chainquery.com/bitcoin-api/getinfo)
  • getmempoolinfo (http://chainquery.com/bitcoin-api/getmempoolinfo)
  • getmininginfo (http://chainquery.com/bitcoin-api/getmininginfo)
  • getnettotals (http://chainquery.com/bitcoin-api/getnettotals)
  • getnetworkhashps (http://chainquery.com/bitcoin-api/getnetworkhashps)
  • getnetworkinfo (http://chainquery.com/bitcoin-api/getnetworkinfo)
  • getpeerinfo (http://chainquery.com/bitcoin-api/getpeerinfo)
  • getrawmempool (http://chainquery.com/bitcoin-api/getrawmempool)
  • getrawtransaction (http://chainquery.com/bitcoin-api/getrawtransaction)
  • help (http://chainquery.com/bitcoin-api/help)
  • validateaddress (http://chainquery.com/bitcoin-api/validateaddress)
  • verifymessage (http://chainquery.com/bitcoin-api/verifymessage)

Built for the average Joe to explore Bitcoin's core API and to serve as the foundation for PHP web applications to easily communicate with bitcoin core.

I hope you like it so far,  any questions or feedback are welcome and appreciated.


Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: achow101 on July 09, 2015, 02:12:32 AM
Seems good. I think you should have the outputs in a way to have everything broken down and apart instead of just returning the JSON object.

Also, maybe have each command in a drop down list and the user selects which command. Then the page has a description of the command and some text boxes to enter the parameters and such instead of having to enter the command as if it were the console. This would make it much more user friendly, especially to those who aren't familiar with using Bitcoin's console.

BTW, this belongs in project development.


Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: batesresearch on July 09, 2015, 10:49:21 AM
Wow, I like it. Could come in very useful for a service me and a friend are looking at starting in the future. Great work


Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: DarkHyudrA on July 09, 2015, 11:03:34 AM
I played around your site a bit, and it's pretty nice to test things since I don't have anymore the daemon on my PC.


Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: okae on July 09, 2015, 11:11:19 AM
ohh looks pretty cool and seems to work pretty faster, i just try your online version, but i will try to downlod it and try by myselft ( when you release it ofc ).

is a relly good job man, ty for release it, im waiting for the GitHub link ;)


Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: jonnybravo0311 on July 09, 2015, 03:19:43 PM
Nice job windpath!  I actually started my own Java project very similar to this... I wrote some code to do some data mining on empty blocks (see my thread here: https://bitcointalk.org/index.php?topic=1085800.0).  Mostly I wrote the code for fun, but realized that I could expand it to provide a nice object-oriented view into the core APIs.  That expansion has been started, but is nowhere near completed at this point, and I haven't put anything up on github yet.  I know there are a number of available libraries already out there (like BitcoinJ), but being who I am, I wanted to figure things out on my own :).

I'm looking forward to your progress with this project.


Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: windpath on July 09, 2015, 03:22:54 PM
Thanks folks!

Regarding adding more accurate descriptions, each command links to it's bitcoin.org documentation with the (?) icon, and where a command has available parameters a form is generated and shown with a description of the fields, for example: http://chainquery.com/bitcoin-api/getnetworkhashps

Once the raw JSON API is up I might break down the individual HTML result sets to make them more user friendly, the priority now is to get all the commands done and get it up on GitHub, this way maybe some others will join in and help :)



Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: windpath on July 09, 2015, 03:24:10 PM
Nice job windpath!  I actually started my own Java project very similar to this... I wrote some code to do some data mining on empty blocks (see my thread here: https://bitcointalk.org/index.php?topic=1085800.0).  Mostly I wrote the code for fun, but realized that I could expand it to provide a nice object-oriented view into the core APIs.  That expansion has been started, but is nowhere near completed at this point, and I haven't put anything up on github yet.  I know there are a number of available libraries already out there (like BitcoinJ), but being who I am, I wanted to figure things out on my own :).

I'm looking forward to your progress with this project.

Thanks JB!

Getting intimate with the API was certainly a motivation of mine as well :)

Edit: That's some great data you have there, did not expect the empty block count to be nearly that high, great work!


Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: jonnybravo0311 on July 09, 2015, 03:38:14 PM
I expected quite a large set of the initial blocks to be empty - after all, a tiny subset of people even knew what Bitcoin was.  However, the thing that really grates on me is how many empty blocks there are when there are most certainly transactions waiting to be included and confirmed.  For example, we've been having our fun little stress tests recently, yet AntPool has continued to mine empty blocks.  At one point I noticed nearly 20k transactions, but AntPool happily submitted a block with not a single one of them.  Oh well... separate debate for another thread :)


Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: unamis76 on July 09, 2015, 03:40:10 PM
New services are always welcome and yours seems a job pretty well done... But what could be the case uses for such a service? I think websites would probably need the wallet component of the Bitcoin Core client and not other API commands as much...


Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: jonnybravo0311 on July 09, 2015, 03:46:35 PM
New services are always welcome and yours seems a job pretty well done... But what could be the case uses for such a service? I think websites would probably need the wallet component of the Bitcoin Core client and not other API commands as much...
The use case would be to have a nicely packaged API library that you can just drop into your site without having to write it from scratch.  Why pay some developer to write the interactions with your wallet, when you can just grab an open source library that already does it? :)


Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: unamis76 on July 09, 2015, 03:50:36 PM
New services are always welcome and yours seems a job pretty well done... But what could be the case uses for such a service? I think websites would probably need the wallet component of the Bitcoin Core client and not other API commands as much...
Why pay some developer to write the interactions with your wallet, when you can just grab an open source library that already does it? :)

Yes... I guess that's right :)


Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: windpath on July 09, 2015, 03:52:58 PM
New services are always welcome and yours seems a job pretty well done... But what could be the case uses for such a service? I think websites would probably need the wallet component of the Bitcoin Core client and not other API commands as much...

Agreed, actually most of the wallet functions are done and when the test-net version is live you will be able to play with them on the site.

Also, this:
Built for the average Joe to explore Bitcoin's core API and to serve as the foundation for PHP web applications to easily communicate with bitcoin core.

The API does handle sanitizing and validating all inputs, but as far as running the wallet functions on main-net: securing the API is currently not in the scope of the project, and a developer would need to create their own login system and security rules to keep it locked down.



Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: windpath on July 10, 2015, 07:11:57 PM

Just added the verifymessage (http://chainquery.com/bitcoin-api/verifymessage) endpoint at http://chainquery.com/bitcoin-api/verifymessage

Up to this point all the other endpoints only accept HTTP GET variables, verifymessage is the first requiring POST, and will only accept POST because of the base64 signatures' special characters.

I also wrote up a quick tutorial on what I feel is an often overlooked and powerful feature built in to just about any bitcoin client worth it's salt, message signing and verification.

Check it out here: https://www.reddit.com/r/Bitcoin/comments/3ctrx1/bitcoin_is_wonderful_verifying_a_bitcoin_signed/


Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: shorena on August 09, 2015, 08:12:42 PM

Just added the verifymessage (http://chainquery.com/bitcoin-api/verifymessage) endpoint at http://chainquery.com/bitcoin-api/verifymessage

Up to this point all the other endpoints only accept HTTP GET variables, verifymessage is the first requiring POST, and will only accept POST because of the base64 signatures' special characters.

I also wrote up a quick tutorial on what I feel is an often overlooked and powerful feature built in to just about any bitcoin client worth it's salt, message signing and verification.

Check it out here: https://www.reddit.com/r/Bitcoin/comments/3ctrx1/bitcoin_is_wonderful_verifying_a_bitcoin_signed/


I just tried to add the verifymessage of your site to my guide[1]. Since brainwallet is no longer operational and coinig[2] seems to be bugged when trying to verify message that have a linebreak. However your site seems to be affected by the same bug. I tried to verify the following two messages that verify just fine with bitcoin core 0.11. The first however does not verify. I added the return message directly below the message used.

Code:
-----BEGIN BITCOIN SIGNED MESSAGE-----
a line followed by a linebreak
this is shorena from bitcointalk.org, today is 2015.08.09 and this is a test for chainquery.com
-----BEGIN SIGNATURE-----
18uTXyQubfaYrkbQDdaXhzd2ALEY5YN77B
IG5WyElz95PZmiW47KV12iQd5Xnu4SkrkxJTkdaaqa0vav4tdDCTg1kVyqJ58inkDMrdoDCLAkKi4cwTAhGZmQ0=
-----END BITCOIN SIGNED MESSAGE-----
Code:
{
"result": false,
"error": null,
"id": null
}

Code:
-----BEGIN BITCOIN SIGNED MESSAGE-----
this is shorena from bitcointalk.org, today is 2015.08.09 and this is a another test for chainquery.com
-----BEGIN SIGNATURE-----
18uTXyQubfaYrkbQDdaXhzd2ALEY5YN77B
ID1SO2KVw8Tv6XowUkrtdQRhuB+sQVyi7jb549ZfZzpMMJ+9rRGx4ZvYyVgXsGPJe6Ds/3B5yYR70jtpJfLJ/gg=
-----END BITCOIN SIGNED MESSAGE-----
Code:
{
"result": true,
"error": null,
"id": null
}

[1] https://bitcointalk.org/index.php?topic=990345.0
[2] https://bitcointalk.org/index.php?topic=990345.msg12097780#msg12097780


Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: windpath on August 09, 2015, 09:06:49 PM

Just added the verifymessage (http://chainquery.com/bitcoin-api/verifymessage) endpoint at http://chainquery.com/bitcoin-api/verifymessage

Up to this point all the other endpoints only accept HTTP GET variables, verifymessage is the first requiring POST, and will only accept POST because of the base64 signatures' special characters.

I also wrote up a quick tutorial on what I feel is an often overlooked and powerful feature built in to just about any bitcoin client worth it's salt, message signing and verification.

Check it out here: https://www.reddit.com/r/Bitcoin/comments/3ctrx1/bitcoin_is_wonderful_verifying_a_bitcoin_signed/


I just tried to add the verifymessage of your site to my guide[1]. Since brainwallet is no longer operational and coinig[2] seems to be bugged when trying to verify message that have a linebreak. However your site seems to be affected by the same bug. I tried to verify the following two messages that verify just fine with bitcoin core 0.11. The first however does not verify. I added the return message directly below the message used.

Code:
-----BEGIN BITCOIN SIGNED MESSAGE-----
a line followed by a linebreak
this is shorena from bitcointalk.org, today is 2015.08.09 and this is a test for chainquery.com
-----BEGIN SIGNATURE-----
18uTXyQubfaYrkbQDdaXhzd2ALEY5YN77B
IG5WyElz95PZmiW47KV12iQd5Xnu4SkrkxJTkdaaqa0vav4tdDCTg1kVyqJ58inkDMrdoDCLAkKi4cwTAhGZmQ0=
-----END BITCOIN SIGNED MESSAGE-----
Code:
{
"result": false,
"error": null,
"id": null
}

Code:
-----BEGIN BITCOIN SIGNED MESSAGE-----
this is shorena from bitcointalk.org, today is 2015.08.09 and this is a another test for chainquery.com
-----BEGIN SIGNATURE-----
18uTXyQubfaYrkbQDdaXhzd2ALEY5YN77B
ID1SO2KVw8Tv6XowUkrtdQRhuB+sQVyi7jb549ZfZzpMMJ+9rRGx4ZvYyVgXsGPJe6Ds/3B5yYR70jtpJfLJ/gg=
-----END BITCOIN SIGNED MESSAGE-----
Code:
{
"result": true,
"error": null,
"id": null
}

[1] https://bitcointalk.org/index.php?topic=990345.0
[2] https://bitcointalk.org/index.php?topic=990345.msg12097780#msg12097780

Interesting, I'll look into it on Monday, what OS are you running bitcoin core on? I'll have to dig into how core handles hard returns on various OS's and have the app mimic that.


Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: shorena on August 09, 2015, 09:26:31 PM
-snip-
Interesting, I'll look into it on Monday, what OS are you running bitcoin core on? I'll have to dig into how core handles hard returns on various OS's and have the app mimic that.

Thanks. Its Win7, but I can set it up on other systems if that helps you. Win 8.1 Pro and Ubuntu 14.04.2 would be the easiest as I already have VMs for those.



Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: windpath on August 09, 2015, 09:29:48 PM
-snip-
Interesting, I'll look into it on Monday, what OS are you running bitcoin core on? I'll have to dig into how core handles hard returns on various OS's and have the app mimic that.

Thanks. Its Win7, but I can set it up on other systems if that helps you. Win 8.1 Pro and Ubuntu 14.04.2 would be the easiest as I already have VMs for those.



It may just be how HTTP post handles hard returns, I'll post back tomorrow after I've have a chance to dig around a little.


Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: windpath on August 11, 2015, 12:49:55 AM
I just tried to add the verifymessage of your site to my guide[1]. Since brainwallet is no longer operational and coinig[2] seems to be bugged when trying to verify message that have a linebreak. However your site seems to be affected by the same bug. I tried to verify the following two messages that verify just fine with bitcoin core 0.11. The first however does not verify. I added the return message directly below the message used.
Code:
-----BEGIN BITCOIN SIGNED MESSAGE-----
a line followed by a linebreak
this is shorena from bitcointalk.org, today is 2015.08.09 and this is a test for chainquery.com
-----BEGIN SIGNATURE-----
18uTXyQubfaYrkbQDdaXhzd2ALEY5YN77B
IG5WyElz95PZmiW47KV12iQd5Xnu4SkrkxJTkdaaqa0vav4tdDCTg1kVyqJ58inkDMrdoDCLAkKi4cwTAhGZmQ0=
-----END BITCOIN SIGNED MESSAGE-----


Thanks again for the bug report, this was challenging as we want Chain Query to be platform independent when released (we are getting very close)...

That means that not only do we have to support various platforms and browsers submitting the form, but also various platforms that bitcoind may be run on to process it.

Typically this is not a huge deal, but as we are verifying a signed message, the message must match the signature exactly or the result will be false.

There is really no standardization around end of line characters:

Code:
\n is a linux/unix line break
\r is a classic mac line break [OS X uses the above unix \n]
\r\n is a windows line break

And that does not take into account how various browsers handle the post data.

Surprisingly in PHP we were able to put together a rather elegant and efficient solution for OS independent end of line characters (after lots of trial and error):

Pseudo code:
Code:
$newLineChars = array("\r\n","\r","\n");
$fixedMessage = str_replace($newLineChars, PHP_EOL, $message);

The array of various new line characters looks for any variation of the newline and replaces it with the PHP_EOL constant in the signed $message.

PHP_EOL is a constant holding the line break character(s) used by the platform the app and bitcoind are running on.

This has been tested with your signed message (including the line break) browsing from OSx with Firefox, Chrome and Safari both in my dev environment, OSx, and on the beta server, Ubuntu 14.04, both with Bitcoin core 0.11.0.

It should also work just fine on your windows machine (fingers crossed)...

Again, thanks for the report and for considering Chain Query for your tutorial.




Title: Re: Chain Query [Alpha] - A web based interface to the Bitcoin API JSON-RPC
Post by: shorena on August 11, 2015, 07:11:53 PM
I just tried to add the verifymessage of your site to my guide[1]. Since brainwallet is no longer operational and coinig[2] seems to be bugged when trying to verify message that have a linebreak. However your site seems to be affected by the same bug. I tried to verify the following two messages that verify just fine with bitcoin core 0.11. The first however does not verify. I added the return message directly below the message used.
Code:
-----BEGIN BITCOIN SIGNED MESSAGE-----
a line followed by a linebreak
this is shorena from bitcointalk.org, today is 2015.08.09 and this is a test for chainquery.com
-----BEGIN SIGNATURE-----
18uTXyQubfaYrkbQDdaXhzd2ALEY5YN77B
IG5WyElz95PZmiW47KV12iQd5Xnu4SkrkxJTkdaaqa0vav4tdDCTg1kVyqJ58inkDMrdoDCLAkKi4cwTAhGZmQ0=
-----END BITCOIN SIGNED MESSAGE-----


Thanks again for the bug report, this was challenging as we want Chain Query to be platform independent when released (we are getting very close)...

That means that not only do we have to support various platforms and browsers submitting the form, but also various platforms that bitcoind may be run on to process it.

Typically this is not a huge deal, but as we are verifying a signed message, the message must match the signature exactly or the result will be false.

There is really no standardization around end of line characters:

Code:
\n is a linux/unix line break
\r is a classic mac line break [OS X uses the above unix \n]
\r\n is a windows line break

And that does not take into account how various browsers handle the post data.

Surprisingly in PHP we were able to put together a rather elegant and efficient solution for OS independent end of line characters (after lots of trial and error):

Pseudo code:
Code:
$newLineChars = array("\r\n","\r","\n");
$fixedMessage = str_replace($newLineChars, PHP_EOL, $message);

The array of various new line characters looks for any variation of the newline and replaces it with the PHP_EOL constant in the signed $message.

PHP_EOL is a constant holding the line break character(s) used by the platform the app and bitcoind are running on.

This has been tested with your signed message (including the line break) browsing from OSx with Firefox, Chrome and Safari both in my dev environment, OSx, and on the beta server, Ubuntu 14.04, both with Bitcoin core 0.11.0.

It should also work just fine on your windows machine (fingers crossed)...

Again, thanks for the report and for considering Chain Query for your tutorial.

Thanks for the fast solution, messages verify just fine on Win7 and Win8.1. I will add the site over the next days.