Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: kamir.tamaatiii on January 06, 2015, 11:52:06 PM



Title: How do you download a specific block number ?
Post by: kamir.tamaatiii on January 06, 2015, 11:52:06 PM
I want to know if there is a way to download specific block numbers without download the whole blockchain.

Edit: I know that I can use bitcoin client with getblock "hash" function, but this require that the block with that "hash" to be in the hard drive, which I don't. So I'm looking for a similar function of getblock "hash" which doesn't require block to be in the hard drive, but instead it download it from some server or other peers.


Title: Re: How do you download a specific block number ?
Post by: hhanh00 on January 07, 2015, 04:50:34 AM
Yes, by their hashes using getdata in the raw protocol or getblock in the client.


Title: Re: How do you download a specific block number ?
Post by: Taras on January 07, 2015, 06:35:19 AM
You can download the details of a specific block in human-readable form from a block explorer, such as blockchain.info or blockr.io etc.


Title: Re: How do you download a specific block number ?
Post by: kamir.tamaatiii on January 07, 2015, 12:07:17 PM
Yes, by their hashes using getdata in the raw protocol or getblock in the client.


I tried getblock "hash", but it seems like I can only get block that I already have in my disk, I want to get this function working without downloading the whole blockchain. Is there any way to connect to some kind of server and use this method on this server ?

TL;DR, I want to compile my own bootstrap.dat file that contain only blocks from a specific block number for example only blocks between 130000 and 140000, all this without having the blockchain in my hard drive.


Title: Re: How do you download a specific block number ?
Post by: hhanh00 on January 07, 2015, 05:10:23 PM
I tried getblock "hash", but it seems like I can only get block that I already have in my disk, I want to get this function working without downloading the whole blockchain. Is there any way to connect to some kind of server and use this method on this server ?

TL;DR, I want to compile my own bootstrap.dat file that contain only blocks from a specific block number for example only blocks between 130000 and 140000, all this without having the blockchain in my hard drive.
Without a local copy your only option is to use getdata since I doubt that an online block explorer would let you download 10000 blocks.


Title: Re: How do you download a specific block number ?
Post by: kamir.tamaatiii on January 07, 2015, 05:15:56 PM
Without a local copy your only option is to use getdata since I doubt that an online block explorer would let you download 10000 blocks.


How do you access the raw protocol? I'm not familiar with this.


Title: Re: How do you download a specific block number ?
Post by: hhanh00 on January 07, 2015, 05:31:57 PM
I don't know any tool that does that out of the box - I think you will need to write it yourself. Sorry


Title: Re: How do you download a specific block number ?
Post by: jimmyscratchlab on January 07, 2015, 06:02:32 PM
Without a local copy your only option is to use getdata since I doubt that an online block explorer would let you download 10000 blocks.


How do you access the raw protocol? I'm not familiar with this.

Bitcore, A pure JavaScript Bitcoin library.

Code:
var bitcore = require('bitcore');
var Messages = bitcore.transport.Messages;
var Peer = bitcore.transport.Peer;
var Block = bitcore.Block;
var peer = new Peer('xxx.xxx.xxx.xxx');

peer.on('block',function(message){
console.log(message.block.toObject());
);

var v = [];
v.push({
type: 2,
hash: new Buffer(...)
});

var message = new Messages.GetData(v);
peer.sendMessage(message);


Title: Re: How do you download a specific block number ?
Post by: gmaxwell on January 07, 2015, 06:24:44 PM
There is no facility to directly do this in the Bitcoin protocol, nor is there ever likely to be. The Bitcoin network is not a free file server, nodes provide data to other nodes for facilitating the operation of the Bitcoin system-- and normal operation has no need for a lookup by height.

You should run your own node and then you can trivially query it over the json rpc (or rest in Bitcoin v0.10).