Bitcoin Forum
May 17, 2024, 05:00:44 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: bitcoind: Your decentralized block explorer (HTTP REST API)  (Read 4690 times)
jgarzik (OP)
Legendary
*
qt
Offline Offline

Activity: 1596
Merit: 1091


View Profile
July 22, 2013, 07:48:45 PM
Last edit: July 23, 2013, 02:55:41 PM by jgarzik
 #1

URL: https://github.com/bitcoin/bitcoin/pull/2844

Adding an HTTP REST API for bitcoind has been occasionally tossed about as a useful thing.  Such an API would essentially provide a decentralized block explorer capability, enabling easy external access to transaction/address/block indices that we maintain.

The first two implemented API calls are simple, returning a block or TX given a simple query string based on block hash, e.g.

Code:
     GET /rest/tx/TX-HASH
Code:
     GET /rest/block/BLOCK-HASH

This can be easily accessed via command line cURL/wget utilities. Output formats -- binary, hex or json -- may be selected by append a "/json" or "/hex" suffix to the URL, e.g.
Code:
     GET /rest/tx/TX-HASH/json

The general goal of the HTTP REST interface is to access unauthenticated, public blockchain information.  There is no plan to add wallet interfacing/manipulation via this API.

Jeff Garzik, Bloq CEO, former bitcoin core dev team; opinions are my own.
Visit bloq.com / metronome.io
Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
NielDLR
Member
**
Offline Offline

Activity: 95
Merit: 10



View Profile WWW
July 23, 2013, 02:38:07 AM
 #2

Great idea. So, how would you access this?

I went through the source code, but couldn't find it?

Would it work on the port exposed by the JSON-RPC interface set in the bitcoin.conf? So for example: localhost:8332/rest/tx/TX-HASH?

Would you have to set tx-index=1 to get transactions with all spent outputs? The same way the getrawtransaction works at the moment?

Great idea. I started building a Bitcoin-Node-API that exposes the commands in a similar way.

The Cypherfunks - A decentralized band and cryptocurrency. The first cryptocollective.
jgarzik (OP)
Legendary
*
qt
Offline Offline

Activity: 1596
Merit: 1091


View Profile
July 23, 2013, 04:47:22 AM
 #3

Would it work on the port exposed by the JSON-RPC interface set in the bitcoin.conf? So for example: localhost:8332/rest/tx/TX-HASH?

Yes.

Quote
Would you have to set tx-index=1 to get transactions with all spent outputs? The same way the getrawtransaction works at the moment?

Yes.


Jeff Garzik, Bloq CEO, former bitcoin core dev team; opinions are my own.
Visit bloq.com / metronome.io
Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
d'aniel
Sr. Member
****
Offline Offline

Activity: 461
Merit: 251


View Profile
July 23, 2013, 07:09:09 AM
 #4

Are there plans for a call that returns a tx's merkle branch?
jgarzik (OP)
Legendary
*
qt
Offline Offline

Activity: 1596
Merit: 1091


View Profile
July 23, 2013, 02:00:47 PM
 #5

Are there plans for a call that returns a tx's merkle branch?

What is the use case?  That data falls into the category of "public blockchain data", so it is OK to add that sort of data, if there is a use.

Note that the JSON format of a TX outputs its confirmed block-hash, which enables discovery of a TX's merkle branch.


Jeff Garzik, Bloq CEO, former bitcoin core dev team; opinions are my own.
Visit bloq.com / metronome.io
Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
jgarzik (OP)
Legendary
*
qt
Offline Offline

Activity: 1596
Merit: 1091


View Profile
July 23, 2013, 02:56:10 PM
 #6

Updated OP and pull request to remove non-standard "Bitcoin-Format" header, and instead use github-style "clean" URLs.

Jeff Garzik, Bloq CEO, former bitcoin core dev team; opinions are my own.
Visit bloq.com / metronome.io
Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
d'aniel
Sr. Member
****
Offline Offline

Activity: 461
Merit: 251


View Profile
July 23, 2013, 05:08:45 PM
 #7

Are there plans for a call that returns a tx's merkle branch?

What is the use case?  That data falls into the category of "public blockchain data", so it is OK to add that sort of data, if there is a use.

Note that the JSON format of a TX outputs its confirmed block-hash, which enables discovery of a TX's merkle branch.


No particular use case in mind at the moment; being able to easily prove a given tx was included in a block just feels generally useful to me, and a more targeted call than one that returns the full block is more efficient for both parties.
Peter Todd
Legendary
*
expert
Offline Offline

Activity: 1120
Merit: 1150


View Profile
July 23, 2013, 06:38:53 PM
 #8

Are there plans for a call that returns a tx's merkle branch?
No particular use case in mind at the moment; being able to easily prove a given tx was included in a block just feels generally useful to me, and a more targeted call than one that returns the full block is more efficient for both parties.

You may find this code interesting, specifically find_digest_in_block(): https://github.com/opentimestamps/opentimestamps-server/blob/master/otsserver/bitcoin.py#L93

Basically it first finds a specific digest in a block, checking every tx, and then rebuilds the merkle tree to extract a merkle path from that transaction to the block header.

jgarzik (OP)
Legendary
*
qt
Offline Offline

Activity: 1596
Merit: 1091


View Profile
July 28, 2013, 03:39:43 PM
 #9

The suggestion on github to permit selection of output format by file extension is interesting.  e.g.

GET /rest/tx/TX-HASH.json (JSON-format expanded tx)

GET /rest/tx/TX-HASH.txt (binary serialized tx, hex encoding)

etc.


Jeff Garzik, Bloq CEO, former bitcoin core dev team; opinions are my own.
Visit bloq.com / metronome.io
Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
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!