tslib

package
v0.0.0-...-2de43c5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2024 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Overview

Package tslib provides conversions between four data types: block numbers, dates, Linux timestamps, and "special" named blocks. The function names are self-explanitory.

Note: Because the relationship between block numbers and timestamps is a per-chain value, some of these functions require a `chain` name. It is assumed the chain is properly configured.

Index

Constants

This section is empty.

Variables

View Source
var ErrInTheFuture = errors.New("timestamp in the future")

Functions

func Append

func Append(chain string, tsArray []TimestampRecord) error

func ClearCache

func ClearCache(chain string)

func EstablishTimestamps

func EstablishTimestamps(chain string, publisher base.Address) error

func FromBnToDate

func FromBnToDate(chain string, bn base.Blknum) (gostradamus.DateTime, error)

FromBnToDate returns a chain-specific date given a block number.

func FromBnToName

func FromBnToName(chain string, bn base.Blknum) (string, error)

FromBnToName returns the block's chain-specific name (if found) given its block number

func FromBnToNamedBlock

func FromBnToNamedBlock(chain string, bn base.Blknum) (*types.NamedBlock, error)

FromBnToNamedBlock returns the block's chain-specific name (if found) given its block number

func FromBnToTs

func FromBnToTs(chain string, bn base.Blknum) (base.Timestamp, error)

FromBnToTs returns a chain-specific Linux timestamp given a block number

func FromDateToBn

func FromDateToBn(chain, dateStr string) (base.Blknum, error)

FromDateToBn returns a chain-specific block number given a date string (date strings are valid JSON dates).

func FromDateToTs

func FromDateToTs(dateStr string) (base.Timestamp, error)

FromDateToTs returns a Linux timestamp given a date string (not chain-specific)

func FromNameToBn

func FromNameToBn(chain, name string) (base.Blknum, error)

FromNameToBn returns the chain-specific block number (if found) given the name of a special block. The list of special blocks is per-chain.

func FromNameToDate

func FromNameToDate(chain, name string) (gostradamus.DateTime, error)

FromNameToDate returns a chain-specific date (if found) given its chain-specific name

func FromTsToBn

func FromTsToBn(chain string, ts base.Timestamp) (base.Blknum, error)

FromTsToBn returns a chain-specific block number given a Linux timestamp.

func FromTsToDate

func FromTsToDate(ts base.Timestamp) (gostradamus.DateTime, error)

FromTsToDate returns a date given a Linux timestamp (not chain-specific)

func GetSpecials

func GetSpecials(chain string) (specials []types.NamedBlock, err error)

GetSpecials returns a chain-specific list of special block names and numbers

func IsSpecialBlock

func IsSpecialBlock(chain, needle string) bool

IsSpecialBlock returns true if the given chain-specific name is a special block

func NTimestamps

func NTimestamps(chain string) (base.Blknum, error)

NTimestamps returns the number of records in the timestamp file

func RangeToBounds

func RangeToBounds(chain string, rng *base.FileRange) types.RangeDates

func Repair

func Repair(chain string, bn base.Blknum) error

Repair repairs a single timestamp

func Truncate

func Truncate(chain string, maxBn base.Blknum) error

Types

type TimestampDatabase

type TimestampDatabase struct {
	// contains filtered or unexported fields
}

type TimestampRecord

type TimestampRecord struct {
	Bn uint32 `json:"bn"`
	Ts uint32 `json:"ts"`
}

func FromBn

func FromBn(chain string, bn base.Blknum) (*TimestampRecord, error)

FromBn is a local function that returns a Timestamp record given a blockNum. It loads the timestamp file into memory if it isn't already loaded

func FromTs

func FromTs(chain string, ts base.Timestamp) (*TimestampRecord, error)

FromTs is a local function that returns a Timestamp record given a Unix timestamp. It loads the timestamp file into memory if it isn't already. If the timestamp requested is past the end of the timestamp file, it estimates the block number and returns and error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL