2022-04-05 07:09:27 +00:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-09-07 06:36:11 +00:00
|
|
|
"github.com/cerc-io/laconicd/x/bond/types"
|
2022-04-05 07:09:27 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Querier struct {
|
|
|
|
Keeper
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ types.QueryServer = Querier{}
|
|
|
|
|
|
|
|
func (q Querier) Bonds(c context.Context, _ *types.QueryGetBondsRequest) (*types.QueryGetBondsResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
resp := q.Keeper.ListBonds(ctx)
|
|
|
|
return &types.QueryGetBondsResponse{Bonds: resp}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
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: ¶ms}, nil
|
|
|
|
}
|
|
|
|
|
2022-10-17 11:03:31 +00:00
|
|
|
func (q Querier) GetBondByID(c context.Context, req *types.QueryGetBondByIDRequest) (*types.QueryGetBondByIDResponse, error) {
|
2022-04-05 07:09:27 +00:00
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
2022-11-15 06:21:14 +00:00
|
|
|
bondID := req.GetId()
|
2022-10-17 11:03:31 +00:00
|
|
|
if len(bondID) == 0 {
|
2022-04-05 07:09:27 +00:00
|
|
|
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "bond id required")
|
|
|
|
}
|
2022-11-15 06:21:14 +00:00
|
|
|
bond := q.Keeper.GetBond(ctx, req.GetId())
|
2022-10-17 11:03:31 +00:00
|
|
|
return &types.QueryGetBondByIDResponse{Bond: &bond}, nil
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q Querier) GetBondsByOwner(c context.Context, req *types.QueryGetBondsByOwnerRequest) (*types.QueryGetBondsByOwnerResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
owner := req.GetOwner()
|
|
|
|
if len(owner) == 0 {
|
|
|
|
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "owner id required")
|
|
|
|
}
|
|
|
|
bonds := q.Keeper.QueryBondsByOwner(ctx, owner)
|
|
|
|
return &types.QueryGetBondsByOwnerResponse{Bonds: bonds}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q Querier) GetBondsModuleBalance(c context.Context, _ *types.QueryGetBondModuleBalanceRequest) (*types.QueryGetBondModuleBalanceResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
balance := q.Keeper.GetBondModuleBalances(ctx)
|
|
|
|
return &types.QueryGetBondModuleBalanceResponse{Balance: balance}, nil
|
|
|
|
}
|