/
query.go
67 lines (54 loc) · 2.01 KB
/
query.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
package beacon
import (
"context"
beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
abciAPI "github.com/oasisprotocol/oasis-core/go/consensus/tendermint/api"
beaconState "github.com/oasisprotocol/oasis-core/go/consensus/tendermint/apps/beacon/state"
)
// Query is the beacon query interface.
type Query interface {
Beacon(context.Context) ([]byte, error)
Epoch(context.Context) (beacon.EpochTime, int64, error)
FutureEpoch(context.Context) (*beacon.EpochTimeState, error)
Genesis(context.Context) (*beacon.Genesis, error)
ConsensusParameters(context.Context) (*beacon.ConsensusParameters, error)
VRFState(context.Context) (*beacon.VRFState, error)
}
// QueryFactory is the beacon query factory.
type QueryFactory struct {
state abciAPI.ApplicationQueryState
}
// QueryAt returns the beacon query interface for a specific height.
func (sf *QueryFactory) QueryAt(ctx context.Context, height int64) (Query, error) {
state, err := beaconState.NewImmutableState(ctx, sf.state, height)
if err != nil {
return nil, err
}
return &beaconQuerier{state}, nil
}
type beaconQuerier struct {
state *beaconState.ImmutableState
}
func (bq *beaconQuerier) Beacon(ctx context.Context) ([]byte, error) {
return bq.state.Beacon(ctx)
}
func (bq *beaconQuerier) Epoch(ctx context.Context) (beacon.EpochTime, int64, error) {
return bq.state.GetEpoch(ctx)
}
func (bq *beaconQuerier) FutureEpoch(ctx context.Context) (*beacon.EpochTimeState, error) {
return bq.state.GetFutureEpoch(ctx)
}
func (bq *beaconQuerier) ConsensusParameters(ctx context.Context) (*beacon.ConsensusParameters, error) {
return bq.state.ConsensusParameters(ctx)
}
func (bq *beaconQuerier) VRFState(ctx context.Context) (*beacon.VRFState, error) {
return bq.state.VRFState(ctx)
}
func (app *beaconApplication) QueryFactory() interface{} {
return &QueryFactory{app.state}
}
// NewQueryFactory returns a new QueryFactory backed by the given state
// instance.
func NewQueryFactory(state abciAPI.ApplicationQueryState) *QueryFactory {
return &QueryFactory{state}
}