From 06ba66a687875d8adb5ca3cda5a8cd28f8dd31c3 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 17 May 2023 00:50:48 +0200 Subject: [PATCH 1/3] feat: LegacyMsg support --- x/ugov/msg.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/x/ugov/msg.go b/x/ugov/msg.go index 86185a8348..2e6ff7128f 100644 --- a/x/ugov/msg.go +++ b/x/ugov/msg.go @@ -4,12 +4,16 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/umee-network/umee/v4/util/checkers" ) var ( _ sdk.Msg = &MsgGovUpdateMinGasPrice{} + + // amino + _ legacytx.LegacyMsg = &MsgGovUpdateMinGasPrice{} ) // ValidateBasic implements Msg @@ -30,3 +34,14 @@ func (msg *MsgGovUpdateMinGasPrice) GetSigners() []sdk.AccAddress { func (msg *MsgGovUpdateMinGasPrice) String() string { return fmt.Sprintf("", msg.Authority, msg.MinGasPrice.String()) } + +// Route implements LegacyMsg.Route +func (msg MsgGovUpdateMinGasPrice) Route() string { return "" } + +// GetSignBytes implements the LegacyMsg.GetSignBytes +func (msg MsgGovUpdateMinGasPrice) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) +} + +// GetSignBytes implements the LegacyMsg.Type +func (msg MsgGovUpdateMinGasPrice) Type() string { return sdk.MsgTypeURL(&msg) } From 8506786848b2788d31f9cd6c415ecbfe21c34554 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 17 May 2023 01:27:46 +0200 Subject: [PATCH 2/3] ugov module implementation --- proto/umee/ugov/v1/genesis.proto | 3 +- x/ugov/codec.go | 42 +++++++++ x/ugov/genesis.go | 16 ++++ x/ugov/genesis.pb.go | 70 ++++++--------- x/ugov/genesis_test.go | 23 +++++ x/ugov/keeper/fees.go | 10 +-- x/ugov/keeper/fees_test.go | 7 +- x/ugov/keeper/genesis.go | 13 +++ x/ugov/keeper/genesis_test.go | 22 +++++ x/ugov/keeper/msg_server.go | 2 +- x/ugov/keeper/query_server.go | 8 +- x/ugov/module/module.go | 146 +++++++++++++++++++++++++++++++ 12 files changed, 308 insertions(+), 54 deletions(-) create mode 100644 x/ugov/codec.go create mode 100644 x/ugov/genesis.go create mode 100644 x/ugov/genesis_test.go create mode 100644 x/ugov/keeper/genesis.go create mode 100644 x/ugov/keeper/genesis_test.go create mode 100644 x/ugov/module/module.go diff --git a/proto/umee/ugov/v1/genesis.proto b/proto/umee/ugov/v1/genesis.proto index 797efb77e7..2cfd325c25 100644 --- a/proto/umee/ugov/v1/genesis.proto +++ b/proto/umee/ugov/v1/genesis.proto @@ -9,6 +9,5 @@ option (gogoproto.goproto_getters_all) = false; // GenesisState of the ugov module. message GenesisState { - repeated cosmos.base.v1beta1.Coin min_tx_fees = 1 - [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"]; + cosmos.base.v1beta1.DecCoin min_gas_price = 1 [(gogoproto.nullable) = false]; } diff --git a/x/ugov/codec.go b/x/ugov/codec.go new file mode 100644 index 0000000000..2a093f6558 --- /dev/null +++ b/x/ugov/codec.go @@ -0,0 +1,42 @@ +package ugov + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" + "github.com/gogo/protobuf/proto" +) + +// Amino codecs +// Note, the ModuleCdc should ONLY be used in certain instances of tests and for JSON +// encoding as Amino is still used for that purpose. +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) + +func init() { + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) + RegisterLegacyAminoCodec(amino) + + amino.Seal() +} + +// RegisterLegacyAminoCodec registers the necessary x/uibc interfaces and +// concrete types on the provided LegacyAmino codec. These types are used for +// Amino JSON serialization. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgGovUpdateMinGasPrice{}, proto.MessageName(&MsgGovUpdateMinGasPrice{}), nil) +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgGovUpdateMinGasPrice{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} diff --git a/x/ugov/genesis.go b/x/ugov/genesis.go new file mode 100644 index 0000000000..4993053b74 --- /dev/null +++ b/x/ugov/genesis.go @@ -0,0 +1,16 @@ +package ugov + +import ( + "github.com/umee-network/umee/v4/util/coin" +) + +// DefaultGenesis creates a default genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + MinGasPrice: coin.UmeeDec("0.1"), + } +} + +func (gs *GenesisState) Validate() error { + return gs.MinGasPrice.Validate() +} diff --git a/x/ugov/genesis.pb.go b/x/ugov/genesis.pb.go index 306caf37f5..9067963ac6 100644 --- a/x/ugov/genesis.pb.go +++ b/x/ugov/genesis.pb.go @@ -5,7 +5,6 @@ package ugov import ( fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" @@ -27,7 +26,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState of the ugov module. type GenesisState struct { - MinTxFees github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=min_tx_fees,json=minTxFees,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"min_tx_fees"` + MinGasPrice types.DecCoin `protobuf:"bytes,1,opt,name=min_gas_price,json=minGasPrice,proto3" json:"min_gas_price"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -70,24 +69,22 @@ func init() { func init() { proto.RegisterFile("umee/ugov/v1/genesis.proto", fileDescriptor_82f39cd8e8ede8c7) } var fileDescriptor_82f39cd8e8ede8c7 = []byte{ - // 259 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xbf, 0x4e, 0xc3, 0x30, - 0x10, 0x87, 0x13, 0x21, 0x21, 0x91, 0x76, 0xaa, 0x18, 0x20, 0x83, 0x8b, 0x18, 0x50, 0x97, 0xfa, - 0x08, 0xf0, 0x04, 0x05, 0xc1, 0x0e, 0x4c, 0x2c, 0x55, 0x12, 0x8e, 0x60, 0x45, 0xf1, 0x55, 0x3d, - 0x27, 0x04, 0xf1, 0x12, 0x3c, 0x07, 0x4f, 0x92, 0xb1, 0x23, 0x13, 0x7f, 0x92, 0x17, 0x41, 0xb6, - 0x3b, 0x30, 0xd9, 0xa7, 0xef, 0xee, 0x3b, 0xfd, 0x2e, 0x8a, 0xeb, 0x0a, 0x11, 0xea, 0x82, 0x1a, - 0x68, 0x12, 0x28, 0x50, 0x23, 0x2b, 0x96, 0xab, 0x35, 0x19, 0x9a, 0x8c, 0x2d, 0x93, 0x96, 0xc9, - 0x26, 0x89, 0xf7, 0x0b, 0x2a, 0xc8, 0x01, 0xb0, 0x3f, 0xdf, 0x13, 0x8b, 0x9c, 0xb8, 0x22, 0x86, - 0x2c, 0x65, 0x84, 0x26, 0xc9, 0xd0, 0xa4, 0x09, 0xe4, 0xa4, 0xb4, 0xe7, 0xc7, 0x6f, 0xd1, 0xf8, - 0xc6, 0x4b, 0xef, 0x4c, 0x6a, 0x70, 0x52, 0x46, 0xa3, 0x4a, 0xe9, 0xa5, 0x69, 0x97, 0x4f, 0x88, - 0x7c, 0x10, 0x1e, 0xed, 0xcc, 0x46, 0x67, 0x87, 0xd2, 0x5b, 0xa4, 0xb5, 0xc8, 0xad, 0x45, 0x5e, - 0x92, 0xd2, 0x8b, 0xd3, 0xee, 0x6b, 0x1a, 0x7c, 0x7c, 0x4f, 0x67, 0x85, 0x32, 0xcf, 0x75, 0x26, - 0x73, 0xaa, 0x60, 0xbb, 0xd2, 0x3f, 0x73, 0x7e, 0x2c, 0xc1, 0xbc, 0xae, 0x90, 0xdd, 0x00, 0xdf, - 0xee, 0x55, 0x4a, 0xdf, 0xb7, 0xd7, 0x88, 0xbc, 0xb8, 0xea, 0x7e, 0x45, 0xd0, 0xf5, 0x22, 0xdc, - 0xf4, 0x22, 0xfc, 0xe9, 0x45, 0xf8, 0x3e, 0x88, 0x60, 0x33, 0x88, 0xe0, 0x73, 0x10, 0xc1, 0xc3, - 0xc9, 0x3f, 0xa5, 0x4d, 0x3a, 0xd7, 0x68, 0x5e, 0x68, 0x5d, 0xba, 0x02, 0x9a, 0x0b, 0x68, 0xdd, - 0x5d, 0xb2, 0x5d, 0x97, 0xe4, 0xfc, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x68, 0xd2, 0x77, 0x1f, 0x2b, - 0x01, 0x00, 0x00, + // 239 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x2c, 0x8f, 0xb1, 0x4a, 0x04, 0x31, + 0x10, 0x86, 0x13, 0x10, 0x8b, 0xbd, 0xb3, 0x39, 0x2c, 0x64, 0x91, 0x28, 0x16, 0x62, 0x63, 0x86, + 0x55, 0x9f, 0xe0, 0x3c, 0xbc, 0x56, 0x14, 0x2c, 0x6c, 0x8e, 0x6c, 0x18, 0x62, 0x90, 0x64, 0x8e, + 0x4d, 0x36, 0xfa, 0x18, 0x3e, 0xd6, 0x96, 0x57, 0x5a, 0x89, 0xee, 0xbe, 0x88, 0x64, 0xf7, 0xba, + 0x19, 0xbe, 0x99, 0x8f, 0xff, 0x2f, 0xca, 0xd6, 0x21, 0x42, 0x6b, 0x28, 0x41, 0xaa, 0xc0, 0xa0, + 0xc7, 0x60, 0x83, 0xdc, 0x36, 0x14, 0x69, 0x31, 0xcf, 0x4c, 0x66, 0x26, 0x53, 0x55, 0x1e, 0x1b, + 0x32, 0x34, 0x02, 0xc8, 0xd3, 0x74, 0x53, 0x0a, 0x4d, 0xc1, 0x51, 0x80, 0x5a, 0x05, 0x84, 0x54, + 0xd5, 0x18, 0x55, 0x05, 0x9a, 0xac, 0x9f, 0xf8, 0xc5, 0x4b, 0x31, 0x5f, 0x4f, 0xd2, 0xe7, 0xa8, + 0x22, 0x2e, 0x1e, 0x8a, 0x23, 0x67, 0xfd, 0xc6, 0xa8, 0xb0, 0xd9, 0x36, 0x56, 0xe3, 0x09, 0x3f, + 0xe7, 0x57, 0xb3, 0x9b, 0x53, 0x39, 0x79, 0x64, 0xf6, 0xc8, 0xbd, 0x47, 0xae, 0x50, 0xdf, 0x93, + 0xf5, 0xcb, 0x83, 0xee, 0xe7, 0x8c, 0x3d, 0xcd, 0x9c, 0xf5, 0x6b, 0x15, 0x1e, 0xf3, 0xdb, 0x72, + 0xd5, 0xfd, 0x09, 0xd6, 0xf5, 0x82, 0xef, 0x7a, 0xc1, 0x7f, 0x7b, 0xc1, 0xbf, 0x06, 0xc1, 0x76, + 0x83, 0x60, 0xdf, 0x83, 0x60, 0xaf, 0x97, 0xc6, 0xc6, 0xb7, 0xb6, 0x96, 0x9a, 0x1c, 0xe4, 0x12, + 0xd7, 0x1e, 0xe3, 0x07, 0x35, 0xef, 0xe3, 0x02, 0xe9, 0x0e, 0x3e, 0xc7, 0xca, 0xf5, 0xe1, 0x18, + 0xf2, 0xf6, 0x3f, 0x00, 0x00, 0xff, 0xff, 0xff, 0x2b, 0x1c, 0x38, 0x06, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -110,20 +107,16 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.MinTxFees) > 0 { - for iNdEx := len(m.MinTxFees) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.MinTxFees[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa + { + size, err := m.MinGasPrice.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -144,12 +137,8 @@ func (m *GenesisState) Size() (n int) { } var l int _ = l - if len(m.MinTxFees) > 0 { - for _, e := range m.MinTxFees { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } + l = m.MinGasPrice.Size() + n += 1 + l + sovGenesis(uint64(l)) return n } @@ -190,7 +179,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinTxFees", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MinGasPrice", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -217,8 +206,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.MinTxFees = append(m.MinTxFees, types.Coin{}) - if err := m.MinTxFees[len(m.MinTxFees)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.MinGasPrice.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/ugov/genesis_test.go b/x/ugov/genesis_test.go new file mode 100644 index 0000000000..99d0169c3a --- /dev/null +++ b/x/ugov/genesis_test.go @@ -0,0 +1,23 @@ +package ugov + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + "github.com/umee-network/umee/v4/util/coin" +) + +func TestGenesis(t *testing.T) { + require := require.New(t) + gs := DefaultGenesis() + + require.NoError(gs.Validate(), "default genesis must be correct") + + gs.MinGasPrice = coin.UtokenDec(coin.Dollar, "0.1") + require.NoError(gs.Validate(), "min_gas_price = 0.1dollar is correct") + + gs.MinGasPrice.Amount = sdk.MustNewDecFromStr("-1") + require.Error(gs.Validate(), "negative min_gas_price is NOT correct") +} diff --git a/x/ugov/keeper/fees.go b/x/ugov/keeper/fees.go index 2f04dfca2e..9864d26397 100644 --- a/x/ugov/keeper/fees.go +++ b/x/ugov/keeper/fees.go @@ -7,14 +7,14 @@ import ( "github.com/umee-network/umee/v4/util/store" ) -func (k Keeper) SetMinGasPrice(p *sdk.DecCoin) error { - return store.SetValue(k.store, keyMinGasPrice, p, "gas_price") +func (k Keeper) SetMinGasPrice(p sdk.DecCoin) error { + return store.SetValue(k.store, keyMinGasPrice, &p, "gas_price") } -func (k Keeper) MinGasPrice() *sdk.DecCoin { +func (k Keeper) MinGasPrice() sdk.DecCoin { gp := store.GetValue[*sdk.DecCoin](k.store, keyMinGasPrice, "gas_price") if gp == nil { - return &coin.Umee0dec + return coin.Umee0dec } - return gp + return *gp } diff --git a/x/ugov/keeper/fees_test.go b/x/ugov/keeper/fees_test.go index fb25c7ff5a..80e29ffd56 100644 --- a/x/ugov/keeper/fees_test.go +++ b/x/ugov/keeper/fees_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/umee-network/umee/v4/util/coin" ) @@ -13,9 +14,9 @@ func TestGasPrice(t *testing.T) { k := initKeeper(t) gpOut := k.MinGasPrice() - require.Equal(*gpOut, coin.UmeeDec("0"), "when nothing is set, 0uumee should be returned") + require.Equal(gpOut, coin.UmeeDec("0"), "when nothing is set, 0uumee should be returned") gp := coin.Atom1_25dec - k.SetMinGasPrice(&gp) - require.Equal(k.MinGasPrice(), &gp) + k.SetMinGasPrice(gp) + require.Equal(k.MinGasPrice(), gp) } diff --git a/x/ugov/keeper/genesis.go b/x/ugov/keeper/genesis.go new file mode 100644 index 0000000000..662eb7a8da --- /dev/null +++ b/x/ugov/keeper/genesis.go @@ -0,0 +1,13 @@ +package keeper + +import "github.com/umee-network/umee/v4/x/ugov" + +func (k Keeper) ExportGenesis() *ugov.GenesisState { + return &ugov.GenesisState{ + MinGasPrice: k.MinGasPrice(), + } +} + +func (k Keeper) InitGenesis(gs *ugov.GenesisState) error { + return k.SetMinGasPrice(gs.MinGasPrice) +} diff --git a/x/ugov/keeper/genesis_test.go b/x/ugov/keeper/genesis_test.go new file mode 100644 index 0000000000..76c3e3f430 --- /dev/null +++ b/x/ugov/keeper/genesis_test.go @@ -0,0 +1,22 @@ +package keeper + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/umee-network/umee/v4/x/ugov" +) + +func TestGenesis(t *testing.T) { + t.Parallel() + require := require.New(t) + k := initKeeper(t) + + gs := ugov.DefaultGenesis() + err := k.InitGenesis(gs) + require.NoError(err) + + gsOut := k.ExportGenesis() + require.Equal(gs, gsOut) +} diff --git a/x/ugov/keeper/msg_server.go b/x/ugov/keeper/msg_server.go index 55fe79f5c9..cb6cdb8c5a 100644 --- a/x/ugov/keeper/msg_server.go +++ b/x/ugov/keeper/msg_server.go @@ -26,7 +26,7 @@ func (m msgServer) GovUpdateMinGasPrice(ctx context.Context, msg *ugov.MsgGovUpd } k := m.kb.Keeper(&sdkCtx) - if err := k.SetMinGasPrice(&msg.MinGasPrice); err != nil { + if err := k.SetMinGasPrice(msg.MinGasPrice); err != nil { return nil, err } sdkutil.Emit(&sdkCtx, &ugov.EventMinTxFees{ diff --git a/x/ugov/keeper/query_server.go b/x/ugov/keeper/query_server.go index 32aaee0e90..bf937a52f1 100644 --- a/x/ugov/keeper/query_server.go +++ b/x/ugov/keeper/query_server.go @@ -14,9 +14,13 @@ type Querier struct { Builder } +func NewQuerier(kb Builder) Querier { + return Querier{kb} +} + // MinTxFees returns minimum transaction fees. func (q Querier) MinGasPrice(ctx context.Context, _ *ugov.QueryMinGasPrice) (*ugov.QueryMinGasPriceResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - p := q.Keeper(&sdkCtx).MinGasPrice() - return &ugov.QueryMinGasPriceResponse{MinGasPrice: *p}, nil + return &ugov.QueryMinGasPriceResponse{MinGasPrice: q.Keeper(&sdkCtx).MinGasPrice()}, + nil } diff --git a/x/ugov/module/module.go b/x/ugov/module/module.go new file mode 100644 index 0000000000..2b2a1da4fd --- /dev/null +++ b/x/ugov/module/module.go @@ -0,0 +1,146 @@ +package uibc + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/umee-network/umee/v4/util" + // "github.com/umee-network/umee/v4/x/ugov/client/cli" + "github.com/umee-network/umee/v4/x/ugov" + "github.com/umee-network/umee/v4/x/ugov/keeper" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// AppModuleBasic is the 29-fee AppModuleBasic +type AppModuleBasic struct { + cdc codec.Codec +} + +func NewAppModuleBasic(cdc codec.Codec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// DefaultGenesis implements module.AppModuleBasic +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(ugov.DefaultGenesis()) +} + +// GetQueryCmd implements module.AppModuleBasic +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return nil // TODO cli.GetQueryCmd() +} + +// GetTxCmd implements module.AppModuleBasic +func (AppModuleBasic) GetTxCmd() *cobra.Command { + return nil // TODO cli.GetTxCmd() +} + +// Name implements module.AppModuleBasic +func (AppModuleBasic) Name() string { + return ugov.ModuleName +} + +// RegisterGRPCGatewayRoutes implements module.AppModuleBasic +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + err := ugov.RegisterQueryHandlerClient( + context.Background(), mux, ugov.NewQueryClient(clientCtx)) + util.Panic(err) +} + +// RegisterInterfaces implements module.AppModuleBasic +func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { + ugov.RegisterInterfaces(registry) +} + +// RegisterLegacyAminoCodec implements module.AppModuleBasic +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + ugov.RegisterLegacyAminoCodec(cdc) +} + +// ValidateGenesis implements module.AppModuleBasic +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var gs ugov.GenesisState + if err := cdc.UnmarshalJSON(bz, &gs); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", ugov.ModuleName, err) + } + + return gs.Validate() +} + +// AppModule represents the AppModule for this module +type AppModule struct { + AppModuleBasic + kb keeper.Builder +} + +func NewAppModule(cdc codec.Codec, kb keeper.Builder) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + kb: kb, + } +} + +// ExportGenesis implements module.AppModule +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := am.kb.Keeper(&ctx).ExportGenesis() + return cdc.MustMarshalJSON(genState) +} + +// InitGenesis implements module.AppModule +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { + var genState ugov.GenesisState + cdc.MustUnmarshalJSON(data, &genState) + am.kb.Keeper(&ctx).InitGenesis(&genState) + + return []abci.ValidatorUpdate{} +} + +// ConsensusVersion implements module.AppModule +func (AppModule) ConsensusVersion() uint64 { + return 1 +} + +// LegacyQuerierHandler implements module.AppModule +func (AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier { + return nil +} + +// QuerierRoute implements module.AppModule +func (AppModule) QuerierRoute() string { return "" } + +// RegisterInvariants implements module.AppModule +func (AppModule) RegisterInvariants(sdk.InvariantRegistry) {} + +// RegisterServices implements module.AppModule +func (am AppModule) RegisterServices(cfg module.Configurator) { + ugov.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServer(am.kb)) + ugov.RegisterQueryServer(cfg.QueryServer(), keeper.NewQuerier(am.kb)) +} + +// Route implements module.AppModule +func (AppModule) Route() sdk.Route { + return sdk.Route{} +} + +// BeginBlock executes all ABCI BeginBlock logic respective to the x/uibc module. +func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {} + +// EndBlock executes all ABCI EndBlock logic respective to the x/uibc module. +// It returns no validator updates. +func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return nil +} From 2d9819b01e4b2d718bd272604618fe93ed63c1dc Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 17 May 2023 16:08:05 +0200 Subject: [PATCH 3/3] lint --- x/ugov/module/module.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x/ugov/module/module.go b/x/ugov/module/module.go index 2b2a1da4fd..4740cd1116 100644 --- a/x/ugov/module/module.go +++ b/x/ugov/module/module.go @@ -104,7 +104,8 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { var genState ugov.GenesisState cdc.MustUnmarshalJSON(data, &genState) - am.kb.Keeper(&ctx).InitGenesis(&genState) + util.Panic( + am.kb.Keeper(&ctx).InitGenesis(&genState)) return []abci.ValidatorUpdate{} } @@ -137,7 +138,7 @@ func (AppModule) Route() sdk.Route { } // BeginBlock executes all ABCI BeginBlock logic respective to the x/uibc module. -func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {} +func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} // EndBlock executes all ABCI EndBlock logic respective to the x/uibc module. // It returns no validator updates.