/
types.go
78 lines (65 loc) · 1.81 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only
package babe
import (
"fmt"
"time"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/crypto/sr25519"
"github.com/ChainSafe/gossamer/pkg/scale"
)
// Randomness is an alias for a byte array with length types.RandomnessLength
type Randomness = [types.RandomnessLength]byte
// VrfOutputAndProof represents the fields for VRF output and proof
type VrfOutputAndProof struct {
output [sr25519.VRFOutputLength]byte
proof [sr25519.VRFProofLength]byte
}
// Slot represents a BABE slot
type Slot struct {
start time.Time
duration time.Duration
number uint64
}
// NewSlot returns a new Slot
func NewSlot(start time.Time, duration time.Duration, number uint64) *Slot {
return &Slot{
start: start,
duration: duration,
number: number,
}
}
func (s Slot) String() string {
return fmt.Sprintf("slot number %d started at %s for a duration of %s",
s.number, s.start, s.duration)
}
// Authorities is an alias for []*types.Authority
type Authorities []types.Authority
// String returns the Authorities as a formatted string
func (d Authorities) String() string {
str := ""
for _, di := range []types.Authority(d) {
str = str + fmt.Sprintf("[key=0x%x weight=%d] ", di.Key.Encode(), di.Weight)
}
return str
}
// epochData contains the current epoch information
type epochData struct {
randomness Randomness
authorityIndex uint32
authorities []types.AuthorityRaw
threshold *scale.Uint128
allowedSlots types.AllowedSlots
}
func (ed *epochData) String() string {
return fmt.Sprintf("randomness=%x authorityIndex=%d authorities=%v threshold=%s",
ed.randomness,
ed.authorityIndex,
ed.authorities,
ed.threshold,
)
}
type constants struct {
slotDuration time.Duration
epochLength uint64
}