Safe Haskell | None |
---|---|
Language | Haskell98 |
- data BlockChainAction
- = BestChain {
- actionNodes :: ![NodeBlock]
- | ChainReorg {
- actionSplitNode :: !NodeBlock
- actionOldNodes :: ![NodeBlock]
- actionNodes :: ![NodeBlock]
- | SideChain {
- actionNodes :: ![NodeBlock]
- | KnownChain {
- actionNodes :: ![NodeBlock]
- = BestChain {
- type BlockHeight = Word32
- data NodeBlock
- type Timestamp = Word32
- initHeaderTree :: MonadIO m => SqlPersistT m ()
- migrateHeaderTree :: Migration
- getBestBlock :: MonadIO m => SqlPersistT m NodeBlock
- getHeads :: MonadIO m => SqlPersistT m [NodeBlock]
- getBlockByHash :: MonadIO m => BlockHash -> SqlPersistT m (Maybe NodeBlock)
- getParentBlock :: MonadIO m => NodeBlock -> SqlPersistT m (Maybe NodeBlock)
- getBlockWindow :: MonadIO m => NodeBlock -> NodeBlock -> Word32 -> SqlPersistT m BlockChainAction
- getBlockAfterTime :: MonadIO m => Timestamp -> SqlPersistT m (Maybe NodeBlock)
- getChildBlocks :: MonadIO m => BlockHash -> SqlPersistT m [NodeBlock]
- getBlockByHeight :: MonadIO m => NodeBlock -> BlockHeight -> SqlPersistT m (Maybe NodeBlock)
- getBlocksByHeight :: MonadIO m => NodeBlock -> [BlockHeight] -> SqlPersistT m [NodeBlock]
- getBlocksFromHeight :: MonadIO m => NodeBlock -> Word32 -> BlockHeight -> SqlPersistT m [NodeBlock]
- getBlocksAtHeight :: MonadIO m => BlockHeight -> SqlPersistT m [NodeBlock]
- putBlock :: MonadIO m => NodeBlock -> SqlPersistT m ()
- putBlocks :: MonadIO m => [NodeBlock] -> SqlPersistT m ()
- genesisBlock :: NodeBlock
- splitBlock :: MonadIO m => NodeBlock -> NodeBlock -> SqlPersistT m NodeBlock
- splitChains :: MonadIO m => (NodeBlock, Word32) -> (NodeBlock, Word32) -> SqlPersistT m (NodeBlock, [NodeBlock], [NodeBlock])
- nodeBlock :: NodeBlock -> Word32 -> BlockHeader -> NodeBlock
- nodeBlockHeight :: NodeBlock -> BlockHeight
- nodeHash :: NodeBlock -> BlockHash
- nodeHeader :: NodeBlock -> BlockHeader
- nodePrev :: NodeBlock -> BlockHash
- nodeTimestamp :: NodeBlock -> Timestamp
- nodeWork :: NodeBlock -> Work
- nodeHeight :: NodeBlock -> BlockHeight
- nodeChain :: NodeBlock -> Word32
- isBestChain :: BlockChainAction -> Bool
- isChainReorg :: BlockChainAction -> Bool
- isSideChain :: BlockChainAction -> Bool
- isKnownChain :: BlockChainAction -> Bool
- connectHeader :: MonadIO m => NodeBlock -> BlockHeader -> Timestamp -> SqlPersistT m (Either String BlockChainAction)
- connectHeaders :: MonadIO m => NodeBlock -> [BlockHeader] -> Timestamp -> SqlPersistT m (Either String BlockChainAction)
- blockLocator :: MonadIO m => NodeBlock -> SqlPersistT m BlockLocator
- pruneChain :: MonadIO m => NodeBlock -> SqlPersistT m NodeBlock
Documentation
data BlockChainAction Source #
BestChain | |
| |
ChainReorg | |
| |
SideChain | |
| |
KnownChain | |
|
type BlockHeight = Word32 Source #
initHeaderTree :: MonadIO m => SqlPersistT m () Source #
Initialize the block header chain by inserting the genesis block if it doesn't already exist.
getBestBlock :: MonadIO m => SqlPersistT m NodeBlock Source #
getBlockByHash :: MonadIO m => BlockHash -> SqlPersistT m (Maybe NodeBlock) Source #
getParentBlock :: MonadIO m => NodeBlock -> SqlPersistT m (Maybe NodeBlock) Source #
Finds the parent of a block.
:: MonadIO m | |
=> NodeBlock | Best block |
-> NodeBlock | Start of window |
-> Word32 | Window count |
-> SqlPersistT m BlockChainAction |
Return blockchain action to connect given block with best block. Count will limit the amount of blocks building up from split point towards the best block.
getBlockAfterTime :: MonadIO m => Timestamp -> SqlPersistT m (Maybe NodeBlock) Source #
Get node immediately at or after timestamp in main chain.
getChildBlocks :: MonadIO m => BlockHash -> SqlPersistT m [NodeBlock] Source #
Get all children for a block
:: MonadIO m | |
=> NodeBlock | Best block |
-> BlockHeight | |
-> SqlPersistT m (Maybe NodeBlock) |
Get ancestor of specified block at given height.
:: MonadIO m | |
=> NodeBlock | Best block |
-> [BlockHeight] | |
-> SqlPersistT m [NodeBlock] |
Get ancestors for specified block at given heights.
:: MonadIO m | |
=> NodeBlock | Best block |
-> Word32 | Count (0 for all) |
-> BlockHeight | Height from (including) |
-> SqlPersistT m [NodeBlock] |
Get a range of block headers building up to specified block. If specified height is too large, an empty list will be returned.
getBlocksAtHeight :: MonadIO m => BlockHeight -> SqlPersistT m [NodeBlock] Source #
Get blocks at specified height in all chains.
genesisBlock :: NodeBlock Source #
Genesis block.
splitBlock :: MonadIO m => NodeBlock -> NodeBlock -> SqlPersistT m NodeBlock Source #
Get node height and chain common to both given.
splitChains :: MonadIO m => (NodeBlock, Word32) -> (NodeBlock, Word32) -> SqlPersistT m (NodeBlock, [NodeBlock], [NodeBlock]) Source #
Find the split point between two nodes. It also returns the two partial chains leading from the split point to the respective nodes. Tuples must contain a block node and the count of nodes that should be returned from the split towards that block. 0 means all.
:: NodeBlock | Parent block node |
-> Word32 | Chain number for new node |
-> BlockHeader | |
-> NodeBlock |
Create a block node data structure from a block header.
nodeHeader :: NodeBlock -> BlockHeader Source #
nodeTimestamp :: NodeBlock -> Timestamp Source #
nodeHeight :: NodeBlock -> BlockHeight Source #
isBestChain :: BlockChainAction -> Bool Source #
Returns True if the action is a best chain.
isChainReorg :: BlockChainAction -> Bool Source #
Returns True if the action is a chain reorg.
isSideChain :: BlockChainAction -> Bool Source #
Returns True if the action is a side chain.
isKnownChain :: BlockChainAction -> Bool Source #
Returns True if the action is a known chain.
connectHeader :: MonadIO m => NodeBlock -> BlockHeader -> Timestamp -> SqlPersistT m (Either String BlockChainAction) Source #
Connect a block header to this block header chain. Corresponds to bitcoind function ProcessBlockHeader and AcceptBlockHeader in main.cpp.
connectHeaders :: MonadIO m => NodeBlock -> [BlockHeader] -> Timestamp -> SqlPersistT m (Either String BlockChainAction) Source #
A more efficient way of connecting a list of block headers than connecting them individually. The list of block headers have must form a valid chain.
blockLocator :: MonadIO m => NodeBlock -> SqlPersistT m BlockLocator Source #
Returns a BlockLocator object for a given block hash.
pruneChain :: MonadIO m => NodeBlock -> SqlPersistT m NodeBlock Source #
Remove all other chains from database and return updated best block node.