2024-02-01 04:48:40 +00:00
|
|
|
package keeper
|
|
|
|
|
2024-02-02 09:39:10 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2024-02-08 13:23:20 +00:00
|
|
|
errorsmod "cosmossdk.io/errors"
|
2024-02-02 09:39:10 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2024-02-08 13:23:20 +00:00
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
2024-02-02 09:39:10 +00:00
|
|
|
|
2024-02-08 13:23:20 +00:00
|
|
|
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
|
|
|
|
)
|
2024-02-02 09:39:10 +00:00
|
|
|
|
2024-02-01 04:48:40 +00:00
|
|
|
type queryServer struct {
|
|
|
|
k Keeper
|
|
|
|
}
|
|
|
|
|
2024-02-08 13:23:20 +00:00
|
|
|
var _ bondtypes.QueryServer = queryServer{}
|
2024-02-01 04:48:40 +00:00
|
|
|
|
|
|
|
// NewQueryServerImpl returns an implementation of the module QueryServer.
|
2024-02-08 13:23:20 +00:00
|
|
|
func NewQueryServerImpl(k Keeper) bondtypes.QueryServer {
|
2024-02-02 09:39:10 +00:00
|
|
|
return queryServer{k}
|
|
|
|
}
|
2024-02-01 04:48:40 +00:00
|
|
|
|
2024-02-08 13:23:20 +00:00
|
|
|
// Params implements bond.QueryServer.
|
|
|
|
func (qs queryServer) Params(c context.Context, _ *bondtypes.QueryParamsRequest) (*bondtypes.QueryParamsResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
|
|
|
|
params, err := qs.k.GetParams(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &bondtypes.QueryParamsResponse{Params: params}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bonds implements bond.QueryServer.
|
|
|
|
func (qs queryServer) Bonds(c context.Context, _ *bondtypes.QueryGetBondsRequest) (*bondtypes.QueryGetBondsResponse, error) {
|
2024-02-02 09:39:10 +00:00
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
|
|
|
|
resp, err := qs.k.ListBonds(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-02-08 13:23:20 +00:00
|
|
|
return &bondtypes.QueryGetBondsResponse{Bonds: resp}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBondById implements bond.QueryServer.
|
|
|
|
func (qs queryServer) GetBondById(c context.Context, req *bondtypes.QueryGetBondByIdRequest) (*bondtypes.QueryGetBondByIdResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
|
|
|
|
bondId := req.GetId()
|
|
|
|
if len(bondId) == 0 {
|
|
|
|
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "bond id required")
|
|
|
|
}
|
|
|
|
|
|
|
|
bond, err := qs.k.GetBondById(ctx, bondId)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &bondtypes.QueryGetBondByIdResponse{Bond: &bond}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBondsByOwner implements bond.QueryServer.
|
|
|
|
func (qs queryServer) GetBondsByOwner(c context.Context, req *bondtypes.QueryGetBondsByOwnerRequest) (*bondtypes.QueryGetBondsByOwnerResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
|
|
|
|
owner := req.GetOwner()
|
|
|
|
if len(owner) == 0 {
|
|
|
|
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "owner required")
|
|
|
|
}
|
|
|
|
|
|
|
|
bonds, err := qs.k.GetBondsByOwner(ctx, owner)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &bondtypes.QueryGetBondsByOwnerResponse{Bonds: bonds}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBondsModuleBalance implements bond.QueryServer.
|
|
|
|
func (qs queryServer) GetBondsModuleBalance(c context.Context, _ *bondtypes.QueryGetBondModuleBalanceRequest) (*bondtypes.QueryGetBondModuleBalanceResponse, error) {
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
balances := qs.k.GetBondModuleBalances(ctx)
|
|
|
|
|
|
|
|
return &bondtypes.QueryGetBondModuleBalanceResponse{Balance: balances}, nil
|
2024-02-02 09:39:10 +00:00
|
|
|
}
|