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

Safe HaskellNone
LanguageHaskell98

Bitcoin.BlockChain.Parser

Description

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

Synopsis

Documentation

computeBlockHash :: BlockHeader -> Hash256 Source #

Computes the hash of a block

computeTxHash :: Tx RawScript RawScript -> Hash256 Source #

Computes the hash of a transaction

runGetMaybeB :: Get a -> ByteString -> Maybe a Source #

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

runGetMaybeL :: Get a -> ByteString -> Maybe a Source #

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

getHash160 :: Get Hash160 Source #

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...)

theMagicWordBE :: Word32 Source #

The magic word in big-endian

theMagicWordLE :: Word32 Source #

The magic word in little-endian

getMaybeWord32be :: Get (Maybe Word32) Source #

Returns Nothing if there are not enough bytes left

skipZeroBytes :: Get (Either Int Int) Source #

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

nextMagicBytes :: Get (Maybe (Word32, Word64)) Source #

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

saferGetChunk :: Get (Either Word32 (Maybe (Word64, ByteString))) Source #

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...

getVarString :: Get ByteString Source #

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 #

getBlock :: Get (Maybe (Word64, Int, Block (Tx RawScript RawScript))) 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

getBlockHeaderOnly :: Get (Maybe (Word64, BlockHeader)) Source #

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?)