d28ef888ff
* WIP : added bond module tx and query cli commands * added bond module invariant * update the go.mod * addressed the pr changes * update to proto files * refactor: move the proto package version from `v1` to `v1beta1` for vulcanize modules * WIP : addin the unit test scripts to bond module * refactor: refactored the test cases for bond module * refactor: refactored the bond module test cases 1. refactored grpc gateway endpoints of bond module 2. added test cases to cli query , cli tx and grpc end points * addressed the pr comments 1. changed query-by-owner to by-owner in cli cmd 2. changed bonds-by-owner route to by-owner in bond module
53 lines
1.8 KiB
Go
53 lines
1.8 KiB
Go
package keeper
|
|
|
|
import (
|
|
"context"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
"github.com/tharsis/ethermint/x/bond/types"
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
func (q Querier) GetBondById(c context.Context, req *types.QueryGetBondByIdRequest) (*types.QueryGetBondByIdResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
bondId := req.GetId()
|
|
if len(bondId) == 0 {
|
|
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "bond id required")
|
|
}
|
|
bond := q.Keeper.GetBond(ctx, req.GetId())
|
|
return &types.QueryGetBondByIdResponse{Bond: &bond}, nil
|
|
}
|
|
|
|
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
|
|
}
|