/
params.go
54 lines (41 loc) · 861 Bytes
/
params.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
package snapshot
import (
"context"
"github.com/0xDaoChain/dao-chain/command/helper"
ibftOp "github.com/0xDaoChain/dao-chain/consensus/ibft/proto"
)
const (
numberFlag = "number"
)
var (
params = &snapshotParams{}
)
type snapshotParams struct {
blockNumber int
snapshot *ibftOp.Snapshot
}
func (p *snapshotParams) initSnapshot(grpcAddress string) error {
ibftClient, err := helper.GetIBFTOperatorClientConnection(grpcAddress)
if err != nil {
return err
}
snapshot, err := ibftClient.GetSnapshot(
context.Background(),
p.getSnapshotRequest(),
)
if err != nil {
return err
}
p.snapshot = snapshot
return nil
}
func (p *snapshotParams) getSnapshotRequest() *ibftOp.SnapshotReq {
req := &ibftOp.SnapshotReq{
Latest: true,
}
if p.blockNumber >= 0 {
req.Latest = false
req.Number = uint64(p.blockNumber)
}
return req
}