/
empty.go
48 lines (36 loc) 路 994 Bytes
/
empty.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
package client
import (
"context"
"errors"
"time"
"github.com/drand/drand/chain"
)
const emptyClientStringerValue = "EmptyClient"
var errEmptyClientUnsupportedGet = errors.New("not supported")
// EmptyClientWithInfo makes a client that returns the given info but no randomness
func EmptyClientWithInfo(info *chain.Info) Client {
return &emptyClient{info}
}
type emptyClient struct {
i *chain.Info
}
func (m *emptyClient) String() string {
return emptyClientStringerValue
}
func (m *emptyClient) Info(ctx context.Context) (*chain.Info, error) {
return m.i, nil
}
func (m *emptyClient) RoundAt(t time.Time) uint64 {
return chain.CurrentRound(t.Unix(), m.i.Period, m.i.GenesisTime)
}
func (m *emptyClient) Get(ctx context.Context, round uint64) (Result, error) {
return nil, errEmptyClientUnsupportedGet
}
func (m *emptyClient) Watch(ctx context.Context) <-chan Result {
ch := make(chan Result, 1)
close(ch)
return ch
}
func (m *emptyClient) Close() error {
return nil
}