Documentation
¶
Index ¶
- Constants
- func BytesToRound(r []byte) uint64
- func CurrentRound(now int64, period time.Duration, genesis int64) uint64
- func MetricsStorageType(st StorageType) int
- func NextRound(now int64, period time.Duration, genesis int64) (nextRound uint64, nextTime int64)
- func PreviousRequiredFromContext(ctx context.Context) bool
- func RoundToBytes(r uint64) []byte
- func SetPreviousRequiredOnContext(ctx context.Context) context.Context
- func TimeOfRound(period time.Duration, genesis int64, round uint64) int64
- type Beacon
- func (b *Beacon) Equal(b2 *Beacon) bool
- func (b *Beacon) GetPreviousSignature() []byte
- func (b *Beacon) GetRound() uint64
- func (b *Beacon) GetSignature() []byte
- func (b *Beacon) Marshal() ([]byte, error)
- func (b *Beacon) Randomness() []byte
- func (b *Beacon) String() string
- func (b *Beacon) Unmarshal(buff []byte) error
- type Cursor
- type Info
- type StorageType
- type Store
Constants ¶
const TimeOfRoundErrorValue = math.MaxInt64 - maxTimeBuffer
TimeOfRoundErrorValue is the value returned by `TimeOfRound` when an invalid round is specified.
Variables ¶
This section is empty.
Functions ¶
func BytesToRound ¶ added in v1.5.3
BytesToRound unserializes a round number from bytes (8 bytes fixed length big-endian) to uint64.
func CurrentRound ¶
CurrentRound calculates the active round at `now`
func MetricsStorageType ¶ added in v1.5.3
func MetricsStorageType(st StorageType) int
func NextRound ¶
NextRound returns the next upcoming round and its UNIX time given the genesis time and the period. round at time genesis = round 1. Round 0 is fixed.
func PreviousRequiredFromContext ¶ added in v1.5.3
func RoundToBytes ¶
RoundToBytes serializes a round number to bytes (8 bytes fixed length big-endian).
func SetPreviousRequiredOnContext ¶ added in v1.5.3
Types ¶
type Beacon ¶
type Beacon struct { // PreviousSig is the previous signature generated PreviousSig []byte // Round is the round number this beacon is tied to Round uint64 // Signature is the BLS deterministic signature over Round || PreviousRand Signature []byte }
Beacon holds the randomness as well as the info to verify it.
func GenesisBeacon ¶ added in v1.0.2
GenesisBeacon returns the first beacon inserted in the chain
func (*Beacon) GetPreviousSignature ¶ added in v1.5.3
GetPreviousSignature returns the previous signature if it's non-nil or nil otherwise
func (*Beacon) GetSignature ¶ added in v1.5.3
GetSignature returns the signature if it's non-nil or nil otherwise
func (*Beacon) Randomness ¶
Randomness returns the hashed signature. The choice of the hash determines the size of the output.
type Cursor ¶
type Cursor interface { First(context.Context) (*Beacon, error) Next(context.Context) (*Beacon, error) Seek(ctx context.Context, round uint64) (*Beacon, error) Last(context.Context) (*Beacon, error) }
Cursor iterates over items in sorted key order. This starts from the first key/value pair and updates the k/v variables to the next key/value on each iteration.
The loop finishes at the end of the cursor when a nil key is returned.
for k, v := c.First(); k != nil; k, v = c.Next() { fmt.Printf("A %s is %s.\n", k, v) }
type Info ¶
type Info struct { PublicKey kyber.Point `json:"public_key"` ID string `json:"id"` Period time.Duration `json:"period"` Scheme string `json:"scheme"` GenesisTime int64 `json:"genesis_time"` GenesisSeed []byte `json:"group_hash"` }
Info represents the public information that is necessary for a client to verify any beacon present in a randomness chain.
func InfoFromJSON ¶
InfoFromJSON returns a Info from JSON description in the given reader
func InfoFromProto ¶
func InfoFromProto(p *drand.ChainInfoPacket) (*Info, error)
InfoFromProto returns a Info from the protocol description
func NewChainInfo ¶
NewChainInfo makes a chain Info from a group
func (*Info) GetSchemeName ¶ added in v1.5.3
GetSchemeName returns the scheme name used
func (*Info) Hash ¶
Hash returns the canonical hash representing the chain information. A hash is consistent throughout the entirety of a chain, regardless of the network composition, the actual nodes, generating the randomness.
func (*Info) HashString ¶ added in v1.4.6
HashString returns the value of Hash in string format
type StorageType ¶ added in v1.5.3
type StorageType string
StorageType defines the supported storage engines
const ( // BoltDB uses the BoltDB engine for storing data BoltDB StorageType = "bolt" // PostgreSQL uses the PostgreSQL database for storing data PostgreSQL StorageType = "postgres" // MemDB uses the in-memory database to store data MemDB StorageType = "memdb" )
Storage engine types
type Store ¶
type Store interface { Len(context.Context) (int, error) Put(context.Context, *Beacon) error Last(context.Context) (*Beacon, error) Get(ctx context.Context, round uint64) (*Beacon, error) Cursor(context.Context, func(context.Context, Cursor) error) error Close(context.Context) error Del(ctx context.Context, round uint64) error SaveTo(ctx context.Context, w io.Writer) error }
Store is an interface to store Beacons packets where they can also be retrieved to be delivered to end clients.
Directories
¶
Path | Synopsis |
---|---|
postgresdb
|
|
database
Package database provides support for access the database.
|
Package database provides support for access the database. |
schema
Package schema helps to keep the database up to date with schema.
|
Package schema helps to keep the database up to date with schema. |