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 to serialize if its a top-level DTO
Get the BlockNumber instance at or before the date timestamp.
Get the BlockNumber instance at or before the datetime timestamp.
from_dict
Returns the block number from the input timestamp.
Get the BlockNumber instance at or before the datetime timestamp.
Get a datetime for date and time values
Returns a list of
count
BlockNumber instances with a gap ofinterval
between each block number and the last block beingend_block_number
.schema
Attributes
is_timestamp_loaded
sample_timestamp
timestamp
timestamp_datetime
- 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.
- 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.
- static get_dt(year, month, day, hour=0, minute=0, second=0, microsecond=0)[source]
Get a datetime for date and time values
- classmethod list_with_interval(end_block_number, interval, count)[source]
Returns a list of
count
BlockNumber instances with a gap ofinterval
between each block number and the last block beingend_block_number
.For example
BlockNumber.list_with_interval(14000000, 100, 5)
will return[13999600, 13999700, 13999800, 13999900, 14000000]