bitcoin-hs-0.0.1: Partial implementation of the Bitcoin protocol (as of 2013)

Bitcoin.BlockChain.Parser

Description

Parsing the blockchain (as stored by bitcoind in the blkNNNNN.dat files)

Synopsis

Documentation

Computes the hash of a block

Computes the hash of a transaction

Returns (Just x) if the input could be parsed in full. Input is a strict ByteString

Returns (Just x) if the input could be parsed in full. Input is a lazy ByteString

Note: We copy the bytestring so that the stream can be garbage collected later ("fromByteString" copies from the ByteString to the ForeignPtr - actually I think two copies...)

The magic word in big-endian

The magic word in little-endian

Returns Nothing if there are not enough bytes left

returns the number of zero bytes which were skipped (Left if the input ends)

returns the next found "magic bytes" (which may be invalid) and their position, unless the file ends.

Unfortunately, it can happen in practice that the chunk length is completely wrong... (or maybe simply the blockchain data is corrupted?)

In that case we have to parse the block to find the correct size (because the next block will start within this block...)

But normally we don't want to always parse the block when it is unnecessary...

Note: we copy the bytestring so that the stream can be garbage collected later

getMany :: Get (Maybe a) -> Get [a] Source #

Parses a lot of something, until the input ends

forceList :: [a] -> [a] Source #

warn :: String -> a -> a Source #

Returns the position, the block size (which usually equals the chunk size, but not always unfortunately, which complicates the parsing considerably... though now it seems its simply corruption of the block data) and the block itself

This parses the next block header, and checks the magic bytes after the chunk.

In the case they are invalid, we also parse the full block, and consume the block, not the chunk, since the chunk size can be invalid in same cases... (though not it seems that instead simply the blockchain data was really corrupted, but how can bitcoind survive that?)