Safe Haskell | None |
---|---|
Language | Haskell98 |
Parsing the blockchain (as stored by bitcoind in the blkNNNNN.dat
files)
- computeBlockHash :: BlockHeader -> Hash256
- computeTxHash :: Tx RawScript RawScript -> Hash256
- serializeTx :: Tx RawScript RawScript -> RawTx
- runGetMaybeB :: Get a -> ByteString -> Maybe a
- runGetMaybeL :: Get a -> ByteString -> Maybe a
- getHash160 :: Get Hash160
- getHash256 :: Get Hash256
- putHash160 :: Hash160 -> Put
- putHash256 :: Hash256 -> Put
- getUnixTimeStamp :: Get UnixTimeStamp
- putUnixTimeStamp :: UnixTimeStamp -> Put
- getBlockHeader :: Get BlockHeader
- putBlockHeader :: BlockHeader -> Put
- theMagicWordBE :: Word32
- theMagicWordLE :: Word32
- getMaybeWord32be :: Get (Maybe Word32)
- skipZeroBytes :: Get (Either Int Int)
- nextMagicBytes :: Get (Maybe (Word32, Word64))
- isValidMagic :: Word32 -> Bool
- unsafeGetChunk :: Get (Maybe (Word64, ByteString))
- saferGetChunk :: Get (Either Word32 (Maybe (Word64, ByteString)))
- getVarInt :: Get Word64
- putVarInt :: Word64 -> Put
- getVarString :: Get ByteString
- putVarString :: ByteString -> Put
- getMany :: Get (Maybe a) -> Get [a]
- forceList :: [a] -> [a]
- getTx_ :: Get (Tx RawScript RawScript)
- getTx :: Get (Tx RawScript RawScript, RawTx)
- getTxInput :: Get (TxInput RawScript)
- getTxOutput :: Get (TxOutput RawScript)
- putTx :: Tx RawScript RawScript -> Put
- putTxInput :: TxInput RawScript -> Put
- putTxOutput :: TxOutput RawScript -> Put
- warn :: String -> a -> a
- getBlock :: Get (Maybe (Word64, Int, Block (Tx RawScript RawScript)))
- getBlocks :: Get [(Word64, Block (Tx RawScript RawScript))]
- parseBlockHeader :: ByteString -> BlockHeader
- getBlockHeaderOnly :: Get (Maybe (Word64, BlockHeader))
- getBlockHeadersOnly :: Get [(Word64, BlockHeader)]
Documentation
computeBlockHash :: BlockHeader -> Hash256 Source #
Computes the hash of a block
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...)
getHash256 :: Get Hash256 Source #
putHash160 :: Hash160 -> Put Source #
putHash256 :: Hash256 -> Put Source #
putUnixTimeStamp :: UnixTimeStamp -> Put Source #
putBlockHeader :: BlockHeader -> Put Source #
theMagicWordBE :: Word32 Source #
The magic word in big-endian
theMagicWordLE :: Word32 Source #
The magic word in little-endian
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.
isValidMagic :: Word32 -> Bool Source #
unsafeGetChunk :: Get (Maybe (Word64, ByteString)) Source #
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
putVarString :: ByteString -> Put 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?)
getBlockHeadersOnly :: Get [(Word64, BlockHeader)] Source #