BlockParser
class BlockParser (View source)
BlockParser reads the raw block data extracted from blk files.
NOTE: These requires knowledge of more than just one block in the chain, this is not a db just a reader/parser.
- height (calculated based on knowing the prev block hash back to genesis.)
- confirmations (total blocks - height)
- median time (MEDIAN([time, of, past, 11, blocks]))
- chain work (requires knowledge of the prev blocks chain work)
- next block hash (it's in the name we need the next block in the chain to tell us)
Properties
| protected Stream | $block | The block bytes we read from. | |
| protected string|null | $magicBytes | The magic bytes that indicates the block start and type. | |
| protected int|null | $size | The block size. | 
Methods
Initialize a new instance of the bitcoin block parser class.
Get the transactions.
The block weight.
Check if the block contains any segregated witness transactions.
Get the stripped size of the block, that is the size of the block without witness data.
Get the block difficulty.
Get the transaction count.
Gets the block hash
Get the block nonce.
Get the block bits.
Get the block bits as hexadecimal.
Gets the block timestamp.
Gets the merkle root of the block.
Gets the previous block hash.
Gets the block version.
Gets the block version as hexadecimal.
Gets the raw block.
Gets the size of the block in bytes.
Gets the magic bytes.
Ends the reader and releases the underlying memory stream.
Write the binary block to a file.
Closes the stream.
Details
        
                            
    __construct(string $block, int|null $size = null, string|null $magicBytes = null)
        
    
    Initialize a new instance of the bitcoin block parser class.
        
                            Generator
    transactions()
        
    
    Get the transactions.
        
                            int
    weight()
        
    
    The block weight.
        
                            bool
    hasSegwit()
        
    
    Check if the block contains any segregated witness transactions.
        
                            int
    strippedSize()
        
    
    Get the stripped size of the block, that is the size of the block without witness data.
        
                            int|float
    difficulty()
        
    
    Get the block difficulty.
        
                            int
    transactionCount()
        
    
    Get the transaction count.
        
                            string
    blockHash()
        
    
    Gets the block hash
        
                            int
    nonce()
        
    
    Get the block nonce.
        
                            int
    bits()
        
    
    Get the block bits.
        
                            string
    bitsHex()
        
    
    Get the block bits as hexadecimal.
        
                            int
    timestamp()
        
    
    Gets the block timestamp.
        
                            string
    merkleRoot()
        
    
    Gets the merkle root of the block.
        
                            string
    previousBlock()
        
    
    Gets the previous block hash.
        
                            int
    version()
        
    
    Gets the block version.
        
                            string
    versionHex()
        
    
    Gets the block version as hexadecimal.
        
                            string
    block(bool $hex = false)
        
    
    Gets the raw block.
Note that magic bytes and size variable are striped from the block.
        
                            int
    size()
        
    
    Gets the size of the block in bytes.
        
                            string|null
    magicBytes()
        
    
    Gets the magic bytes.
        
                            void
    end()
        
    
    Ends the reader and releases the underlying memory stream.
        
                            void
    writeToFile(string $file)
        
    
    Write the binary block to a file.
This will write the block to $file in the same format as when reading a blk file, [MagicBytes][Size][BlockData].
        
                            
    __destruct()
        
    
    Closes the stream.