| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Network.Haskoin.Block.Merkle
Contents
Synopsis
- data MerkleBlock = MerkleBlock {}
- type MerkleRoot = Hash256
- type FlagBits = [Bool]
- type PartialMerkleTree = [Hash256]
- buildMerkleRoot :: [TxHash] -> MerkleRoot
- merkleBlockTxs :: Network -> MerkleBlock -> Either String [TxHash]
- testMerkleRoot :: Network -> MerkleBlock -> Bool
- buildPartialMerkle :: [(TxHash, Bool)] -> (FlagBits, PartialMerkleTree)
- decodeMerkleFlags :: [Word8] -> FlagBits
- encodeMerkleFlags :: FlagBits -> [Word8]
- calcTreeHeight :: Int -> Int
- calcTreeWidth :: Int -> Int -> Int
- hash2 :: Hash256 -> Hash256 -> Hash256
- calcHash :: Int -> Int -> [TxHash] -> Hash256
- traverseAndBuild :: Int -> Int -> [(TxHash, Bool)] -> (FlagBits, PartialMerkleTree)
- traverseAndExtract :: Int -> Int -> Int -> FlagBits -> PartialMerkleTree -> Maybe (MerkleRoot, [TxHash], Int, Int)
- extractMatches :: Network -> FlagBits -> PartialMerkleTree -> Int -> Either String (MerkleRoot, [TxHash])
- splitIn :: Int -> [a] -> [[a]]
- boolsToWord8 :: [Bool] -> Word8
Documentation
data MerkleBlock Source #
Filtered block: a block with a partial Merkle tree that only includes the transactions that pass a bloom filter that was negotiated.
Constructors
| MerkleBlock | |
Fields
| |
Instances
| Eq MerkleBlock Source # | |
Defined in Network.Haskoin.Block.Merkle | |
| Show MerkleBlock Source # | |
Defined in Network.Haskoin.Block.Merkle Methods showsPrec :: Int -> MerkleBlock -> ShowS # show :: MerkleBlock -> String # showList :: [MerkleBlock] -> ShowS # | |
| Serialize MerkleBlock Source # | |
Defined in Network.Haskoin.Block.Merkle | |
| NFData MerkleBlock Source # | |
Defined in Network.Haskoin.Block.Merkle Methods rnf :: MerkleBlock -> () # | |
type MerkleRoot = Hash256 Source #
Hash of the block's Merkle root.
type FlagBits = [Bool] Source #
Bits that are used to rebuild partial merkle tree transaction hash list.
type PartialMerkleTree = [Hash256] Source #
Partial Merkle tree for a filtered block.
Arguments
| :: [TxHash] | transaction hashes (leaf nodes) |
| -> MerkleRoot | root of the Merkle tree |
Computes the root of a Merkle tree from a list of leaf node hashes.
merkleBlockTxs :: Network -> MerkleBlock -> Either String [TxHash] Source #
Get matching transactions from Merkle block.
testMerkleRoot :: Network -> MerkleBlock -> Bool Source #
Check if Merkle block root is valid against the block header.
Helper functions
Arguments
| :: [(TxHash, Bool)] | transaction hash and whether to include |
| -> (FlagBits, PartialMerkleTree) | flag bits and partial Merkle tree |
Build a partial Merkle tree. Provide a list of tuples with all transaction hashes in the block, and whether the transaction is to be included in the partial tree. Returns a flag bits structure and the computed partial Merkle tree.
Computes the height of a Merkle tree.
Arguments
| :: Int | number of transactions (leaf nodes) |
| -> Int | height at which we want to compute the width |
| -> Int | width of the Merkle tree |
Computes the width of a Merkle tree at a specific height. The transactions are at height 0.
Arguments
| :: Int | height of the node |
| -> Int | position of the node (0 for the leftmost node) |
| -> [TxHash] | transaction hashes (leaf nodes) |
| -> Hash256 | hash of the node at the specified position |
Computes the hash of a specific node in a Merkle tree.
traverseAndBuild :: Int -> Int -> [(TxHash, Bool)] -> (FlagBits, PartialMerkleTree) Source #
Helper function to build partial Merkle tree. Used by buildPartialMerkle
above.
traverseAndExtract :: Int -> Int -> Int -> FlagBits -> PartialMerkleTree -> Maybe (MerkleRoot, [TxHash], Int, Int) Source #
Helper function to extract transaction hashes from partial Merkle tree.
Arguments
| :: Network | |
| -> FlagBits | |
| -> PartialMerkleTree | |
| -> Int | number of transaction at height 0 (leaf nodes) |
| -> Either String (MerkleRoot, [TxHash]) | Merkle root and list of matching transaction hashes |
Extracts the matching hashes from a partial merkle tree. This will return
the list of transaction hashes that have been included (set to true) in
a call to buildPartialMerkle.
splitIn :: Int -> [a] -> [[a]] Source #
Helper function to split a list in chunks Int length. Last chunk may be
smaller.
boolsToWord8 :: [Bool] -> Word8 Source #
Pack up to eight bools in a byte.