tslib

package
v0.0.0-...-3f8eaf4 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: GPL-3.0 Imports: 27 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 uint64) (gostradamus.DateTime, error)

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

func FromBnToName

func FromBnToName(chain string, bn uint64) (string, error)

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

func FromBnToNamedBlock

func FromBnToNamedBlock(chain string, bn uint64) (*types.SimpleNamedBlock, error)

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

func FromBnToTs

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

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

func FromDateToBn

func FromDateToBn(chain, dateStr string) (uint64, 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) (uint64, 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) (uint64, 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.SimpleNamedBlock, 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) (uint64, error)

NTimestamps returns the number of records in the timestamp file

func Repair

func Repair(chain string, bn uint64) error

Repair repairs a single timestamp

func Truncate

func Truncate(chain string, maxBn uint64) 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 uint64) (*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

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