0g-chain/x/council/v1/keeper/grpc_query.go

36 lines
918 B
Go
Raw Normal View History

2024-04-24 07:10:22 +00:00
package keeper
import (
"context"
2024-04-25 06:13:27 +00:00
"github.com/0glabs/0g-chain/x/council/v1/types"
2024-04-24 07:10:22 +00:00
sdk "github.com/cosmos/cosmos-sdk/types"
)
var _ types.QueryServer = Keeper{}
2024-04-25 06:13:27 +00:00
func (k Keeper) CurrentCouncilID(
2024-04-24 07:10:22 +00:00
c context.Context,
2024-04-25 06:13:27 +00:00
_ *types.QueryCurrentCouncilIDRequest,
) (*types.QueryCurrentCouncilIDResponse, error) {
2024-04-24 07:10:22 +00:00
ctx := sdk.UnwrapSDKContext(c)
2024-04-25 06:13:27 +00:00
currentCouncilID, err := k.GetCurrentCouncilID(ctx)
2024-04-24 07:10:22 +00:00
if err != nil {
return nil, err
}
2024-04-25 06:13:27 +00:00
return &types.QueryCurrentCouncilIDResponse{CurrentCouncilID: currentCouncilID}, nil
2024-04-24 07:10:22 +00:00
}
func (k Keeper) RegisteredVoters(
c context.Context,
_ *types.QueryRegisteredVotersRequest,
) (*types.QueryRegisteredVotersResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
voterAddrs := k.GetVoters(ctx)
voters := make([]string, len(voterAddrs))
for i, voterAddr := range voterAddrs {
voters[i] = voterAddr.String()
}
return &types.QueryRegisteredVotersResponse{Voters: voters}, nil
}