-
Notifications
You must be signed in to change notification settings - Fork 168
/
querier.go
64 lines (48 loc) · 1.57 KB
/
querier.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 keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
globalerrors "github.com/CosmosContracts/juno/v19/app/helpers"
"github.com/CosmosContracts/juno/v19/x/clock/types"
)
var _ types.QueryServer = &Querier{}
type Querier struct {
keeper Keeper
}
func NewQuerier(k Keeper) Querier {
return Querier{
keeper: k,
}
}
// ContractModules returns contract addresses which are using the clock
func (q Querier) ClockContracts(stdCtx context.Context, req *types.QueryClockContracts) (*types.QueryClockContractsResponse, error) {
ctx := sdk.UnwrapSDKContext(stdCtx)
contracts, err := q.keeper.GetPaginatedContracts(ctx, req.Pagination)
if err != nil {
return nil, err
}
return contracts, nil
}
// ClockContract returns the clock contract information
func (q Querier) ClockContract(stdCtx context.Context, req *types.QueryClockContract) (*types.QueryClockContractResponse, error) {
ctx := sdk.UnwrapSDKContext(stdCtx)
// Ensure the contract address is valid
if _, err := sdk.AccAddressFromBech32(req.ContractAddress); err != nil {
return nil, globalerrors.ErrInvalidAddress
}
contract, err := q.keeper.GetClockContract(ctx, req.ContractAddress)
if err != nil {
return nil, err
}
return &types.QueryClockContractResponse{
ClockContract: *contract,
}, nil
}
// Params returns the total set of clock parameters.
func (q Querier) Params(stdCtx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(stdCtx)
p := q.keeper.GetParams(ctx)
return &types.QueryParamsResponse{
Params: &p,
}, nil
}