-
Notifications
You must be signed in to change notification settings - Fork 6
/
appquerier.go
64 lines (53 loc) · 1.85 KB
/
appquerier.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
package query
import (
"context"
"cosmossdk.io/depinject"
grpc "github.com/cosmos/gogoproto/grpc"
"github.com/pokt-network/poktroll/pkg/client"
apptypes "github.com/pokt-network/poktroll/x/application/types"
)
var _ client.ApplicationQueryClient = (*appQuerier)(nil)
// appQuerier is a wrapper around the apptypes.QueryClient that enables the
// querying of on-chain application information through a single exposed method
// which returns an apptypes.Application interface
type appQuerier struct {
clientConn grpc.ClientConn
applicationQuerier apptypes.QueryClient
}
// NewApplicationQuerier returns a new instance of a client.ApplicationQueryClient
// by injecting the dependecies provided by the depinject.Config
//
// Required dependencies:
// - clientCtx
func NewApplicationQuerier(deps depinject.Config) (client.ApplicationQueryClient, error) {
aq := &appQuerier{}
if err := depinject.Inject(
deps,
&aq.clientConn,
); err != nil {
return nil, err
}
aq.applicationQuerier = apptypes.NewQueryClient(aq.clientConn)
return aq, nil
}
// GetApplication returns an apptypes.Application interface for a given address
func (aq *appQuerier) GetApplication(
ctx context.Context,
appAddress string,
) (apptypes.Application, error) {
req := apptypes.QueryGetApplicationRequest{Address: appAddress}
res, err := aq.applicationQuerier.Application(ctx, &req)
if err != nil {
return apptypes.Application{}, apptypes.ErrAppNotFound.Wrapf("app address: %s [%v]", appAddress, err)
}
return res.Application, nil
}
// GetAllApplications returns all staked applications
func (aq *appQuerier) GetAllApplications(ctx context.Context) ([]apptypes.Application, error) {
req := apptypes.QueryAllApplicationsRequest{}
res, err := aq.applicationQuerier.AllApplications(ctx, &req)
if err != nil {
return []apptypes.Application{}, err
}
return res.Applications, nil
}