laconicd-deprecated/x/registry/keeper/grpc_query.go

121 lines
4.2 KiB
Go
Raw Normal View History

package keeper
import (
"context"
2022-12-09 04:17:14 +00:00
"github.com/cerc-io/laconicd/x/registry/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// BondIDAttributeName denotes the record bond ID.
const BondIDAttributeName = "bondId"
// ExpiryTimeAttributeName denotes the record expiry time.
const ExpiryTimeAttributeName = "expiryTime"
type Querier struct {
Keeper
}
var _ types.QueryServer = Querier{}
func (q Querier) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
params := q.Keeper.GetParams(ctx)
return &types.QueryParamsResponse{Params: &params}, nil
}
func (q Querier) ListRecords(c context.Context, req *types.QueryListRecordsRequest) (*types.QueryListRecordsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
attributes := req.GetAttributes()
all := req.GetAll()
2022-10-17 11:03:31 +00:00
var records []types.Record
if len(attributes) > 0 {
var err error
records, err = q.Keeper.RecordsFromAttributes(ctx, attributes, all)
if err != nil {
return nil, err
}
} else {
records = q.Keeper.ListRecords(ctx)
}
return &types.QueryListRecordsResponse{Records: records}, nil
}
2022-10-17 11:03:31 +00:00
func (q Querier) GetRecord(c context.Context, req *types.QueryRecordByIDRequest) (*types.QueryRecordByIDResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
id := req.GetId()
if !q.Keeper.HasRecord(ctx, id) {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "Record not found.")
}
record := q.Keeper.GetRecord(ctx, id)
2022-10-17 11:03:31 +00:00
return &types.QueryRecordByIDResponse{Record: record}, nil
}
2022-10-17 11:03:31 +00:00
func (q Querier) GetRecordByBondID(c context.Context, req *types.QueryRecordByBondIDRequest) (*types.QueryRecordByBondIDResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
records := q.recordKeeper.QueryRecordsByBond(ctx, req.GetId())
2022-10-17 11:03:31 +00:00
return &types.QueryRecordByBondIDResponse{Records: records}, nil
}
2023-01-06 05:54:50 +00:00
func (q Querier) GetRegistryModuleBalance(c context.Context,
_ *types.GetRegistryModuleBalanceRequest,
) (*types.GetRegistryModuleBalanceResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
balances := q.Keeper.GetModuleBalances(ctx)
2022-12-09 04:17:14 +00:00
return &types.GetRegistryModuleBalanceResponse{
Balances: balances,
}, nil
}
func (q Querier) ListNameRecords(c context.Context, _ *types.QueryListNameRecordsRequest) (*types.QueryListNameRecordsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
nameRecords := q.Keeper.ListNameRecords(ctx)
return &types.QueryListNameRecordsResponse{Names: nameRecords}, nil
}
func (q Querier) Whois(c context.Context, request *types.QueryWhoisRequest) (*types.QueryWhoisResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
nameAuthority := q.Keeper.GetNameAuthority(ctx, request.GetName())
return &types.QueryWhoisResponse{NameAuthority: nameAuthority}, nil
}
2022-04-20 07:37:38 +00:00
func (q Querier) LookupCrn(c context.Context, req *types.QueryLookupCrn) (*types.QueryLookupCrnResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
2022-04-20 07:37:38 +00:00
crn := req.GetCrn()
if !q.Keeper.HasNameRecord(ctx, crn) {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "CRN not found.")
}
2022-04-20 07:37:38 +00:00
nameRecord := q.Keeper.GetNameRecord(ctx, crn)
if nameRecord == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "name record not found.")
}
2022-04-20 07:37:38 +00:00
return &types.QueryLookupCrnResponse{Name: nameRecord}, nil
}
2022-04-20 07:37:38 +00:00
func (q Querier) ResolveCrn(c context.Context, req *types.QueryResolveCrn) (*types.QueryResolveCrnResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
2022-04-20 07:37:38 +00:00
crn := req.GetCrn()
record := q.Keeper.ResolveCRN(ctx, crn)
if record == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "record not found.")
}
2022-04-20 07:37:38 +00:00
return &types.QueryResolveCrnResponse{Record: record}, nil
}
func (q Querier) GetRecordExpiryQueue(c context.Context, _ *types.QueryGetRecordExpiryQueue) (*types.QueryGetRecordExpiryQueueResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
records := q.Keeper.GetRecordExpiryQueue(ctx)
return &types.QueryGetRecordExpiryQueueResponse{Records: records}, nil
}
2023-01-06 05:54:50 +00:00
func (q Querier) GetAuthorityExpiryQueue(c context.Context,
_ *types.QueryGetAuthorityExpiryQueue,
) (*types.QueryGetAuthorityExpiryQueueResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
authorities := q.Keeper.GetAuthorityExpiryQueue(ctx)
return &types.QueryGetAuthorityExpiryQueueResponse{Authorities: authorities}, nil
}