Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: restructure x/consortium #493

Merged
merged 19 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (refactor) [\#493](https://github.com/line/lbm-sdk/pull/493) restructure x/consortium

### Bug Fixes
* (x/wasm) [\#453](https://github.com/line/lbm-sdk/pull/453) modify wasm grpc query api path
* (client) [\#476](https://github.com/line/lbm-sdk/pull/476) change the default value of the client output format in the config
Expand Down
10 changes: 5 additions & 5 deletions proto/lbm/consortium/v1/consortium.proto
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
syntax = "proto3";
package lbm.consortium.v1;

option go_package = "github.com/line/lbm-sdk/x/consortium/types";
option go_package = "github.com/line/lbm-sdk/x/consortium";
option (gogoproto.equal_all) = true;

import "gogoproto/gogo.proto";

// Params defines the parameters for the consortium module.
message Params {
bool enabled = 1 [(gogoproto.moretags) = "yaml:\"enabled\""];
bool enabled = 1;
}

// ValidatorAuth defines authorization info of a validator.
message ValidatorAuth {
string operator_address = 1 [(gogoproto.moretags) = "yaml:\"operator_address\""];
bool creation_allowed = 2 [(gogoproto.moretags) = "yaml:\"creation_allowed\""];
string operator_address = 1;
bool creation_allowed = 2;
}

// UpdateConsortiumParamsProposal details a proposal to update params of cosortium module.
Expand All @@ -36,5 +36,5 @@ message UpdateValidatorAuthsProposal {

string title = 1;
string description = 2;
repeated ValidatorAuth auths = 3 [(gogoproto.moretags) = "yaml:\"auths\""];
repeated ValidatorAuth auths = 3;
}
2 changes: 1 addition & 1 deletion proto/lbm/consortium/v1/event.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package lbm.consortium.v1;

option go_package = "github.com/line/lbm-sdk/x/consortium/types";
option go_package = "github.com/line/lbm-sdk/x/consortium";

import "lbm/consortium/v1/consortium.proto";

Expand Down
6 changes: 3 additions & 3 deletions proto/lbm/consortium/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package lbm.consortium.v1;

option go_package = "github.com/line/lbm-sdk/x/consortium/types";
option go_package = "github.com/line/lbm-sdk/x/consortium";
option (gogoproto.equal_all) = true;

import "gogoproto/gogo.proto";
Expand All @@ -13,9 +13,9 @@ message GenesisState {
option (gogoproto.goproto_getters) = false;

// params defines the module parameters at genesis.
Params params = 1 [(gogoproto.moretags) = "yaml:\"params\""];
Params params = 1;

// allowed_validators defines the allowed validator addresses at genesis.
// provided empty, the module gathers information from staking module.
repeated ValidatorAuth validator_auths = 2 [(gogoproto.moretags) = "yaml:\"validator_auths\""];
repeated ValidatorAuth validator_auths = 2;
}
2 changes: 1 addition & 1 deletion proto/lbm/consortium/v1/query.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package lbm.consortium.v1;

option go_package = "github.com/line/lbm-sdk/x/consortium/types";
option go_package = "github.com/line/lbm-sdk/x/consortium";

import "lbm/base/query/v1/pagination.proto";
import "google/api/annotations.proto";
Expand Down
18 changes: 9 additions & 9 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import (
"github.com/line/lbm-sdk/x/consortium"
consortiumclient "github.com/line/lbm-sdk/x/consortium/client"
consortiumkeeper "github.com/line/lbm-sdk/x/consortium/keeper"
consortiumtypes "github.com/line/lbm-sdk/x/consortium/types"
consortiummodule "github.com/line/lbm-sdk/x/consortium/module"
"github.com/line/lbm-sdk/x/crisis"
crisiskeeper "github.com/line/lbm-sdk/x/crisis/keeper"
crisistypes "github.com/line/lbm-sdk/x/crisis/types"
Expand Down Expand Up @@ -130,7 +130,7 @@ var (
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distr.AppModuleBasic{},
consortium.AppModuleBasic{},
consortiummodule.AppModuleBasic{},
gov.NewAppModuleBasic(
consortiumclient.UpdateConsortiumParamsProposalHandler,
consortiumclient.UpdateValidatorAuthsProposalHandler,
Expand Down Expand Up @@ -266,7 +266,7 @@ func NewSimApp(
ibctransfertypes.StoreKey,
capabilitytypes.StoreKey,
feegrant.StoreKey,
consortiumtypes.StoreKey,
consortium.StoreKey,
class.StoreKey,
token.StoreKey,
authzkeeper.StoreKey,
Expand Down Expand Up @@ -328,7 +328,7 @@ func NewSimApp(

app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper)
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp)
app.ConsortiumKeeper = consortiumkeeper.NewKeeper(appCodec, keys[consortiumtypes.StoreKey], stakingKeeper)
app.ConsortiumKeeper = consortiumkeeper.NewKeeper(appCodec, keys[consortium.StoreKey], stakingKeeper)

classKeeper := classkeeper.NewKeeper(appCodec, keys[class.StoreKey])
app.TokenKeeper = tokenkeeper.NewKeeper(appCodec, keys[token.StoreKey], app.AccountKeeper, classKeeper)
Expand All @@ -353,7 +353,7 @@ func NewSimApp(
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)).
AddRoute(consortiumtypes.RouterKey, consortium.NewProposalHandler(app.ConsortiumKeeper))
AddRoute(consortium.RouterKey, consortiumkeeper.NewProposalHandler(app.ConsortiumKeeper))

govKeeper := govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
Expand Down Expand Up @@ -410,7 +410,7 @@ func NewSimApp(
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
consortium.NewAppModule(appCodec, app.ConsortiumKeeper, app.StakingKeeper),
consortiummodule.NewAppModule(appCodec, app.ConsortiumKeeper, app.StakingKeeper),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
Expand Down Expand Up @@ -449,7 +449,7 @@ func NewSimApp(
vestingtypes.ModuleName,
ibchost.ModuleName,
ibctransfertypes.ModuleName,
consortiumtypes.ModuleName,
consortium.ModuleName,
token.ModuleName,
)
app.mm.SetOrderEndBlockers(
Expand All @@ -471,7 +471,7 @@ func NewSimApp(
vestingtypes.ModuleName,
ibchost.ModuleName,
ibctransfertypes.ModuleName,
consortiumtypes.ModuleName,
consortium.ModuleName,
token.ModuleName,
)

Expand Down Expand Up @@ -500,7 +500,7 @@ func NewSimApp(
ibchost.ModuleName,
ibctransfertypes.ModuleName,
vestingtypes.ModuleName,
consortiumtypes.ModuleName,
consortium.ModuleName,
token.ModuleName,
)

Expand Down
6 changes: 3 additions & 3 deletions simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/line/lbm-sdk/x/bank"
banktypes "github.com/line/lbm-sdk/x/bank/types"
"github.com/line/lbm-sdk/x/capability"
"github.com/line/lbm-sdk/x/consortium"
consortiummodule "github.com/line/lbm-sdk/x/consortium/module"
"github.com/line/lbm-sdk/x/crisis"
"github.com/line/lbm-sdk/x/distribution"
"github.com/line/lbm-sdk/x/evidence"
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestRunMigrations(t *testing.T) {
"crisis": crisis.AppModule{}.ConsensusVersion(),
"genutil": genutil.AppModule{}.ConsensusVersion(),
"capability": capability.AppModule{}.ConsensusVersion(),
"consortium": consortium.AppModule{}.ConsensusVersion(),
"consortium": consortiummodule.AppModule{}.ConsensusVersion(),
"token": tokenmodule.AppModule{}.ConsensusVersion(),
},
)
Expand Down Expand Up @@ -242,7 +242,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
"crisis": crisis.AppModule{}.ConsensusVersion(),
"genutil": genutil.AppModule{}.ConsensusVersion(),
"capability": capability.AppModule{}.ConsensusVersion(),
"consortium": consortium.AppModule{}.ConsensusVersion(),
"consortium": consortiummodule.AppModule{}.ConsensusVersion(),
"token": tokenmodule.AppModule{}.ConsensusVersion(),
},
)
Expand Down
16 changes: 8 additions & 8 deletions x/consortium/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"github.com/line/lbm-sdk/client"
"github.com/line/lbm-sdk/client/flags"
sdk "github.com/line/lbm-sdk/types"
"github.com/line/lbm-sdk/x/consortium/types"
"github.com/line/lbm-sdk/x/consortium"
)

// NewQueryCmd returns the parent command for all x/consortium CLi query commands.
func NewQueryCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Use: consortium.ModuleName,
Short: "Querying commands for the consortium module",
}

Expand All @@ -39,9 +39,9 @@ func NewQueryCmdParams() *cobra.Command {
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
queryClient := consortium.NewQueryClient(clientCtx)

params := types.QueryParamsRequest{}
params := consortium.QueryParamsRequest{}
res, err := queryClient.Params(context.Background(), &params)
if err != nil {
return err
Expand All @@ -68,14 +68,14 @@ func NewQueryCmdValidatorAuth() *cobra.Command {
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
queryClient := consortium.NewQueryClient(clientCtx)

valAddr := args[0]
if err = sdk.ValidateValAddress(valAddr); err != nil {
return err
}

params := types.QueryValidatorAuthRequest{ValidatorAddress: valAddr}
params := consortium.QueryValidatorAuthRequest{ValidatorAddress: valAddr}
res, err := queryClient.ValidatorAuth(context.Background(), &params)
if err != nil {
return err
Expand All @@ -102,14 +102,14 @@ func NewQueryCmdValidatorAuths() *cobra.Command {
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
queryClient := consortium.NewQueryClient(clientCtx)

pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}

params := types.QueryValidatorAuthsRequest{Pagination: pageReq}
params := consortium.QueryValidatorAuthsRequest{Pagination: pageReq}
res, err := queryClient.ValidatorAuths(context.Background(), &params)
if err != nil {
return err
Expand Down
16 changes: 8 additions & 8 deletions x/consortium/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/line/lbm-sdk/client/tx"
sdk "github.com/line/lbm-sdk/types"
"github.com/line/lbm-sdk/version"
"github.com/line/lbm-sdk/x/consortium/types"
"github.com/line/lbm-sdk/x/consortium"
"github.com/line/lbm-sdk/x/gov/client/cli"
govtypes "github.com/line/lbm-sdk/x/gov/types"
)
Expand Down Expand Up @@ -64,10 +64,10 @@ $ %s tx gov submit-proposal update-consortium-params [flags]
return err
}

params := &types.Params{
params := &consortium.Params{
Enabled: false,
}
content := types.NewUpdateConsortiumParamsProposal(title, description, params)
content := consortium.NewUpdateConsortiumParamsProposal(title, description, params)
msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from)
if err != nil {
return err
Expand Down Expand Up @@ -149,17 +149,17 @@ $ %s tx gov submit-proposal update-validator-auths [flags]
}
deletingValidators := parseCommaSeparated(deletingValidatorsStr)

createAuths := func(addings, deletings []string) []*types.ValidatorAuth {
var auths []*types.ValidatorAuth
createAuths := func(addings, deletings []string) []*consortium.ValidatorAuth {
var auths []*consortium.ValidatorAuth
for _, addr := range addings {
auth := &types.ValidatorAuth{
auth := &consortium.ValidatorAuth{
OperatorAddress: addr,
CreationAllowed: true,
}
auths = append(auths, auth)
}
for _, addr := range deletings {
auth := &types.ValidatorAuth{
auth := &consortium.ValidatorAuth{
OperatorAddress: addr,
CreationAllowed: false,
}
Expand All @@ -170,7 +170,7 @@ $ %s tx gov submit-proposal update-validator-auths [flags]
}

auths := createAuths(addingValidators, deletingValidators)
content := types.NewUpdateValidatorAuthsProposal(title, description, auths)
content := consortium.NewUpdateValidatorAuthsProposal(title, description, auths)
msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from)
if err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions x/consortium/client/testutil/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/line/lbm-sdk/testutil"
"github.com/line/lbm-sdk/testutil/rest"
"github.com/line/lbm-sdk/x/consortium/types"
"github.com/line/lbm-sdk/x/consortium"
)

func (s *IntegrationTestSuite) TestGRPCParams() {
Expand All @@ -24,9 +24,9 @@ func (s *IntegrationTestSuite) TestGRPCParams() {
"valid request",
fmt.Sprintf("%s/lbm/consortium/v1/params", val.APIAddress),
false,
&types.QueryParamsResponse{},
&types.QueryParamsResponse{
Params: &types.Params{
&consortium.QueryParamsResponse{},
&consortium.QueryParamsResponse{
Params: &consortium.Params{
Enabled: true,
},
},
Expand Down Expand Up @@ -83,7 +83,7 @@ func (s *IntegrationTestSuite) TestGRPCValidatorAuth() {
resp, err := rest.GetRequest(tc.url)
s.Require().NoError(err)

var auth types.QueryValidatorAuthResponse
var auth consortium.QueryValidatorAuthResponse
err = s.cfg.Codec.UnmarshalJSON(resp, &auth)

if tc.expErr {
Expand Down Expand Up @@ -121,7 +121,7 @@ func (s *IntegrationTestSuite) TestGRPCValidatorAuths() {
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers)
s.Require().NoError(err)

var auths types.QueryValidatorAuthsResponse
var auths consortium.QueryValidatorAuthsResponse
err = s.cfg.Codec.UnmarshalJSON(resp, &auths)

if tc.expErr {
Expand Down
10 changes: 5 additions & 5 deletions x/consortium/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/stretchr/testify/suite"

"github.com/line/lbm-sdk/testutil/network"
"github.com/line/lbm-sdk/x/consortium/types"
"github.com/line/lbm-sdk/x/consortium"
)

type IntegrationTestSuite struct {
Expand All @@ -23,18 +23,18 @@ func (s *IntegrationTestSuite) SetupSuite() {

genesisState := s.cfg.GenesisState

var consortiumData types.GenesisState
s.Require().NoError(s.cfg.Codec.UnmarshalJSON(genesisState[types.ModuleName], &consortiumData))
var consortiumData consortium.GenesisState
s.Require().NoError(s.cfg.Codec.UnmarshalJSON(genesisState[consortium.ModuleName], &consortiumData))

// enable consortium
params := &types.Params{
params := &consortium.Params{
Enabled: true,
}
consortiumData.Params = params

consortiumDataBz, err := s.cfg.Codec.MarshalJSON(&consortiumData)
s.Require().NoError(err)
genesisState[types.ModuleName] = consortiumDataBz
genesisState[consortium.ModuleName] = consortiumDataBz
s.cfg.GenesisState = genesisState

s.network = network.New(s.T(), s.cfg)
Expand Down
14 changes: 14 additions & 0 deletions x/consortium/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package consortium

import (
"github.com/line/lbm-sdk/codec/types"
govtypes "github.com/line/lbm-sdk/x/gov/types"
)

func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations(
(*govtypes.Content)(nil),
&UpdateConsortiumParamsProposal{},
&UpdateValidatorAuthsProposal{},
)
}
Loading