credmark.cmf.types.block_number.BlockNumber

class BlockNumber(number, timestamp=None, sampleTimestamp=None, **_kwargs)[source]

Bases: IntDTO

A block number which is a subclass of int so it can be used as a normal integer. It can also be used to get the timestamp for a block number and may have an associated sample_timestamp if the block number was determined based on a timestamp (for example when querying for block numbers from the ledger.)

A BlockNumber can be used as a DTO input or output to a model. When used as a top-level DTO it is serialized as a dict, otherwise it is serialized as a number.

Methods

dict

Dict to serialize if its a top-level DTO

from_date

Get the BlockNumber instance at or before the date timestamp.

from_datetime

Get the BlockNumber instance at or before the datetime timestamp.

from_dict

from_timestamp

Returns the block number from the input timestamp.

from_ymd

Get the BlockNumber instance at or before the datetime timestamp.

get_dt

Get a datetime for date and time values

list_with_interval

Returns a list of count BlockNumber instances with a gap of interval between each block number and the last block being end_block_number.

schema

Attributes

is_timestamp_loaded

sample_timestamp

timestamp

timestamp_datetime

Parameters
  • number (int) –

  • timestamp (Optional[Timestamp]) –

  • sampleTimestamp (Optional[Timestamp]) –

dict()[source]

Dict to serialize if its a top-level DTO

classmethod from_date(in_d)[source]

Get the BlockNumber instance at or before the date timestamp.

Parameters

in_d (date) –

classmethod from_datetime(in_dt)[source]

Get the BlockNumber instance at or before the datetime timestamp.

Parameters

in_dt (datetime) –

classmethod from_timestamp(timestamp)[source]

Returns the block number from the input timestamp. For input of timestamp and datetime, the last block before the datetime is returned.

The timestamp here will be used as the sample_timestamp on the resulting BlockNumber.

Parameters

timestamp (Union[datetime, int, float]) –

classmethod from_ymd(year, month, day, hour=0, minute=0, second=0, microsecond=0)[source]

Get the BlockNumber instance at or before the datetime timestamp.

Parameters
  • year (int) –

  • month (int) –

  • day (int) –

static get_dt(year, month, day, hour=0, minute=0, second=0, microsecond=0)[source]

Get a datetime for date and time values

Parameters
  • year (int) –

  • month (int) –

  • day (int) –

classmethod list_with_interval(end_block_number, interval, count)[source]

Returns a list of count BlockNumber instances with a gap of interval between each block number and the last block being end_block_number.

For example BlockNumber.list_with_interval(14000000, 100, 5) will return [13999600, 13999700, 13999800, 13999900, 14000000]

Parameters
  • end_block_number (int) –

  • interval (int) –

  • count (int) –