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-04-01 09:57:26 +00:00
|
|
|
bondtypes "git.vdb.to/cerc-io/laconicd/x/bond"
|
2024-02-08 13:23:20 +00:00
|
|
|
)
|
2024-02-02 09:39:10 +00:00
|
|
|
|
2024-02-16 06:40:42 +00:00
|
|
|
var _ bondtypes.QueryServer = queryServer{}
|
|
|
|
|
2024-02-01 04:48:40 +00:00
|
|
|
type queryServer struct {
|
2024-02-28 04:34:58 +00:00
|
|
|
k *Keeper
|
2024-02-01 04:48:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewQueryServerImpl returns an implementation of the module QueryServer.
|
2024-02-28 04:34:58 +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.
|
2024-03-07 11:25:15 +00:00
|
|
|
func (qs queryServer) Bonds(c context.Context, _ *bondtypes.QueryBondsRequest) (*bondtypes.QueryBondsResponse, 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-03-07 11:25:15 +00:00
|
|
|
return &bondtypes.QueryBondsResponse{Bonds: resp}, nil
|
2024-02-08 13:23:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2024-07-11 05:16:31 +00:00
|
|
|
func (qs queryServer) GetBondsByOwner(
|
|
|
|
c context.Context,
|
|
|
|
req *bondtypes.QueryGetBondsByOwnerRequest,
|
|
|
|
) (*bondtypes.QueryGetBondsByOwnerResponse, error) {
|
2024-02-08 13:23:20 +00:00
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
|
|
|
|
owner := req.GetOwner()
|
|
|
|
if len(owner) == 0 {
|
2024-07-11 05:16:31 +00:00
|
|
|
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest,
|
|
|
|
"owner required",
|
|
|
|
)
|
2024-02-08 13:23:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bonds, err := qs.k.GetBondsByOwner(ctx, owner)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &bondtypes.QueryGetBondsByOwnerResponse{Bonds: bonds}, nil
|
|
|
|
}
|
|
|
|
|
2024-03-07 11:25:15 +00:00
|
|
|
// GetBondModuleBalance implements bond.QueryServer.
|
2024-07-11 05:16:31 +00:00
|
|
|
func (qs queryServer) GetBondModuleBalance(
|
|
|
|
c context.Context,
|
|
|
|
_ *bondtypes.QueryGetBondModuleBalanceRequest,
|
|
|
|
) (*bondtypes.QueryGetBondModuleBalanceResponse, error) {
|
2024-02-08 13:23:20 +00:00
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
balances := qs.k.GetBondModuleBalances(ctx)
|
|
|
|
|
2024-07-11 05:16:31 +00:00
|
|
|
return &bondtypes.QueryGetBondModuleBalanceResponse{
|
|
|
|
Balance: balances,
|
|
|
|
}, nil
|
2024-02-02 09:39:10 +00:00
|
|
|
}
|