NAME

Bitcoin::Crypto::Block - Stripped down block instance

SYNOPSIS

use Bitcoin::Crypto qw(btc_block);

my $block = btc_block->new(
	timestamp => 1697298600,
	height => 812164,
);

my $next_block = btc_block->new(
	timestamp => 1697299200,
	height => 812165,
	previous => $block,
);

print $next_block->median_time_past;

DESCRIPTION

This is a block instance required for locktime and sequence checks in transactions. It is used in "verify" in Bitcoin::Crypto::Transaction and "block" in Bitcoin::Crypto::Transaction::UTXO.

Bitcoin::Crypto does not contain any real blocks implementation. This class provides the bare minimum required for checking locktime and sequence.

INTERFACE

Attributes

height

An integer height of the block. Required.

Available in the constructor.

timestamp

An integer timestamp of the block. Default - now.

Available in the constructor.

previous

An optional instance of the previous block.

Available in the constructor.

Methods

new

$block = $class->new(%args)

This is a standard Moo constructor, which can be used to create the object. It takes arguments specified in "Attributes".

Returns class instance.

median_time_past

$mtp = $object->median_time_past()

This method returns the median time past described in BIP113 (median timestamp of previous 11 blocks).

Since this block implementation is as basic as it gets, it will happily calculate median time past from less than 11 blocks, if there aren't enough blocks chained via "previous".

SEE ALSO

Bitcoin::Crypto::Transaction
Bitcoin::Crypto::Transaction::UTXO