diff --git a/proto/hub-genesis/genesis.proto b/proto/hub-genesis/genesis.proto index e6e57214..2a121577 100755 --- a/proto/hub-genesis/genesis.proto +++ b/proto/hub-genesis/genesis.proto @@ -3,7 +3,7 @@ package rollapp.hub_genesis; import "gogoproto/gogo.proto"; import "hub-genesis/params.proto"; -import "hub-genesis/state.proto"; +import "hub-genesis/genesis_info.proto"; option go_package = "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types"; @@ -11,6 +11,7 @@ option go_package = "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types"; message GenesisState { // params defines all the parameters of the module. Params params = 1 [ (gogoproto.nullable) = false ]; - State state = 2 [(gogoproto.nullable) = false]; - repeated uint64 unacked_transfer_seq_nums = 3 [(gogoproto.nullable) = false]; + + // accounts on the Hub to fund with some bootstrapping transfers + repeated GenesisAccount genesis_accounts = 2 [ (gogoproto.nullable) = false ]; } diff --git a/proto/hub-genesis/genesis_bridge_data.proto b/proto/hub-genesis/genesis_bridge_data.proto new file mode 100644 index 00000000..987d42ed --- /dev/null +++ b/proto/hub-genesis/genesis_bridge_data.proto @@ -0,0 +1,22 @@ + +syntax = "proto3"; +package rollapp.hub_genesis; + +import "gogoproto/gogo.proto"; +import "cosmos/bank/v1beta1/bank.proto"; +import "ibc/applications/transfer/v2/packet.proto"; +import "hub-genesis/genesis_info.proto"; + +option go_package = "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types"; + +// GenesisBridgeData is the data struct that is passed to the hub for the +// genesis bridge flow +message GenesisBridgeData { + // genesis_info is the genesis info of the rollapp. used for hub validation + GenesisInfo genesis_info = 1 [ (gogoproto.nullable) = false ]; + // native_denom is the native denom of the rollapp. registered on the hub + cosmos.bank.v1beta1.Metadata native_denom = 2 + [ (gogoproto.nullable) = false ]; + // optional genesis transfer packet data + ibc.applications.transfer.v2.FungibleTokenPacketData genesis_transfer = 3; +} diff --git a/proto/hub-genesis/genesis_info.proto b/proto/hub-genesis/genesis_info.proto new file mode 100644 index 00000000..e9907f95 --- /dev/null +++ b/proto/hub-genesis/genesis_info.proto @@ -0,0 +1,45 @@ + +syntax = "proto3"; +package rollapp.hub_genesis; + +import "gogoproto/gogo.proto"; +import "cosmos/bank/v1beta1/bank.proto"; +import "hub-genesis/state.proto"; + +option go_package = "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types"; + +// The genesis info of the rollapp, that is passed to the hub for validation. +// it's populated on the InitGenesis of the rollapp +message GenesisInfo { + // checksum used to verify integrity of the genesis file. currently unused + string genesis_checksum = 1; + // unique bech32 prefix + string bech32_prefix = 2; + // native_denom is the base denom for the native token + DenomMetadata native_denom = 3; + // initial_supply is the initial supply of the native token + string initial_supply = 4 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; + // accounts on the Hub to fund with some bootstrapping transfers + repeated GenesisAccount genesis_accounts = 5 [ (gogoproto.nullable) = false ]; +} + +message DenomMetadata { + string display = 1; + string base = 2; + uint32 exponent = 3; +} + + +// GenesisAccount is a struct for the genesis account for the rollapp +message GenesisAccount { + // amount of coins to be sent to the genesis address + string amount = 1 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; + // address is a bech-32 address of the genesis account + string address = 2; +} \ No newline at end of file diff --git a/proto/hub-genesis/query.proto b/proto/hub-genesis/query.proto index 35b30535..21eb17d6 100644 --- a/proto/hub-genesis/query.proto +++ b/proto/hub-genesis/query.proto @@ -5,6 +5,7 @@ import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; import "hub-genesis/params.proto"; import "hub-genesis/state.proto"; +import "hub-genesis/genesis_info.proto"; option go_package = "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types"; @@ -16,11 +17,17 @@ service Query { "/dymensionxyz/dymension-rdk/hub-genesis/params"; } - // State returns the state of the genesis event. - rpc State(QueryStateRequest) returns (QueryStateResponse) { + // State returns the state of the genesis event. + rpc State(QueryStateRequest) returns (QueryStateResponse) { option (google.api.http).get = "/dymensionxyz/dymension-rdk/hub-genesis/state"; } + + // GenesisInfo returns the genesis info of the rollapp. + rpc GenesisInfo(QueryGenesisInfoRequest) returns (QueryGenesisInfoResponse) { + option (google.api.http).get = + "/dymensionxyz/dymension-rdk/hub-genesis/genesis_info"; + } } // QueryParamsRequest is the request type for the Query/Params RPC method. @@ -38,5 +45,16 @@ message QueryStateRequest {} // QueryStateResponse is the response type for the Query/State RPC method. message QueryStateResponse { // state holds the state of the genesis event - State state = 1 [(gogoproto.nullable) = false]; + State state = 1 [ (gogoproto.nullable) = false ]; +} + +// QueryGenesisInfoRequest is the request type for the Query/GenesisInfo RPC +// method. +message QueryGenesisInfoRequest {} + +// QueryGenesisInfoResponse is the response type for the Query/GenesisInfo RPC +// method. +message QueryGenesisInfoResponse { + // genesis_info holds the genesis info of the rollapp + GenesisInfo genesis_info = 1 [ (gogoproto.nullable) = false ]; } \ No newline at end of file diff --git a/proto/hub-genesis/state.proto b/proto/hub-genesis/state.proto index 6404bc8a..2ce9c7ba 100644 --- a/proto/hub-genesis/state.proto +++ b/proto/hub-genesis/state.proto @@ -2,22 +2,18 @@ syntax = "proto3"; package rollapp.hub_genesis; import "gogoproto/gogo.proto"; -import "cosmos/base/v1beta1/coin.proto"; option go_package = "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types"; // State holds the state of the genesis event message State { - reserved 1; - reserved 2; - // accounts on the Hub to fund with some bootstrapping transfers - repeated GenesisAccount genesis_accounts = 3 [(gogoproto.nullable) = false]; - // the number of genesis transfers for which an ack has not yet been received - uint64 num_unacked_transfers = 5; - // are outboundTransfersEnabled? This is only true if the genesis protocol has finished + reserved 1 to 5; + + // are outboundTransfersEnabled? This is only true if the genesis protocol has + // finished bool outbound_transfers_enabled = 6; // the canonical transfer port and channel for the hub - PortAndChannel hub_port_and_channel= 7; + PortAndChannel hub_port_and_channel = 7; } message PortAndChannel { @@ -26,11 +22,3 @@ message PortAndChannel { // channel string channel = 2; } - -// GenesisAccount is a struct for the genesis account for the rollapp -message GenesisAccount { - // amount of coins to be sent to the genesis address - cosmos.base.v1beta1.Coin amount = 1 [(gogoproto.nullable) = false]; - // address is a bech-32 address of the genesis account - string address = 2; -} diff --git a/testutil/app/app.go b/testutil/app/app.go index 0fe6c340..e0b244d0 100644 --- a/testutil/app/app.go +++ b/testutil/app/app.go @@ -454,28 +454,33 @@ func NewRollapp( keys[hubtypes.StoreKey], ) - denomMetadataMiddleware := denommetadata.NewICS4Wrapper( - app.IBCKeeper.ChannelKeeper, - app.HubKeeper, - app.BankKeeper, - app.HubGenesisKeeper.GetState, - ) - app.HubGenesisKeeper = hubgenkeeper.NewKeeper( appCodec, keys[hubgentypes.StoreKey], app.GetSubspace(hubgentypes.ModuleName), app.AccountKeeper, + app.BankKeeper, + app.MintKeeper, ) - genesisTransfersBlocker := hubgenkeeper.NewICS4Wrapper(denomMetadataMiddleware, app.HubGenesisKeeper) + // The IBC tranfer submit is wrapped with: + var ics4Wrapper ibcporttypes.ICS4Wrapper + // - denom metadata middleware + ics4Wrapper = denommetadata.NewICS4Wrapper( + app.IBCKeeper.ChannelKeeper, + app.HubKeeper, + app.BankKeeper, + app.HubGenesisKeeper.GetState, + ) + // - transfer rejecter until genesis bridge phase is finished + ics4Wrapper = hubgenkeeper.NewICS4Wrapper(ics4Wrapper, app.HubGenesisKeeper) // Create Transfer Keepers app.TransferKeeper = ibctransferkeeper.NewKeeper( appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName), - genesisTransfersBlocker, + ics4Wrapper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, @@ -494,9 +499,9 @@ func NewRollapp( ) transferStack = hubgenkeeper.NewIBCModule( transferStack, - app.TransferKeeper, app.HubGenesisKeeper, app.BankKeeper, + app.IBCKeeper.ChannelKeeper, ) app.GaslessKeeper = gaslesskeeper.NewKeeper( diff --git a/testutil/utils/test_app.go b/testutil/utils/test_app.go index 6c262f76..ead88328 100644 --- a/testutil/utils/test_app.go +++ b/testutil/utils/test_app.go @@ -19,8 +19,8 @@ import ( "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" app "github.com/dymensionxyz/dymension-rdk/testutil/app" - seqtypes "github.com/dymensionxyz/dymension-rdk/x/sequencers/types" + hubgenesistypes "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" rollappparamstypes "github.com/dymensionxyz/dymension-rdk/x/rollappparams/types" "github.com/stretchr/testify/require" @@ -33,9 +33,6 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" - - // unnamed import of statik for swagger UI support - _ "github.com/cosmos/cosmos-sdk/client/docs/statik" ) var DefaultConsensusParams = &abci.ConsensusParams{ @@ -92,34 +89,42 @@ func setup(withGenesis bool, invCheckPeriod uint) (*app.App, map[string]json.Raw log.NewNopLogger(), db, nil, true, map[int64]bool{}, "/tmp", invCheckPeriod, encCdc, app.GetEnabledProposals(), EmptyAppOptions{}, emptyWasmOpts, ) if withGenesis { + // override the rollapp version, so we'll have a valid default genesis + rollappparamstypes.Version = "5f8393904fb1e9c616fe89f013cafe7501a63f86" return testApp, app.NewDefaultGenesisState(encCdc.Codec) } return testApp, map[string]json.RawMessage{} } -// Setup initializes a new Rollapp. A Nop logger is set in Rollapp. -func Setup(t *testing.T, isCheckTx bool) *app.App { +// setGenesisAndInitChain contains the shared setup logic +func setGenesisAndInitChain(t *testing.T, app *app.App, genesisState map[string]json.RawMessage) { t.Helper() - app, genesisState := setup(true, 5) - - // setup for sequencer - seqGenesis := seqtypes.GenesisState{ - Params: seqtypes.DefaultParams(), - } - genesisState[seqtypes.ModuleName] = app.AppCodec().MustMarshalJSON(&seqGenesis) - - // setup for rollapp params - - rollappParamsGenesis := rollappparamstypes.GenesisState{ - Params: rollappparamstypes.NewParams("mock", "5f8393904fb1e9c616fe89f013cafe7501a63f86"), + // setting bank genesis as required for genesis bridge + nativeDenomMetadata := banktypes.Metadata{ + DenomUnits: []*banktypes.DenomUnit{ + { + Denom: "stake", + Exponent: 0, + }, + { + Denom: "TST", + Exponent: 18, + }, + }, + Base: "stake", + Display: "TST", } - genesisState[rollappparamstypes.ModuleName] = app.AppCodec().MustMarshalJSON(&rollappParamsGenesis) - // for now bank genesis won't be set here, funding accounts should be called with fund utils.FundModuleAccount + var bankGenesis banktypes.GenesisState + err := json.Unmarshal(genesisState[banktypes.ModuleName], &bankGenesis) + require.NoError(t, err) + bankGenesis.DenomMetadata = append(bankGenesis.DenomMetadata, nativeDenomMetadata) + genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(&bankGenesis) stateBytes, err := json.MarshalIndent(genesisState, "", " ") require.NoError(t, err) + // init chain will set the validator set and initialize the genesis accounts app.InitChain( abci.RequestInitChain{ @@ -133,7 +138,38 @@ func Setup(t *testing.T, isCheckTx bool) *app.App { InitialHeight: 0, }, ) +} + +func SetupWithGenesisBridge(t *testing.T, gbFunds sdk.Coin, genAcct []hubgenesistypes.GenesisAccount) *app.App { + t.Helper() + app, genesisState := setup(true, 5) + // Additional setup specific to SetupWithGenesisBridge + genesisBridgeFunds := []banktypes.Balance{ + { + Address: authtypes.NewModuleAddress(hubgenesistypes.ModuleName).String(), + Coins: sdk.NewCoins(gbFunds), + }, + } + + bankGenesis := banktypes.DefaultGenesisState() + bankGenesis.Balances = append(bankGenesis.Balances, genesisBridgeFunds...) + bankGenesis.Supply = sdk.NewCoins(gbFunds) + genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis) + + // set genesis transfer required accounts + genesisBridgeGenesisState := hubgenesistypes.DefaultGenesisState() + genesisBridgeGenesisState.GenesisAccounts = genAcct + genesisState[hubgenesistypes.ModuleName] = app.AppCodec().MustMarshalJSON(genesisBridgeGenesisState) + + setGenesisAndInitChain(t, app, genesisState) + return app +} + +func Setup(t *testing.T, isCheckTx bool) *app.App { + t.Helper() + app, genesisState := setup(true, 5) + setGenesisAndInitChain(t, app, genesisState) return app } @@ -141,14 +177,8 @@ func Setup(t *testing.T, isCheckTx bool) *app.App { // but unlike the other one, this one adds the sequencer to the genesis state on InitChain func SetupWithGenesisValSet(t *testing.T, chainID, rollAppDenom string, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances []banktypes.Balance) *app.App { t.Helper() - app, genesisState := setup(true, 5) - seqGenesis := seqtypes.GenesisState{ - Params: seqtypes.DefaultParams(), - } - genesisState[seqtypes.ModuleName] = app.AppCodec().MustMarshalJSON(&seqGenesis) - authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs) genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis) diff --git a/x/denommetadata/ibc_middleware.go b/x/denommetadata/ibc_middleware.go index 09473e59..95c27209 100644 --- a/x/denommetadata/ibc_middleware.go +++ b/x/denommetadata/ibc_middleware.go @@ -30,8 +30,10 @@ import ( type ICS4Wrapper struct { porttypes.ICS4Wrapper - hubKeeper types.HubKeeper - bankKeeper types.BankKeeper + hubKeeper types.HubKeeper + bankKeeper types.BankKeeper + + // TODO: refactor to `IsCanonicalHubTransferChannel` directly getHubGenState func(ctx sdk.Context) hgtypes.State } @@ -64,6 +66,7 @@ func (m *ICS4Wrapper) SendPacket( return 0, errorsmod.Wrapf(errortypes.ErrJSONUnmarshal, "unmarshal ICS-20 transfer packet data: %s", err.Error()) } + // don't send metadata on non-canonical channels if hubGenState := m.getHubGenState(ctx); !hubGenState.IsCanonicalHubTransferChannel(destinationPort, destinationChannel) { return m.ICS4Wrapper.SendPacket(ctx, chanCap, destinationPort, destinationChannel, timeoutHeight, timeoutTimestamp, data) } diff --git a/x/hub-genesis/keeper/genesis.go b/x/hub-genesis/keeper/genesis.go index 805a592c..7658d0fb 100644 --- a/x/hub-genesis/keeper/genesis.go +++ b/x/hub-genesis/keeper/genesis.go @@ -1,6 +1,9 @@ package keeper import ( + "fmt" + + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" ) @@ -8,9 +11,21 @@ import ( // InitGenesis new hub-genesis genesis. func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) { k.SetParams(ctx, genState.Params) - k.SetState(ctx, genState.State) - for _, seq := range genState.UnackedTransferSeqNums { - k.saveUnackedTransferSeqNum(ctx, seq) + k.SetState(ctx, types.State{}) + + err := k.PopulateGenesisInfo(ctx, genState.GenesisAccounts) + if err != nil { + panic(fmt.Sprintf("generate genesis info: %s", err)) + } + + // validate the funds in the module account are equal to the sum of the funds in the genesis accounts + expectedTotal := math.ZeroInt() + for _, acc := range genState.GenesisAccounts { + expectedTotal = expectedTotal.Add(acc.Amount) + } + balance := k.bk.GetBalance(ctx, k.ak.GetModuleAccount(ctx, types.ModuleName).GetAddress(), k.GetBaseDenom(ctx)) + if !balance.Amount.Equal(expectedTotal) { + panic("module account balance does not match the sum of genesis accounts") } } @@ -18,7 +33,6 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) { func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { genesis := types.DefaultGenesisState() genesis.Params = k.GetParams(ctx) - genesis.State = k.GetState(ctx) - genesis.UnackedTransferSeqNums = k.getAllUnackedTransferSeqNums(ctx) + genesis.GenesisAccounts = k.GetGenesisInfo(ctx).GenesisAccounts return genesis } diff --git a/x/hub-genesis/keeper/genesis_info.go b/x/hub-genesis/keeper/genesis_info.go new file mode 100644 index 00000000..e98159a2 --- /dev/null +++ b/x/hub-genesis/keeper/genesis_info.go @@ -0,0 +1,63 @@ +package keeper + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" +) + +// GetNativeDenom returns the native denomination. +func (k Keeper) GetBaseDenom(ctx sdk.Context) string { + return k.GetGenesisInfo(ctx).BaseDenom() +} + +// PopulateGenesisInfo populates the genesis info. This function is called during InitGenesis. +func (k Keeper) PopulateGenesisInfo(ctx sdk.Context, gAccounts []types.GenesisAccount) error { + // Query the bech32 prefix + bech32Prefix := sdk.GetConfig().GetBech32AccountAddrPrefix() + + // Query the native denom + nativeDenom := k.mk.MintDenom(ctx) + + // Query the denom's metadata + metadata, found := k.bk.GetDenomMetaData(ctx, nativeDenom) + if !found { + return fmt.Errorf("denom metadata not found for %s", nativeDenom) + } + + // Query the decimals of the denom + decimals := uint32(0) + for _, unit := range metadata.DenomUnits { + // guaranteed to exist in a valid denom metadata + if unit.Denom == metadata.Display { + decimals = unit.Exponent + break + } + } + if decimals == 0 { + return fmt.Errorf("denom metadata does not contain display unit %s", metadata.Display) + } + + // Query the initial supply + initialSupply := k.bk.GetSupply(ctx, nativeDenom).Amount + + // Create the genesis info + genesisInfo := types.GenesisInfo{ + // TODO: populate checksum value (https://github.com/dymensionxyz/dymension-rdk/issues/569) + GenesisChecksum: "checksum", // currently using a placeholder as we don't allow empty strings + Bech32Prefix: bech32Prefix, + NativeDenom: &types.DenomMetadata{ + Display: metadata.Display, + Base: metadata.Base, + Exponent: decimals, + }, + InitialSupply: initialSupply, + GenesisAccounts: gAccounts, + } + + // Set the genesis info + k.SetGenesisInfo(ctx, genesisInfo) + + return nil +} diff --git a/x/hub-genesis/keeper/genesis_info_test.go b/x/hub-genesis/keeper/genesis_info_test.go new file mode 100644 index 00000000..1ff193f6 --- /dev/null +++ b/x/hub-genesis/keeper/genesis_info_test.go @@ -0,0 +1,56 @@ +package keeper_test + +import ( + "testing" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + testkeepers "github.com/dymensionxyz/dymension-rdk/testutil/keepers" + "github.com/dymensionxyz/dymension-rdk/testutil/utils" + "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestInitGenesis_HappyFlow(t *testing.T) { + genesisBridgeFunds := sdk.NewCoin("stake", math.NewInt(100_000)) + genAccounts := []types.GenesisAccount{ + { + Address: utils.AccAddress().String(), + Amount: genesisBridgeFunds.Amount.QuoRaw(2), + }, + { + Address: utils.AccAddress().String(), + Amount: genesisBridgeFunds.Amount.QuoRaw(2), + }, + } + + app := utils.SetupWithGenesisBridge(t, genesisBridgeFunds, genAccounts) + k, ctx := testkeepers.NewTestHubGenesisKeeperFromApp(app) + + // change some state values post the genesis, make sure it doesn't affect the genesis info + utils.AddTestAddrs(app, ctx, 2, sdk.NewInt(1000)) + require.NotEqual(t, app.BankKeeper.GetSupply(ctx, "stake"), genesisBridgeFunds) + + gInfo := k.GetGenesisInfo(ctx) + assert.Equal(t, genAccounts, gInfo.GenesisAccounts) + // assert native denom + assert.Equal(t, genesisBridgeFunds.Denom, gInfo.NativeDenom.Base) + // assert initial supply + assert.Equal(t, genesisBridgeFunds.Amount, gInfo.InitialSupply) +} + +func TestInitGenesis_MissingGenesisFundsOnGenesis(t *testing.T) { + genesisBridgeFunds := sdk.NewCoin("stake", math.NewInt(100_000)) + genAccounts := []types.GenesisAccount{ + { + Address: utils.AccAddress().String(), + Amount: genesisBridgeFunds.Amount.MulRaw(2), // genesis account has more funds than the module account + }, + } + assert.Panics(t, func() { + utils.SetupWithGenesisBridge(t, genesisBridgeFunds, genAccounts) + }) +} + +// TODO: test for missing metadata on genesis diff --git a/x/hub-genesis/keeper/genesis_test.go b/x/hub-genesis/keeper/genesis_test.go deleted file mode 100644 index bb56a255..00000000 --- a/x/hub-genesis/keeper/genesis_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package keeper_test - -import ( - _ "embed" - "testing" - - testkeepers "github.com/dymensionxyz/dymension-rdk/testutil/keepers" - "github.com/dymensionxyz/dymension-rdk/testutil/utils" - "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" - "github.com/stretchr/testify/require" -) - -func TestGenesis(t *testing.T) { - app := utils.Setup(t, false) - k, ctx := testkeepers.NewTestHubGenesisKeeperFromApp(app) - - expect := &types.GenesisState{ - State: types.State{ - NumUnackedTransfers: 2, - }, - UnackedTransferSeqNums: []uint64{42, 43}, - } - k.InitGenesis(ctx, expect) - got := k.ExportGenesis(ctx) - require.NotNil(t, got) - - require.ElementsMatch(t, expect.UnackedTransferSeqNums, got.UnackedTransferSeqNums) - require.Equal(t, expect.State.NumUnackedTransfers, got.State.NumUnackedTransfers) -} diff --git a/x/hub-genesis/keeper/genesis_transfer.go b/x/hub-genesis/keeper/genesis_transfer.go new file mode 100644 index 00000000..6159f5fb --- /dev/null +++ b/x/hub-genesis/keeper/genesis_transfer.go @@ -0,0 +1,52 @@ +package keeper + +import ( + errorsmod "cosmossdk.io/errors" + "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" + + "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" +) + +const ( + // hubRecipient is the address of `x/rollapp` module's account on the hub chain. + hubRecipient = "dym1mk7pw34ypusacm29m92zshgxee3yreums8avur" +) + +// PrepareGenesisTransfer prepares the genesis transfer packet. +// It returns the packet data if the genesis accounts are defined, otherwise it returns nil. +// The transfer funds are escrowed explicitly in this method. +func (k Keeper) PrepareGenesisTransfer(ctx sdk.Context, portID, channelID string) (*transfertypes.FungibleTokenPacketData, error) { + gAccounts := k.GetGenesisInfo(ctx).GenesisAccounts + amount := math.ZeroInt() + for _, acc := range gAccounts { + amount = amount.Add(acc.Amount) + } + + // no genesis accounts defined => no genesis transfer needed + if amount.IsZero() { + return nil, nil + } + + sender := k.ak.GetModuleAccount(ctx, types.ModuleName).GetAddress().String() + denom := k.GetBaseDenom(ctx) + + // As we don't use the `ibc/transfer` module, we need to handle the funds escrow ourselves + err := k.EscrowGenesisTransferFunds(ctx, portID, channelID, sdk.NewCoin(denom, amount)) + if err != nil { + return nil, errorsmod.Wrap(err, "escrow genesis transfer funds") + } + + packet := transfertypes.NewFungibleTokenPacketData(denom, amount.String(), sender, hubRecipient, "") + return &packet, nil +} + +// EscrowGenesisTransferFunds escrows the genesis transfer funds. +// The code is copied from the `transfer` module's `Keeper.sendTransfer` method. +func (k Keeper) EscrowGenesisTransferFunds(ctx sdk.Context, portID, channelID string, token sdk.Coin) error { + escrowAddress := transfertypes.GetEscrowAddress(portID, channelID) + sender := k.ak.GetModuleAccount(ctx, types.ModuleName).GetAddress() + return k.bk.SendCoins(ctx, sender, escrowAddress, sdk.NewCoins(token)) +} diff --git a/x/hub-genesis/keeper/genesis_transfer_test.go b/x/hub-genesis/keeper/genesis_transfer_test.go new file mode 100644 index 00000000..41cd0c0f --- /dev/null +++ b/x/hub-genesis/keeper/genesis_transfer_test.go @@ -0,0 +1,47 @@ +package keeper_test + +import ( + "testing" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + testkeepers "github.com/dymensionxyz/dymension-rdk/testutil/keepers" + "github.com/dymensionxyz/dymension-rdk/testutil/utils" + "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestGenesisTransferCreation(t *testing.T) { + genesisBridgeFunds := sdk.NewCoin("stake", math.NewInt(100_000)) + genAccounts := []types.GenesisAccount{ + { + Address: utils.AccAddress().String(), + Amount: genesisBridgeFunds.Amount.QuoRaw(2), + }, + { + Address: utils.AccAddress().String(), + Amount: genesisBridgeFunds.Amount.QuoRaw(2), + }, + } + + app := utils.SetupWithGenesisBridge(t, genesisBridgeFunds, genAccounts) + k, ctx := testkeepers.NewTestHubGenesisKeeperFromApp(app) + + packet, err := k.PrepareGenesisTransfer(ctx, "porttransfer", "channel-0") + require.NoError(t, err) + require.NotNil(t, packet) + + assert.Equal(t, "stake", packet.Denom) + assert.Equal(t, genesisBridgeFunds.Amount.String(), packet.Amount) + assert.Equal(t, app.AccountKeeper.GetModuleAddress(types.ModuleName).String(), packet.Sender) +} + +func TestGenesisTransferCreation_NoGenesisAccounts(t *testing.T) { + app := utils.Setup(t, false) + k, ctx := testkeepers.NewTestHubGenesisKeeperFromApp(app) + + packet, err := k.PrepareGenesisTransfer(ctx, "porttransfer", "channel-0") + require.NoError(t, err) + require.Nil(t, packet) +} diff --git a/x/hub-genesis/keeper/grpc_query.go b/x/hub-genesis/keeper/grpc_query.go index 0f1e37a4..2a2936e3 100644 --- a/x/hub-genesis/keeper/grpc_query.go +++ b/x/hub-genesis/keeper/grpc_query.go @@ -20,15 +20,14 @@ func NewQuerier(k Keeper) Querier { return Querier{Keeper: k} } -// Params returns params of the hub-genesis module. -func (q Querier) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { - ctx := sdk.UnwrapSDKContext(c) - params := q.Keeper.GetParams(ctx) +func (q Querier) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + return &types.QueryParamsResponse{Params: q.Keeper.GetParams(sdk.UnwrapSDKContext(ctx))}, nil +} - return &types.QueryParamsResponse{Params: params}, nil +func (q Querier) State(ctx context.Context, _ *types.QueryStateRequest) (*types.QueryStateResponse, error) { + return &types.QueryStateResponse{State: q.Keeper.GetState(sdk.UnwrapSDKContext(ctx))}, nil } -func (q Querier) State(goCtx context.Context, request *types.QueryStateRequest) (*types.QueryStateResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - return &types.QueryStateResponse{State: q.Keeper.GetState(ctx)}, nil +func (q Querier) GenesisInfo(ctx context.Context, _ *types.QueryGenesisInfoRequest) (*types.QueryGenesisInfoResponse, error) { + return &types.QueryGenesisInfoResponse{GenesisInfo: q.Keeper.GetGenesisInfo(sdk.UnwrapSDKContext(ctx))}, nil } diff --git a/x/hub-genesis/keeper/ibc_module.go b/x/hub-genesis/keeper/ibc_module.go index abecf1b2..ceff0a10 100644 --- a/x/hub-genesis/keeper/ibc_module.go +++ b/x/hub-genesis/keeper/ibc_module.go @@ -1,55 +1,40 @@ package keeper import ( - "context" "errors" - "fmt" "time" errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types" - "github.com/dymensionxyz/gerr-cosmos/gerrc" "github.com/tendermint/tendermint/libs/log" "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" + "github.com/dymensionxyz/gerr-cosmos/gerrc" ) -const ( - transferTimeout = time.Hour * 24 * 365 -) +var transferTimeout = (time.Duration(24*365) * time.Hour) // very long timeout type IBCModule struct { porttypes.IBCModule - k Keeper - transfer TransferKeeper - bank BankKeeper -} - -type TransferKeeper interface { - Transfer(goCtx context.Context, msg *transfertypes.MsgTransfer) (*transfertypes.MsgTransferResponse, error) + k Keeper + bank types.BankKeeper + channelKeeper types.ChannelKeeper } -type BankKeeper interface { - GetDenomMetaData(ctx sdk.Context, denom string) (banktypes.Metadata, bool) - MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error -} - -func NewIBCModule(next porttypes.IBCModule, t TransferKeeper, k Keeper, bank BankKeeper) *IBCModule { - return &IBCModule{next, k, t, bank} +func NewIBCModule(next porttypes.IBCModule, k Keeper, bank types.BankKeeper, chanKeeper types.ChannelKeeper) *IBCModule { + return &IBCModule{next, k, bank, chanKeeper} } func (w IBCModule) logger(ctx sdk.Context) log.Logger { - return w.k.Logger(ctx).With("module", types.ModuleName, "component", "ibc module") + return w.k.Logger(ctx) } -// OnChanOpenConfirm will send any unsent genesis account transfers over the channel. -// It is ASSUMED that the channel is for the Hub. This can be ensured by not exposing -// the sequencer API until after genesis is complete. +// On successful OnChanOpenConfirm for the canonical channel, the genesis bridge flow will be initiated. +// It will prepare the genesis bridge data and send it over the channel. +// The genesis bridge data includes the genesis info, the native denom metadata, and the genesis transfer packet. // Since transfers are only sent once, it does not matter if someone else tries to open // a channel in future (it will no-op). func (w IBCModule) OnChanOpenConfirm( @@ -57,84 +42,67 @@ func (w IBCModule) OnChanOpenConfirm( portID, channelID string, ) error { - l := ctx.Logger().With("module", "hubgenesis OnChanOpenConfirm middleware", "port id", portID, "channelID", channelID) - err := w.IBCModule.OnChanOpenConfirm(ctx, portID, channelID) if err != nil { return err } state := w.k.GetState(ctx) - if state.CanonicalHubTransferChannelHasBeenSet() { // We only set the canonical channel in this function, so if it's already been set, we don't need // to send the transfers again. return nil } - state.SetCanonicalTransferChannel(portID, channelID) - - state.NumUnackedTransfers = uint64(len(state.GetGenesisAccounts())) - - w.k.SetState(ctx, state) - - if len(state.GetGenesisAccounts()) == 0 { - // we want to handle the case where the rollapp doesn't have genesis transfers - // normally we would enable outbound transfers on an ack, but in this case we won't have an ack - w.k.enableOutboundTransfers(ctx) - return nil - } - - srcAccount := w.k.accountKeeper.GetModuleAccount(ctx, types.ModuleName) - srcAddr := srcAccount.GetAddress().String() - - for i, a := range state.GetGenesisAccounts() { - if err := w.mintAndTransfer(ctx, a, srcAddr, portID, channelID); err != nil { - // there is no feasible way to recover - panic(fmt.Errorf("mint and transfer: %w", err)) - } - l.Info("Sent genesis transfer.", "index", i, "receiver", a.GetAddress(), "coin", a) + seq, err := w.SubmitGenesisBridgeData(ctx, portID, channelID) + if err != nil { + return errorsmod.Wrap(err, "submit genesis bridge data") } - l.Info("Sent all genesis transfers.", "n", len(state.GetGenesisAccounts())) + state.SetCanonicalTransferChannel(portID, channelID) + w.k.SetState(ctx, state) + w.logger(ctx).Info("genesis bridge data submitted", "sequence", seq, "port", portID, "channel", channelID) return nil } -func (w IBCModule) mintAndTransfer(ctx sdk.Context, account types.GenesisAccount, srcAddr string, portID string, channelID string) error { - coin := account.GetAmount() - err := w.bank.MintCoins(ctx, types.ModuleName, sdk.Coins{coin}) +// SubmitGenesisBridgeData sends the genesis bridge data over the channel. +// The genesis bridge data includes the genesis info, the native denom metadata, and the genesis transfer packet. +// It uses the channel keeper to send the packet, instead of transfer keeper, as we are not sending fungible token directly. +func (w IBCModule) SubmitGenesisBridgeData(ctx sdk.Context, portID string, channelID string) (seq uint64, err error) { + _, chanCap, err := w.channelKeeper.LookupModuleByChannel(ctx, portID, channelID) if err != nil { - return errorsmod.Wrap(err, "mint coins") + return } - // NOTE: for simplicity we don't optimize to avoid sending duplicate metadata - // we assume the hub will deduplicate. We expect to eventually get a timeout - // or commit anyway, so the packet will be cleared up. - // (Actually, since transfers may arrive out of order, we must include the - // denom metadata anyway). - memo, err := w.createMemo(ctx, account.Amount.Denom) + // prepare genesis info + gInfo := w.k.GetGenesisInfo(ctx) + + // prepare the denom metadata + d, ok := w.bank.GetDenomMetaData(ctx, gInfo.BaseDenom()) + if !ok { + return 0, errorsmod.Wrap(gerrc.ErrInternal, "denom metadata not found") + } + + // prepare the genesis transfer + genesisTransferPacket, err := w.k.PrepareGenesisTransfer(ctx, portID, channelID) if err != nil { - return errorsmod.Wrap(err, "create memo") + return 0, errorsmod.Wrap(err, "genesis transfer") } - m := transfertypes.MsgTransfer{ - SourcePort: portID, - SourceChannel: channelID, - Token: account.Amount, - Sender: srcAddr, - Receiver: account.GetAddress(), - TimeoutHeight: clienttypes.Height{}, - TimeoutTimestamp: uint64(ctx.BlockTime().Add(transferTimeout).UnixNano()), - Memo: memo, + data := &types.GenesisBridgeData{ + GenesisInfo: gInfo, + NativeDenom: d, + GenesisTransfer: genesisTransferPacket, } - res, err := w.transfer.Transfer(sdk.WrapSDKContext(allowSpecialMemoCtx(ctx)), &m) + bz, err := data.Marshal() if err != nil { - return errorsmod.Wrap(err, "transfer") + return 0, errorsmod.Wrap(err, "marshal genesis bridge data") } - w.k.saveUnackedTransferSeqNum(ctx, res.Sequence) - return nil + + timeoutTimestamp := ctx.BlockTime().Add(transferTimeout).UnixNano() + return w.channelKeeper.SendPacket(ctx, chanCap, portID, channelID, clienttypes.ZeroHeight(), uint64(timeoutTimestamp), bz) } func (w IBCModule) OnAcknowledgementPacket( @@ -143,33 +111,33 @@ func (w IBCModule) OnAcknowledgementPacket( acknowledgement []byte, relayer sdk.AccAddress, ) error { - l := w.logger(ctx) state := w.k.GetState(ctx) - if !state.IsCanonicalHubTransferChannel(packet.SourcePort, packet.SourceChannel) { - return w.IBCModule.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer) - } - + // if outbound transfers are enabled, we past the genesis phase. nothing to do here. if state.OutboundTransfersEnabled { return w.IBCModule.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer) } - var data transfertypes.FungibleTokenPacketData - err := transfertypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &data) - if err != nil { - return err - } - var ack channeltypes.Acknowledgement - err = types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack) + err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack) if err != nil { return err } - err = w.k.ackTransferSeqNum(ctx, packet.Sequence, ack) - if err != nil { - l.Error("Processing ack from transfer.", "err", err) - return errorsmod.Wrap(errors.Join(err, gerrc.ErrUnknown), "ack transfer seq num") + if !ack.Success() { + w.logger(ctx).Error("acknowledgement failed for genesis transfer", "packet", packet, "ack", ack) + return errors.New("acknowledgement failed for genesis transfer") } - return w.IBCModule.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer) + + w.k.enableBridge(ctx, state) + ctx.EventManager().EmitEvent(sdk.NewEvent(types.EventTypeOutboundTransfersEnabled)) + w.logger(ctx).Info("genesis bridge phase completed successfully") + + return nil +} + +// enableBridge enables the bridge after successful genesis bridge phase. +func (k Keeper) enableBridge(ctx sdk.Context, state types.State) { + state.OutboundTransfersEnabled = true + k.SetState(ctx, state) } diff --git a/x/hub-genesis/keeper/ics4_wrapper.go b/x/hub-genesis/keeper/ics4_wrapper.go deleted file mode 100644 index f60378a3..00000000 --- a/x/hub-genesis/keeper/ics4_wrapper.go +++ /dev/null @@ -1,71 +0,0 @@ -package keeper - -import ( - errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" - clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" - porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types" - "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" - "github.com/dymensionxyz/gerr-cosmos/gerrc" - "github.com/tendermint/tendermint/libs/log" -) - -type ctxKeySkip struct{} - -// allowSpecialMemoCtx returns a context which can be passed to ibc SendPacket -// if passed, the memo guard will not check that call -func allowSpecialMemoCtx(ctx sdk.Context) sdk.Context { - return ctx.WithValue(ctxKeySkip{}, true) -} - -func allowSpecialMemo(ctx sdk.Context) bool { - val, ok := ctx.Value(ctxKeySkip{}).(bool) - return ok && val -} - -type ICS4Wrapper struct { - porttypes.ICS4Wrapper - k Keeper -} - -func NewICS4Wrapper(next porttypes.ICS4Wrapper, k Keeper) *ICS4Wrapper { - return &ICS4Wrapper{next, k} -} - -func (w ICS4Wrapper) logger(ctx sdk.Context) log.Logger { - return w.k.Logger(ctx).With("module", types.ModuleName, "component", "ics4 middleware") -} - -// SendPacket does two things: -// 1. It stops anyone from sending a packet with the special memo. Only the module itself is allowed to do so. -// 2. It stops anyone from sending a regular transfer until the genesis phase is finished. To help with this, -// it tracks all acks which arrive from genesis transfers. -func (w ICS4Wrapper) SendPacket( - ctx sdk.Context, - chanCap *capabilitytypes.Capability, - sourcePort string, - sourceChannel string, - timeoutHeight clienttypes.Height, - timeoutTimestamp uint64, - data []byte, -) (sequence uint64, err error) { - l := w.logger(ctx) - - state := w.k.GetState(ctx) - var transfer transfertypes.FungibleTokenPacketData - _ = transfertypes.ModuleCdc.UnmarshalJSON(data, &transfer) - specialMemo := memoHasKey(transfer.GetMemo()) - - if specialMemo && !allowSpecialMemo(ctx) { - return 0, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "cannot use transfer genesis memo") - } - if !(specialMemo || state.OutboundTransfersEnabled) { - l.Debug("Transfer rejected: outbound transfers are disabled.") - return 0, errorsmod.Wrap(gerrc.ErrFailedPrecondition, "genesis phase not finished") - } - - return w.ICS4Wrapper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data) -} diff --git a/x/hub-genesis/keeper/keeper.go b/x/hub-genesis/keeper/keeper.go index 57a93b6b..c538c84d 100644 --- a/x/hub-genesis/keeper/keeper.go +++ b/x/hub-genesis/keeper/keeper.go @@ -18,29 +18,91 @@ type Keeper struct { storeKey storetypes.StoreKey paramstore paramtypes.Subspace - accountKeeper types.AuthAccountKeeper + ak types.AccountKeeper + bk types.BankKeeper + mk types.MintKeeper } func NewKeeper( cdc codec.BinaryCodec, storeKey storetypes.StoreKey, ps paramtypes.Subspace, - accountKeeper types.AuthAccountKeeper, + ak types.AccountKeeper, + bk types.BankKeeper, + mk types.MintKeeper, ) Keeper { // set KeyTable if it has not already been set if !ps.HasKeyTable() { table := types.ParamKeyTable() ps = ps.WithKeyTable(table) } + if ak == nil { + panic("account keeper cannot be nil") + } + if bk == nil { + panic("bank keeper cannot be nil") + } + if mk == nil { + panic("mint keeper cannot be nil") + } return Keeper{ - cdc: cdc, - storeKey: storeKey, - paramstore: ps, - accountKeeper: accountKeeper, + cdc: cdc, + storeKey: storeKey, + paramstore: ps, + ak: ak, + bk: bk, + mk: mk, } } func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } + +// SetState sets the state. +func (k Keeper) SetState(ctx sdk.Context, state types.State) { + store := ctx.KVStore(k.storeKey) + store.Set(types.StateKey, k.cdc.MustMarshal(&state)) +} + +// GetState returns the state. +func (k Keeper) GetState(ctx sdk.Context) types.State { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.StateKey) + if bz == nil { + return types.State{} + } + var state types.State + k.cdc.MustUnmarshal(bz, &state) + return state +} + +// GetParams returns the total set of minting parameters. +func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { + k.paramstore.GetParamSet(ctx, ¶ms) + return params +} + +// SetParams sets the total set of minting parameters. +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { + k.paramstore.SetParamSet(ctx, ¶ms) +} + +// SetGenesisInfo sets the genesis info. +func (k Keeper) SetGenesisInfo(ctx sdk.Context, gInfo types.GenesisInfo) { + store := ctx.KVStore(k.storeKey) + store.Set(types.GenesisInfoKey, k.cdc.MustMarshal(&gInfo)) +} + +// GetGenesisInfo returns the genesis info. +func (k Keeper) GetGenesisInfo(ctx sdk.Context) types.GenesisInfo { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.GenesisInfoKey) + if bz == nil { + return types.GenesisInfo{} + } + var gInfo types.GenesisInfo + k.cdc.MustUnmarshal(bz, &gInfo) + return gInfo +} diff --git a/x/hub-genesis/keeper/memo.go b/x/hub-genesis/keeper/memo.go deleted file mode 100644 index 9e3f5066..00000000 --- a/x/hub-genesis/keeper/memo.go +++ /dev/null @@ -1,50 +0,0 @@ -package keeper - -import ( - "encoding/json" - - "cosmossdk.io/errors" - - "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" -) - -const ( - memoNamespaceKey = "genesis_transfer" -) - -func memoHasKey(memo string) bool { - m := make(map[string]any) - if err := json.Unmarshal([]byte(memo), &m); err != nil { - return false - } - _, ok := m[memoNamespaceKey] - return ok -} - -// createMemo creates a memo to go with the transfer. It's used by the hub to confirm -// that the transfer originated from the chain itself, rather than a user of the chain. -// It may also contain token metadata. -func (w IBCModule) createMemo(ctx types.Context, denom string) (string, error) { - d, ok := w.bank.GetDenomMetaData(ctx, denom) - if !ok { - return "", errors.Wrap(sdkerrors.ErrNotFound, "get denom metadata") - } - - m := memo{} - m.Data.Denom = d - - bz, err := json.Marshal(m) - if err != nil { - return "", sdkerrors.ErrJSONMarshal - } - - return string(bz), nil -} - -type memo struct { - Data struct { - Denom banktypes.Metadata `json:"denom"` - } `json:"genesis_transfer"` -} diff --git a/x/hub-genesis/keeper/params.go b/x/hub-genesis/keeper/params.go deleted file mode 100644 index b7dd1bbf..00000000 --- a/x/hub-genesis/keeper/params.go +++ /dev/null @@ -1,18 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" -) - -// GetParams returns the total set of minting parameters. -func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { - k.paramstore.GetParamSet(ctx, ¶ms) - return params -} - -// SetParams sets the total set of minting parameters. -func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { - k.paramstore.SetParamSet(ctx, ¶ms) -} diff --git a/x/hub-genesis/keeper/sequence_numbers.go b/x/hub-genesis/keeper/sequence_numbers.go deleted file mode 100644 index 66635eee..00000000 --- a/x/hub-genesis/keeper/sequence_numbers.go +++ /dev/null @@ -1,85 +0,0 @@ -package keeper - -import ( - errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types" - "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" - "github.com/dymensionxyz/gerr-cosmos/gerrc" -) - -/* -Whenever a genesis transfer is sent, we record the sequence number. We do not allow transfers until -all acks have been received with success. - -We use an O(1) access pattern, because we don't place a limit on the number of genesis accounts. -*/ - -var UnackedTransferSeqNumsPrefix = []byte("unacked_seqs") - -func seqNumKey(seq uint64) []byte { - bz := make([]byte, len(UnackedTransferSeqNumsPrefix)) - copy(bz, UnackedTransferSeqNumsPrefix) - bz = append(bz, sdk.Uint64ToBigEndian(seq)...) - return bz -} - -func seqNumFromKey(key []byte) uint64 { - return sdk.BigEndianToUint64(key[len(UnackedTransferSeqNumsPrefix):]) -} - -func (k Keeper) saveUnackedTransferSeqNum(ctx sdk.Context, seq uint64) { - ctx.KVStore(k.storeKey).Set(seqNumKey(seq), []byte{}) -} - -func (k Keeper) delUnackedTransferSeqNum(ctx sdk.Context, seq uint64) { - ctx.KVStore(k.storeKey).Delete(seqNumKey(seq)) -} - -func (k Keeper) hasUnackedTransferSeqNum(ctx sdk.Context, seq uint64) bool { - return ctx.KVStore(k.storeKey).Has(seqNumKey(seq)) -} - -// returns all seq nums, only intended for genesis export -func (k Keeper) getAllUnackedTransferSeqNums(ctx sdk.Context) []uint64 { - state := k.GetState(ctx) - n := state.NumUnackedTransfers - ret := make([]uint64, 0, n) - store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, UnackedTransferSeqNumsPrefix) - defer iterator.Close() // nolint: errcheck - for ; iterator.Valid(); iterator.Next() { - ret = append(ret, seqNumFromKey(iterator.Key())) - } - return ret -} - -// ackTransferSeqNum handles the inbound acknowledgement of an outbound genesis transfer -func (k Keeper) ackTransferSeqNum(ctx sdk.Context, seq uint64, ack channeltypes.Acknowledgement) error { - if !ack.Success() { - res, ok := ack.Response.(*channeltypes.Acknowledgement_Error) - if !ok { - return errorsmod.WithType(gerrc.ErrInvalidArgument, ack) - } - return errorsmod.Wrapf(gerrc.ErrUnknown, "ack is not success: %s", res.Error) - } - if k.hasUnackedTransferSeqNum(ctx, seq) { - k.delUnackedTransferSeqNum(ctx, seq) - state := k.GetState(ctx) - state.NumUnackedTransfers-- - k.SetState(ctx, state) - if state.NumUnackedTransfers == 0 { - // all acks have come back successfully - k.enableOutboundTransfers(ctx) - } - } - return nil -} - -func (k Keeper) enableOutboundTransfers(ctx sdk.Context) { - state := k.GetState(ctx) - state.OutboundTransfersEnabled = true - k.SetState(ctx, state) - ctx.EventManager().EmitEvent(sdk.NewEvent(types.EventTypeOutboundTransfersEnabled)) - k.Logger(ctx).With("module", types.ModuleName).Debug("Enabled outbound transfers.") -} diff --git a/x/hub-genesis/keeper/state.go b/x/hub-genesis/keeper/state.go deleted file mode 100644 index e327d78f..00000000 --- a/x/hub-genesis/keeper/state.go +++ /dev/null @@ -1,24 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" -) - -// SetState sets the state. -func (k Keeper) SetState(ctx sdk.Context, state types.State) { - store := ctx.KVStore(k.storeKey) - store.Set(types.StateKey, k.cdc.MustMarshal(&state)) -} - -// GetState returns the state. -func (k Keeper) GetState(ctx sdk.Context) types.State { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.StateKey) - if bz == nil { - return types.State{} - } - var state types.State - k.cdc.MustUnmarshal(bz, &state) - return state -} diff --git a/x/hub-genesis/keeper/transfer_enable_ics4_wrapper.go b/x/hub-genesis/keeper/transfer_enable_ics4_wrapper.go new file mode 100644 index 00000000..f9da1498 --- /dev/null +++ b/x/hub-genesis/keeper/transfer_enable_ics4_wrapper.go @@ -0,0 +1,45 @@ +package keeper + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" + porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types" + "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types" + "github.com/dymensionxyz/gerr-cosmos/gerrc" + "github.com/tendermint/tendermint/libs/log" +) + +type ICS4Wrapper struct { + porttypes.ICS4Wrapper + k Keeper +} + +func NewICS4Wrapper(next porttypes.ICS4Wrapper, k Keeper) *ICS4Wrapper { + return &ICS4Wrapper{next, k} +} + +func (w ICS4Wrapper) logger(ctx sdk.Context) log.Logger { + return w.k.Logger(ctx).With("module", types.ModuleName, "component", "ics4 middleware") +} + +// SendPacket is a wrapper around the ICS4Wrapper.SendPacket method. +// It will reject outbound transfers until the genesis bridge phase is finished. +func (w ICS4Wrapper) SendPacket( + ctx sdk.Context, + chanCap *capabilitytypes.Capability, + sourcePort string, + sourceChannel string, + timeoutHeight clienttypes.Height, + timeoutTimestamp uint64, + data []byte, +) (sequence uint64, err error) { + state := w.k.GetState(ctx) + if !state.OutboundTransfersEnabled { + w.logger(ctx).Info("Transfer rejected: outbound transfers are disabled.") + return 0, errorsmod.Wrap(gerrc.ErrFailedPrecondition, "genesis phase not finished") + } + + return w.ICS4Wrapper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data) +} diff --git a/x/hub-genesis/module.go b/x/hub-genesis/module.go index 43e64dd3..fc55ac6f 100644 --- a/x/hub-genesis/module.go +++ b/x/hub-genesis/module.go @@ -68,7 +68,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingCo return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) } - return types.ValidateGenesis(data) + return data.ValidateBasic() } // RegisterRESTRoutes registers the REST routes for the hub-genesis module. diff --git a/x/hub-genesis/types/expected_keepers.go b/x/hub-genesis/types/expected_keepers.go index 2a9df5c7..5df837c2 100644 --- a/x/hub-genesis/types/expected_keepers.go +++ b/x/hub-genesis/types/expected_keepers.go @@ -3,9 +3,30 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types" + + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) -// AuthAccountKeeper defines the contract required for account APIs. -type AuthAccountKeeper interface { +// AccountKeeper defines the contract required for account APIs. +type AccountKeeper interface { GetModuleAccount(ctx sdk.Context, moduleName string) types.ModuleAccountI } + +// ChannelKeeper defines the expected IBC channel keeper +type ChannelKeeper interface { + porttypes.ICS4Wrapper + LookupModuleByChannel(ctx sdk.Context, portID, channelID string) (string, *capabilitytypes.Capability, error) +} + +type BankKeeper interface { + GetDenomMetaData(ctx sdk.Context, denom string) (banktypes.Metadata, bool) + GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin + GetSupply(ctx sdk.Context, denom string) sdk.Coin + SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error +} + +type MintKeeper interface { + MintDenom(ctx sdk.Context) string +} diff --git a/x/hub-genesis/types/genesis.go b/x/hub-genesis/types/genesis.go index 1a3cc1ca..b4d03c0d 100644 --- a/x/hub-genesis/types/genesis.go +++ b/x/hub-genesis/types/genesis.go @@ -1,36 +1,23 @@ package types -import ( - errorsmod "cosmossdk.io/errors" - "github.com/dymensionxyz/gerr-cosmos/gerrc" -) - -// NewGenesisState creates a new GenesisState object. -func NewGenesisState(params Params, state State) *GenesisState { - return &GenesisState{ - Params: params, - State: state, - } -} - // DefaultGenesisState creates a default GenesisState object. func DefaultGenesisState() *GenesisState { - return NewGenesisState(DefaultParams(), State{}) + return &GenesisState{ + Params: DefaultParams(), + GenesisAccounts: []GenesisAccount{}, + } } -// ValidateGenesis validates the provided genesis state to ensure the -// expected invariants holds. -func ValidateGenesis(data GenesisState) error { - if err := data.Params.Validate(); err != nil { +// ValidateBasic performs basic validation of the genesis state. +func (g GenesisState) ValidateBasic() error { + if err := g.Params.Validate(); err != nil { return err } - if err := data.State.Validate(); err != nil { - return err - } - nSeqsExpected := data.State.NumUnackedTransfers - nSeqsHave := uint64(len(data.UnackedTransferSeqNums)) - if nSeqsExpected != nSeqsHave { - return errorsmod.Wrapf(gerrc.ErrInvalidArgument, "got different number of unacked transfers than expected: expect: %d, actual: %d", nSeqsExpected, nSeqsHave) + + for _, acc := range g.GenesisAccounts { + if err := acc.ValidateBasic(); err != nil { + return err + } } return nil diff --git a/x/hub-genesis/types/genesis.pb.go b/x/hub-genesis/types/genesis.pb.go index ec91b51f..061dca67 100644 --- a/x/hub-genesis/types/genesis.pb.go +++ b/x/hub-genesis/types/genesis.pb.go @@ -26,9 +26,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the hub-genesis module's genesis state. type GenesisState struct { // params defines all the parameters of the module. - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` - State State `protobuf:"bytes,2,opt,name=state,proto3" json:"state"` - UnackedTransferSeqNums []uint64 `protobuf:"varint,3,rep,packed,name=unacked_transfer_seq_nums,json=unackedTransferSeqNums,proto3" json:"unacked_transfer_seq_nums,omitempty"` + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + // accounts on the Hub to fund with some bootstrapping transfers + GenesisAccounts []GenesisAccount `protobuf:"bytes,2,rep,name=genesis_accounts,json=genesisAccounts,proto3" json:"genesis_accounts"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -71,16 +71,9 @@ func (m *GenesisState) GetParams() Params { return Params{} } -func (m *GenesisState) GetState() State { +func (m *GenesisState) GetGenesisAccounts() []GenesisAccount { if m != nil { - return m.State - } - return State{} -} - -func (m *GenesisState) GetUnackedTransferSeqNums() []uint64 { - if m != nil { - return m.UnackedTransferSeqNums + return m.GenesisAccounts } return nil } @@ -92,25 +85,23 @@ func init() { func init() { proto.RegisterFile("hub-genesis/genesis.proto", fileDescriptor_6deac3d79fd587fe) } var fileDescriptor_6deac3d79fd587fe = []byte{ - // 282 bytes of a gzipped FileDescriptorProto + // 251 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcc, 0x28, 0x4d, 0xd2, 0x4d, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x87, 0xd2, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xc2, 0x45, 0xf9, 0x39, 0x39, 0x89, 0x05, 0x05, 0x7a, 0x19, 0xa5, 0x49, 0xf1, 0x50, 0x29, 0x29, 0x91, 0xf4, 0xfc, 0xf4, 0x7c, 0xb0, 0xbc, 0x3e, 0x88, 0x05, 0x51, 0x2a, 0x25, 0x81, 0x6c, - 0x4a, 0x41, 0x62, 0x51, 0x62, 0x2e, 0xd4, 0x10, 0x29, 0x71, 0x64, 0x99, 0xe2, 0x92, 0xc4, 0x92, - 0x54, 0x88, 0x84, 0xd2, 0x21, 0x46, 0x2e, 0x1e, 0x77, 0x88, 0x78, 0x30, 0x48, 0x58, 0xc8, 0x92, - 0x8b, 0x0d, 0xa2, 0x53, 0x82, 0x51, 0x81, 0x51, 0x83, 0xdb, 0x48, 0x5a, 0x0f, 0x8b, 0xfd, 0x7a, - 0x01, 0x60, 0x25, 0x4e, 0x2c, 0x27, 0xee, 0xc9, 0x33, 0x04, 0x41, 0x35, 0x08, 0x99, 0x71, 0xb1, - 0x82, 0x8d, 0x96, 0x60, 0x02, 0xeb, 0x94, 0xc2, 0xaa, 0x13, 0x6c, 0x0b, 0x54, 0x23, 0x44, 0xb9, - 0x90, 0x3d, 0x97, 0x64, 0x69, 0x5e, 0x62, 0x72, 0x76, 0x6a, 0x4a, 0x7c, 0x49, 0x51, 0x62, 0x5e, - 0x71, 0x5a, 0x6a, 0x51, 0x7c, 0x71, 0x6a, 0x61, 0x7c, 0x5e, 0x69, 0x6e, 0xb1, 0x04, 0xb3, 0x02, - 0xb3, 0x06, 0x0b, 0x54, 0xbd, 0x18, 0x54, 0x59, 0x08, 0x54, 0x55, 0x70, 0x6a, 0xa1, 0x5f, 0x69, - 0x6e, 0xb1, 0x53, 0xf0, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, - 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x59, 0xa6, - 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0xa7, 0x54, 0xe6, 0xa6, 0xe6, 0x15, - 0x67, 0xe6, 0xe7, 0x55, 0x54, 0x56, 0x21, 0x38, 0xba, 0x45, 0x29, 0xd9, 0xfa, 0x15, 0xfa, 0xc8, - 0xe1, 0x53, 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0x0e, 0x20, 0x63, 0x40, 0x00, 0x00, 0x00, - 0xff, 0xff, 0x63, 0x8d, 0x1f, 0x86, 0x9b, 0x01, 0x00, 0x00, + 0x4a, 0x41, 0x62, 0x51, 0x62, 0x2e, 0xd4, 0x10, 0x29, 0x39, 0x2c, 0xe6, 0xc7, 0x67, 0xe6, 0xa5, + 0x41, 0x75, 0x2a, 0xcd, 0x67, 0xe4, 0xe2, 0x71, 0x87, 0x08, 0x07, 0x97, 0x24, 0x96, 0xa4, 0x0a, + 0x59, 0x72, 0xb1, 0x41, 0x0c, 0x90, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x36, 0x92, 0xd6, 0xc3, 0xe2, + 0x0c, 0xbd, 0x00, 0xb0, 0x12, 0x27, 0x96, 0x13, 0xf7, 0xe4, 0x19, 0x82, 0xa0, 0x1a, 0x84, 0x42, + 0xb8, 0x04, 0x60, 0x36, 0x24, 0x26, 0x27, 0xe7, 0x97, 0xe6, 0x95, 0x14, 0x4b, 0x30, 0x29, 0x30, + 0x6b, 0x70, 0x1b, 0x29, 0x63, 0x35, 0x04, 0x6a, 0xaf, 0x23, 0x44, 0x2d, 0xd4, 0x30, 0xfe, 0x74, + 0x14, 0xd1, 0x62, 0xa7, 0xe0, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, + 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0xb2, + 0x4c, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xa9, 0xcc, 0x4d, 0xcd, + 0x2b, 0xce, 0xcc, 0xcf, 0xab, 0xa8, 0xac, 0x42, 0x70, 0x74, 0x8b, 0x52, 0xb2, 0xf5, 0x2b, 0xf4, + 0x91, 0xc3, 0xa0, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0xec, 0x7b, 0x63, 0x40, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xe8, 0xed, 0x69, 0xd0, 0x7f, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -133,34 +124,20 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.UnackedTransferSeqNums) > 0 { - dAtA2 := make([]byte, len(m.UnackedTransferSeqNums)*10) - var j1 int - for _, num := range m.UnackedTransferSeqNums { - for num >= 1<<7 { - dAtA2[j1] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j1++ + if len(m.GenesisAccounts) > 0 { + for iNdEx := len(m.GenesisAccounts) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.GenesisAccounts[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) } - dAtA2[j1] = uint8(num) - j1++ + i-- + dAtA[i] = 0x12 } - i -= j1 - copy(dAtA[i:], dAtA2[:j1]) - i = encodeVarintGenesis(dAtA, i, uint64(j1)) - i-- - dAtA[i] = 0x1a } - { - size, err := m.State.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 { size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -193,14 +170,11 @@ func (m *GenesisState) Size() (n int) { _ = l l = m.Params.Size() n += 1 + l + sovGenesis(uint64(l)) - l = m.State.Size() - n += 1 + l + sovGenesis(uint64(l)) - if len(m.UnackedTransferSeqNums) > 0 { - l = 0 - for _, e := range m.UnackedTransferSeqNums { - l += sovGenesis(uint64(e)) + if len(m.GenesisAccounts) > 0 { + for _, e := range m.GenesisAccounts { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) } - n += 1 + sovGenesis(uint64(l)) + l } return n } @@ -275,7 +249,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field State", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field GenesisAccounts", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -302,86 +276,11 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.State.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.GenesisAccounts = append(m.GenesisAccounts, GenesisAccount{}) + if err := m.GenesisAccounts[len(m.GenesisAccounts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 3: - if wireType == 0 { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.UnackedTransferSeqNums = append(m.UnackedTransferSeqNums, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - var elementCount int - var count int - for _, integer := range dAtA[iNdEx:postIndex] { - if integer < 128 { - count++ - } - } - elementCount = count - if elementCount != 0 && len(m.UnackedTransferSeqNums) == 0 { - m.UnackedTransferSeqNums = make([]uint64, 0, elementCount) - } - for iNdEx < postIndex { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.UnackedTransferSeqNums = append(m.UnackedTransferSeqNums, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field UnackedTransferSeqNums", wireType) - } default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/hub-genesis/types/genesis_bridge_data.pb.go b/x/hub-genesis/types/genesis_bridge_data.pb.go new file mode 100644 index 00000000..c9475def --- /dev/null +++ b/x/hub-genesis/types/genesis_bridge_data.pb.go @@ -0,0 +1,452 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: hub-genesis/genesis_bridge_data.proto + +package types + +import ( + fmt "fmt" + types "github.com/cosmos/cosmos-sdk/x/bank/types" + types1 "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisBridgeData is the data struct that is passed to the hub for the +// genesis bridge flow +type GenesisBridgeData struct { + // genesis_info is the genesis info of the rollapp. used for hub validation + GenesisInfo GenesisInfo `protobuf:"bytes,1,opt,name=genesis_info,json=genesisInfo,proto3" json:"genesis_info"` + // native_denom is the native denom of the rollapp. registered on the hub + NativeDenom types.Metadata `protobuf:"bytes,2,opt,name=native_denom,json=nativeDenom,proto3" json:"native_denom"` + // optional genesis transfer packet data + GenesisTransfer *types1.FungibleTokenPacketData `protobuf:"bytes,3,opt,name=genesis_transfer,json=genesisTransfer,proto3" json:"genesis_transfer,omitempty"` +} + +func (m *GenesisBridgeData) Reset() { *m = GenesisBridgeData{} } +func (m *GenesisBridgeData) String() string { return proto.CompactTextString(m) } +func (*GenesisBridgeData) ProtoMessage() {} +func (*GenesisBridgeData) Descriptor() ([]byte, []int) { + return fileDescriptor_b92d08aeaaf6feb0, []int{0} +} +func (m *GenesisBridgeData) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisBridgeData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisBridgeData.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisBridgeData) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisBridgeData.Merge(m, src) +} +func (m *GenesisBridgeData) XXX_Size() int { + return m.Size() +} +func (m *GenesisBridgeData) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisBridgeData.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisBridgeData proto.InternalMessageInfo + +func (m *GenesisBridgeData) GetGenesisInfo() GenesisInfo { + if m != nil { + return m.GenesisInfo + } + return GenesisInfo{} +} + +func (m *GenesisBridgeData) GetNativeDenom() types.Metadata { + if m != nil { + return m.NativeDenom + } + return types.Metadata{} +} + +func (m *GenesisBridgeData) GetGenesisTransfer() *types1.FungibleTokenPacketData { + if m != nil { + return m.GenesisTransfer + } + return nil +} + +func init() { + proto.RegisterType((*GenesisBridgeData)(nil), "rollapp.hub_genesis.GenesisBridgeData") +} + +func init() { + proto.RegisterFile("hub-genesis/genesis_bridge_data.proto", fileDescriptor_b92d08aeaaf6feb0) +} + +var fileDescriptor_b92d08aeaaf6feb0 = []byte{ + // 365 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0xb1, 0x4e, 0xeb, 0x30, + 0x14, 0x86, 0x93, 0xde, 0xab, 0x3b, 0xa4, 0x95, 0x2e, 0x04, 0x86, 0xaa, 0x12, 0xa1, 0x42, 0x42, + 0x82, 0xa1, 0xb6, 0x5a, 0xc4, 0xc0, 0x5a, 0x55, 0x45, 0x1d, 0x90, 0x50, 0xe9, 0xc4, 0x12, 0xec, + 0xc4, 0x4d, 0xad, 0x24, 0xb6, 0x15, 0x3b, 0x51, 0xcb, 0x13, 0x30, 0xf2, 0x58, 0x1d, 0x3b, 0x32, + 0x21, 0xd4, 0xbe, 0x08, 0x8a, 0xe3, 0xa8, 0x1d, 0x3a, 0x25, 0xe7, 0x9c, 0xff, 0xfc, 0x3e, 0xdf, + 0xef, 0x5c, 0x2f, 0x72, 0xdc, 0x8b, 0x08, 0x23, 0x92, 0x4a, 0x68, 0xbe, 0x3e, 0xce, 0x68, 0x18, + 0x11, 0x3f, 0x44, 0x0a, 0x01, 0x91, 0x71, 0xc5, 0xdd, 0xb3, 0x8c, 0x27, 0x09, 0x12, 0x02, 0x2c, + 0x72, 0xec, 0x1b, 0x59, 0xe7, 0x3c, 0xe2, 0x11, 0xd7, 0x73, 0x58, 0xfe, 0x55, 0xd2, 0x8e, 0x17, + 0x70, 0x99, 0x72, 0x09, 0x31, 0x62, 0x31, 0x2c, 0xfa, 0x98, 0x28, 0xd4, 0xd7, 0x85, 0x99, 0xdf, + 0x52, 0x1c, 0x40, 0x24, 0x44, 0x42, 0x03, 0xa4, 0x28, 0x67, 0x12, 0xaa, 0x0c, 0x31, 0x39, 0x27, + 0x19, 0x2c, 0x06, 0x50, 0xa0, 0x20, 0x26, 0xaa, 0xb6, 0x3a, 0x76, 0x1c, 0x65, 0x73, 0xf3, 0xd4, + 0xd5, 0x47, 0xc3, 0x39, 0x7d, 0xac, 0xda, 0x43, 0x7d, 0xf2, 0x08, 0x29, 0xe4, 0x4e, 0x9c, 0xd6, + 0xa1, 0xb6, 0x6d, 0x77, 0xed, 0x9b, 0xe6, 0xa0, 0x0b, 0x8e, 0x20, 0x00, 0xb3, 0x3d, 0x61, 0x73, + 0x3e, 0xfc, 0xbb, 0xfe, 0xbe, 0xb4, 0xa6, 0xcd, 0x68, 0xdf, 0x72, 0xc7, 0x4e, 0x8b, 0x21, 0x45, + 0x0b, 0xe2, 0x87, 0x84, 0xf1, 0xb4, 0xdd, 0xd0, 0x56, 0x17, 0xa0, 0x42, 0x04, 0x9a, 0xca, 0x20, + 0x82, 0x27, 0xa2, 0x50, 0x99, 0x58, 0xed, 0x53, 0x2d, 0x8e, 0xca, 0x3d, 0xf7, 0xcd, 0x39, 0xa9, + 0x4f, 0xaa, 0x61, 0xdb, 0x7f, 0xb4, 0xd7, 0x3d, 0xa0, 0x38, 0x00, 0x87, 0x71, 0x80, 0x5a, 0x01, + 0x8a, 0x01, 0x18, 0xe7, 0x2c, 0xa2, 0x38, 0x21, 0x33, 0x1e, 0x13, 0xf6, 0xac, 0xb3, 0x29, 0x19, + 0xa7, 0xff, 0x8d, 0xdd, 0xcc, 0x68, 0x87, 0x2f, 0xeb, 0xad, 0x67, 0x6f, 0xb6, 0x9e, 0xfd, 0xb3, + 0xf5, 0xec, 0xcf, 0x9d, 0x67, 0x6d, 0x76, 0x9e, 0xf5, 0xb5, 0xf3, 0xac, 0xd7, 0x87, 0x88, 0xaa, + 0x45, 0x8e, 0x41, 0xc0, 0x53, 0x18, 0xae, 0x52, 0xc2, 0x24, 0xe5, 0x6c, 0xb9, 0x7a, 0xdf, 0x17, + 0xbd, 0x2c, 0x8c, 0xe1, 0x12, 0x1e, 0x86, 0xad, 0x56, 0x82, 0x48, 0xfc, 0x4f, 0xc7, 0x7c, 0xf7, + 0x1b, 0x00, 0x00, 0xff, 0xff, 0x97, 0x37, 0xbb, 0xed, 0x25, 0x02, 0x00, 0x00, +} + +func (m *GenesisBridgeData) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisBridgeData) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisBridgeData) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.GenesisTransfer != nil { + { + size, err := m.GenesisTransfer.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesisBridgeData(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + { + size, err := m.NativeDenom.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesisBridgeData(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.GenesisInfo.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesisBridgeData(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesisBridgeData(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesisBridgeData(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisBridgeData) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.GenesisInfo.Size() + n += 1 + l + sovGenesisBridgeData(uint64(l)) + l = m.NativeDenom.Size() + n += 1 + l + sovGenesisBridgeData(uint64(l)) + if m.GenesisTransfer != nil { + l = m.GenesisTransfer.Size() + n += 1 + l + sovGenesisBridgeData(uint64(l)) + } + return n +} + +func sovGenesisBridgeData(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesisBridgeData(x uint64) (n int) { + return sovGenesisBridgeData(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisBridgeData) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesisBridgeData + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisBridgeData: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisBridgeData: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field GenesisInfo", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesisBridgeData + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesisBridgeData + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesisBridgeData + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.GenesisInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NativeDenom", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesisBridgeData + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesisBridgeData + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesisBridgeData + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.NativeDenom.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field GenesisTransfer", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesisBridgeData + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesisBridgeData + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesisBridgeData + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.GenesisTransfer == nil { + m.GenesisTransfer = &types1.FungibleTokenPacketData{} + } + if err := m.GenesisTransfer.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesisBridgeData(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesisBridgeData + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesisBridgeData(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesisBridgeData + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesisBridgeData + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesisBridgeData + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesisBridgeData + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesisBridgeData + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesisBridgeData + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesisBridgeData = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesisBridgeData = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesisBridgeData = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/hub-genesis/types/genesis_info.go b/x/hub-genesis/types/genesis_info.go new file mode 100644 index 00000000..052c5352 --- /dev/null +++ b/x/hub-genesis/types/genesis_info.go @@ -0,0 +1,33 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/dymensionxyz/gerr-cosmos/gerrc" +) + +// AccAddressFromBech32 creates an AccAddress from a Bech32 string. +func ValidateHubBech32(address string) (err error) { + bech32PrefixAccAddr := "dym" + bz, err := sdk.GetFromBech32(address, bech32PrefixAccAddr) + if err != nil { + return err + } + return sdk.VerifyAddressFormat(bz) +} + +func (a GenesisAccount) ValidateBasic() error { + if !a.Amount.IsPositive() { + return errorsmod.Wrapf(gerrc.ErrInvalidArgument, "invalid amount: %s %s", a.Address, a.Amount) + } + + if err := ValidateHubBech32(a.Address); err != nil { + return errorsmod.Wrapf(err, "invalid address: %s", a.Address) + } + + return nil +} + +func (g GenesisInfo) BaseDenom() string { + return g.NativeDenom.Base +} diff --git a/x/hub-genesis/types/genesis_info.pb.go b/x/hub-genesis/types/genesis_info.pb.go new file mode 100644 index 00000000..461b9744 --- /dev/null +++ b/x/hub-genesis/types/genesis_info.pb.go @@ -0,0 +1,1039 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: hub-genesis/genesis_info.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/x/bank/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// The genesis info of the rollapp, that is passed to the hub for validation. +// it's populated on the InitGenesis of the rollapp +type GenesisInfo struct { + // checksum used to verify integrity of the genesis file. currently unused + GenesisChecksum string `protobuf:"bytes,1,opt,name=genesis_checksum,json=genesisChecksum,proto3" json:"genesis_checksum,omitempty"` + // unique bech32 prefix + Bech32Prefix string `protobuf:"bytes,2,opt,name=bech32_prefix,json=bech32Prefix,proto3" json:"bech32_prefix,omitempty"` + // native_denom is the base denom for the native token + NativeDenom *DenomMetadata `protobuf:"bytes,3,opt,name=native_denom,json=nativeDenom,proto3" json:"native_denom,omitempty"` + // initial_supply is the initial supply of the native token + InitialSupply github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,4,opt,name=initial_supply,json=initialSupply,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"initial_supply"` + // accounts on the Hub to fund with some bootstrapping transfers + GenesisAccounts []GenesisAccount `protobuf:"bytes,5,rep,name=genesis_accounts,json=genesisAccounts,proto3" json:"genesis_accounts"` +} + +func (m *GenesisInfo) Reset() { *m = GenesisInfo{} } +func (m *GenesisInfo) String() string { return proto.CompactTextString(m) } +func (*GenesisInfo) ProtoMessage() {} +func (*GenesisInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_db3d5bf55e08315f, []int{0} +} +func (m *GenesisInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisInfo.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisInfo.Merge(m, src) +} +func (m *GenesisInfo) XXX_Size() int { + return m.Size() +} +func (m *GenesisInfo) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisInfo proto.InternalMessageInfo + +func (m *GenesisInfo) GetGenesisChecksum() string { + if m != nil { + return m.GenesisChecksum + } + return "" +} + +func (m *GenesisInfo) GetBech32Prefix() string { + if m != nil { + return m.Bech32Prefix + } + return "" +} + +func (m *GenesisInfo) GetNativeDenom() *DenomMetadata { + if m != nil { + return m.NativeDenom + } + return nil +} + +func (m *GenesisInfo) GetGenesisAccounts() []GenesisAccount { + if m != nil { + return m.GenesisAccounts + } + return nil +} + +type DenomMetadata struct { + Display string `protobuf:"bytes,1,opt,name=display,proto3" json:"display,omitempty"` + Base string `protobuf:"bytes,2,opt,name=base,proto3" json:"base,omitempty"` + Exponent uint32 `protobuf:"varint,3,opt,name=exponent,proto3" json:"exponent,omitempty"` +} + +func (m *DenomMetadata) Reset() { *m = DenomMetadata{} } +func (m *DenomMetadata) String() string { return proto.CompactTextString(m) } +func (*DenomMetadata) ProtoMessage() {} +func (*DenomMetadata) Descriptor() ([]byte, []int) { + return fileDescriptor_db3d5bf55e08315f, []int{1} +} +func (m *DenomMetadata) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DenomMetadata) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DenomMetadata.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DenomMetadata) XXX_Merge(src proto.Message) { + xxx_messageInfo_DenomMetadata.Merge(m, src) +} +func (m *DenomMetadata) XXX_Size() int { + return m.Size() +} +func (m *DenomMetadata) XXX_DiscardUnknown() { + xxx_messageInfo_DenomMetadata.DiscardUnknown(m) +} + +var xxx_messageInfo_DenomMetadata proto.InternalMessageInfo + +func (m *DenomMetadata) GetDisplay() string { + if m != nil { + return m.Display + } + return "" +} + +func (m *DenomMetadata) GetBase() string { + if m != nil { + return m.Base + } + return "" +} + +func (m *DenomMetadata) GetExponent() uint32 { + if m != nil { + return m.Exponent + } + return 0 +} + +// GenesisAccount is a struct for the genesis account for the rollapp +type GenesisAccount struct { + // amount of coins to be sent to the genesis address + Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` + // address is a bech-32 address of the genesis account + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` +} + +func (m *GenesisAccount) Reset() { *m = GenesisAccount{} } +func (m *GenesisAccount) String() string { return proto.CompactTextString(m) } +func (*GenesisAccount) ProtoMessage() {} +func (*GenesisAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_db3d5bf55e08315f, []int{2} +} +func (m *GenesisAccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisAccount.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisAccount.Merge(m, src) +} +func (m *GenesisAccount) XXX_Size() int { + return m.Size() +} +func (m *GenesisAccount) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisAccount proto.InternalMessageInfo + +func (m *GenesisAccount) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func init() { + proto.RegisterType((*GenesisInfo)(nil), "rollapp.hub_genesis.GenesisInfo") + proto.RegisterType((*DenomMetadata)(nil), "rollapp.hub_genesis.DenomMetadata") + proto.RegisterType((*GenesisAccount)(nil), "rollapp.hub_genesis.GenesisAccount") +} + +func init() { proto.RegisterFile("hub-genesis/genesis_info.proto", fileDescriptor_db3d5bf55e08315f) } + +var fileDescriptor_db3d5bf55e08315f = []byte{ + // 456 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0x4d, 0x6f, 0xd3, 0x40, + 0x10, 0x8d, 0xdb, 0x50, 0x60, 0xd3, 0x14, 0xb4, 0x20, 0x61, 0xe5, 0xe0, 0x46, 0xa9, 0x84, 0xc2, + 0x21, 0xb6, 0x9a, 0x9e, 0x38, 0x12, 0xbe, 0xd4, 0x03, 0x12, 0x4a, 0xe1, 0x00, 0x17, 0x6b, 0x6d, + 0x4f, 0xe2, 0x55, 0xec, 0xdd, 0x95, 0x67, 0x5d, 0xc5, 0xfc, 0x0a, 0x7e, 0x56, 0x8f, 0xe5, 0x86, + 0x38, 0x54, 0x28, 0xf9, 0x23, 0xc8, 0xeb, 0x4d, 0x9b, 0x4a, 0xb9, 0x70, 0xda, 0x7d, 0x6f, 0x66, + 0xe7, 0xbd, 0x79, 0x5a, 0xe2, 0xa5, 0x65, 0x34, 0x9a, 0x83, 0x00, 0xe4, 0x18, 0xd8, 0x33, 0xe4, + 0x62, 0x26, 0x7d, 0x55, 0x48, 0x2d, 0xe9, 0xb3, 0x42, 0x66, 0x19, 0x53, 0xca, 0x4f, 0xcb, 0x28, + 0xb4, 0xf5, 0xde, 0xf3, 0xb9, 0x9c, 0x4b, 0x53, 0x0f, 0xea, 0x5b, 0xd3, 0xda, 0xf3, 0x62, 0x89, + 0xb9, 0xc4, 0x20, 0x62, 0x62, 0x11, 0x5c, 0x9e, 0x46, 0xa0, 0xd9, 0xa9, 0x01, 0xb6, 0xfe, 0x62, + 0x5b, 0x0a, 0x35, 0xd3, 0xd0, 0x14, 0x06, 0xbf, 0xf6, 0x48, 0xe7, 0x63, 0xc3, 0x9f, 0x8b, 0x99, + 0xa4, 0xaf, 0xc8, 0xd3, 0x8d, 0x93, 0x38, 0x85, 0x78, 0x81, 0x65, 0xee, 0x3a, 0x7d, 0x67, 0xf8, + 0x78, 0xfa, 0xc4, 0xf2, 0x6f, 0x2d, 0x4d, 0x4f, 0x48, 0x37, 0x82, 0x38, 0x3d, 0x1b, 0x87, 0xaa, + 0x80, 0x19, 0x5f, 0xba, 0x7b, 0xa6, 0xef, 0xb0, 0x21, 0x3f, 0x1b, 0x8e, 0xbe, 0x27, 0x87, 0x82, + 0x69, 0x7e, 0x09, 0x61, 0x02, 0x42, 0xe6, 0xee, 0x7e, 0xdf, 0x19, 0x76, 0xc6, 0x03, 0x7f, 0xc7, + 0x6a, 0xfe, 0xbb, 0xba, 0xe3, 0x13, 0x68, 0x96, 0x30, 0xcd, 0xa6, 0x9d, 0xe6, 0x9d, 0x21, 0xe9, + 0x57, 0x72, 0xc4, 0x05, 0xd7, 0x9c, 0x65, 0x21, 0x96, 0x4a, 0x65, 0x95, 0xdb, 0xae, 0xc5, 0x26, + 0xfe, 0xd5, 0xcd, 0x71, 0xeb, 0xcf, 0xcd, 0xf1, 0xcb, 0x39, 0xd7, 0x69, 0x19, 0xf9, 0xb1, 0xcc, + 0x03, 0x1b, 0x45, 0x73, 0x8c, 0x30, 0x59, 0x04, 0xba, 0x52, 0x80, 0xfe, 0xb9, 0xd0, 0xd3, 0xae, + 0x9d, 0x72, 0x61, 0x86, 0xd0, 0x2f, 0x77, 0xdb, 0xb2, 0x38, 0x96, 0xa5, 0xd0, 0xe8, 0x3e, 0xe8, + 0xef, 0x0f, 0x3b, 0xe3, 0x93, 0x9d, 0x0e, 0x6d, 0x52, 0x6f, 0x9a, 0xde, 0x49, 0xbb, 0x56, 0xbf, + 0x0d, 0xc6, 0xb2, 0x38, 0xf8, 0x46, 0xba, 0xf7, 0x56, 0xa1, 0x2e, 0x79, 0x98, 0x70, 0x54, 0x19, + 0xab, 0x6c, 0x96, 0x1b, 0x48, 0x29, 0x69, 0x47, 0x0c, 0xc1, 0x46, 0x67, 0xee, 0xb4, 0x47, 0x1e, + 0xc1, 0x52, 0x49, 0x01, 0x42, 0x9b, 0xb8, 0xba, 0xd3, 0x5b, 0x3c, 0x28, 0xc8, 0xd1, 0x7d, 0x0f, + 0xf4, 0x03, 0x39, 0x60, 0x79, 0x7d, 0x6b, 0x46, 0xff, 0x77, 0x22, 0xf6, 0x75, 0xed, 0x91, 0x25, + 0x49, 0x01, 0x88, 0xd6, 0xcc, 0x06, 0x4e, 0x2e, 0xae, 0x56, 0x9e, 0x73, 0xbd, 0xf2, 0x9c, 0xbf, + 0x2b, 0xcf, 0xf9, 0xb9, 0xf6, 0x5a, 0xd7, 0x6b, 0xaf, 0xf5, 0x7b, 0xed, 0xb5, 0xbe, 0xbf, 0xde, + 0xd2, 0x48, 0xaa, 0x1c, 0x04, 0x72, 0x29, 0x96, 0xd5, 0x8f, 0x3b, 0x30, 0x2a, 0x92, 0x45, 0xb0, + 0x0c, 0xb6, 0x7f, 0x9f, 0x91, 0x8e, 0x0e, 0xcc, 0xf7, 0x3b, 0xfb, 0x17, 0x00, 0x00, 0xff, 0xff, + 0x8f, 0x72, 0xef, 0x1e, 0x04, 0x03, 0x00, 0x00, +} + +func (m *GenesisInfo) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.GenesisAccounts) > 0 { + for iNdEx := len(m.GenesisAccounts) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.GenesisAccounts[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesisInfo(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + } + { + size := m.InitialSupply.Size() + i -= size + if _, err := m.InitialSupply.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGenesisInfo(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + if m.NativeDenom != nil { + { + size, err := m.NativeDenom.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesisInfo(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if len(m.Bech32Prefix) > 0 { + i -= len(m.Bech32Prefix) + copy(dAtA[i:], m.Bech32Prefix) + i = encodeVarintGenesisInfo(dAtA, i, uint64(len(m.Bech32Prefix))) + i-- + dAtA[i] = 0x12 + } + if len(m.GenesisChecksum) > 0 { + i -= len(m.GenesisChecksum) + copy(dAtA[i:], m.GenesisChecksum) + i = encodeVarintGenesisInfo(dAtA, i, uint64(len(m.GenesisChecksum))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *DenomMetadata) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DenomMetadata) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DenomMetadata) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Exponent != 0 { + i = encodeVarintGenesisInfo(dAtA, i, uint64(m.Exponent)) + i-- + dAtA[i] = 0x18 + } + if len(m.Base) > 0 { + i -= len(m.Base) + copy(dAtA[i:], m.Base) + i = encodeVarintGenesisInfo(dAtA, i, uint64(len(m.Base))) + i-- + dAtA[i] = 0x12 + } + if len(m.Display) > 0 { + i -= len(m.Display) + copy(dAtA[i:], m.Display) + i = encodeVarintGenesisInfo(dAtA, i, uint64(len(m.Display))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *GenesisAccount) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintGenesisInfo(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0x12 + } + { + size := m.Amount.Size() + i -= size + if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGenesisInfo(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesisInfo(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesisInfo(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.GenesisChecksum) + if l > 0 { + n += 1 + l + sovGenesisInfo(uint64(l)) + } + l = len(m.Bech32Prefix) + if l > 0 { + n += 1 + l + sovGenesisInfo(uint64(l)) + } + if m.NativeDenom != nil { + l = m.NativeDenom.Size() + n += 1 + l + sovGenesisInfo(uint64(l)) + } + l = m.InitialSupply.Size() + n += 1 + l + sovGenesisInfo(uint64(l)) + if len(m.GenesisAccounts) > 0 { + for _, e := range m.GenesisAccounts { + l = e.Size() + n += 1 + l + sovGenesisInfo(uint64(l)) + } + } + return n +} + +func (m *DenomMetadata) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Display) + if l > 0 { + n += 1 + l + sovGenesisInfo(uint64(l)) + } + l = len(m.Base) + if l > 0 { + n += 1 + l + sovGenesisInfo(uint64(l)) + } + if m.Exponent != 0 { + n += 1 + sovGenesisInfo(uint64(m.Exponent)) + } + return n +} + +func (m *GenesisAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Amount.Size() + n += 1 + l + sovGenesisInfo(uint64(l)) + l = len(m.Address) + if l > 0 { + n += 1 + l + sovGenesisInfo(uint64(l)) + } + return n +} + +func sovGenesisInfo(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesisInfo(x uint64) (n int) { + return sovGenesisInfo(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisInfo) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesisInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field GenesisChecksum", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesisInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesisInfo + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesisInfo + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.GenesisChecksum = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bech32Prefix", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesisInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesisInfo + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesisInfo + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Bech32Prefix = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NativeDenom", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesisInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesisInfo + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesisInfo + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.NativeDenom == nil { + m.NativeDenom = &DenomMetadata{} + } + if err := m.NativeDenom.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InitialSupply", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesisInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesisInfo + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesisInfo + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.InitialSupply.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field GenesisAccounts", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesisInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesisInfo + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesisInfo + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.GenesisAccounts = append(m.GenesisAccounts, GenesisAccount{}) + if err := m.GenesisAccounts[len(m.GenesisAccounts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesisInfo(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesisInfo + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DenomMetadata) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesisInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DenomMetadata: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DenomMetadata: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Display", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesisInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesisInfo + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesisInfo + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Display = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Base", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesisInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesisInfo + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesisInfo + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Base = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Exponent", wireType) + } + m.Exponent = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesisInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Exponent |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipGenesisInfo(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesisInfo + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *GenesisAccount) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesisInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisAccount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesisInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesisInfo + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesisInfo + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesisInfo + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesisInfo + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesisInfo + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesisInfo(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesisInfo + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesisInfo(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesisInfo + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesisInfo + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesisInfo + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesisInfo + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesisInfo + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesisInfo + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesisInfo = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesisInfo = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesisInfo = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/hub-genesis/types/genesis_test.go b/x/hub-genesis/types/genesis_test.go new file mode 100644 index 00000000..e29fe611 --- /dev/null +++ b/x/hub-genesis/types/genesis_test.go @@ -0,0 +1,74 @@ +package types + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func sampleAddr() []byte { + return secp256k1.GenPrivKey().PubKey().Address().Bytes() +} + +func TestGenesisState_ValidateBasic(t *testing.T) { + tests := []struct { + name string + genesisState GenesisState + wantErr bool + errMsg string + }{ + { + name: "valid genesis state", + genesisState: GenesisState{ + GenesisAccounts: []GenesisAccount{ + {Address: sdk.MustBech32ifyAddressBytes("dym", sampleAddr()), Amount: sdk.NewInt(100)}, + {Address: sdk.MustBech32ifyAddressBytes("dym", sampleAddr()), Amount: sdk.NewInt(100)}, + }, + }, + wantErr: false, + }, + { + name: "valid genesis - no genesis accounts", + genesisState: GenesisState{}, + wantErr: false, + }, + { + name: "invalid state - invalid address", + genesisState: GenesisState{ + GenesisAccounts: []GenesisAccount{ + {Address: sdk.MustBech32ifyAddressBytes("dym", sampleAddr()), Amount: sdk.NewInt(100)}, + {Address: "invalid_address", Amount: sdk.NewInt(100)}, + }, + }, + wantErr: true, + errMsg: "invalid address", + }, + { + name: "invalid state - invalid amount", + genesisState: GenesisState{ + GenesisAccounts: []GenesisAccount{ + {Address: sdk.MustBech32ifyAddressBytes("dym", sampleAddr()), Amount: sdk.NewInt(100)}, + {Address: sdk.MustBech32ifyAddressBytes("dym", sampleAddr()), Amount: sdk.NewInt(-100)}, + }, + }, + wantErr: true, + errMsg: "invalid amount", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.genesisState.ValidateBasic() + if tt.wantErr { + require.Error(t, err) + assert.Contains(t, err.Error(), tt.errMsg) + } else { + require.NoError(t, err) + } + }) + } +} diff --git a/x/hub-genesis/types/keys.go b/x/hub-genesis/types/keys.go index f7b97ced..b7e23d47 100644 --- a/x/hub-genesis/types/keys.go +++ b/x/hub-genesis/types/keys.go @@ -3,17 +3,14 @@ package types const ( ModuleName = "hubgenesis" - // StoreKey is the default store key for mint. + // StoreKey is the default store key for hub-genesis module. StoreKey = ModuleName - // RouterKey is the message route for hub genesis. - RouterKey = ModuleName - - // QuerierRoute is the querier route for the minting store. + // QuerierRoute is the querier route for the hub-genesis module QuerierRoute = StoreKey - - // QueryParameters endpoints supported by the minting querier. - QueryParameters = "parameters" ) -var StateKey = []byte{0x01} +var ( + StateKey = []byte{0x01} + GenesisInfoKey = []byte{0x02} +) diff --git a/x/hub-genesis/types/query.pb.go b/x/hub-genesis/types/query.pb.go index a1a82d10..f5fccead 100644 --- a/x/hub-genesis/types/query.pb.go +++ b/x/hub-genesis/types/query.pb.go @@ -195,40 +195,132 @@ func (m *QueryStateResponse) GetState() State { return State{} } +// QueryGenesisInfoRequest is the request type for the Query/GenesisInfo RPC +// method. +type QueryGenesisInfoRequest struct { +} + +func (m *QueryGenesisInfoRequest) Reset() { *m = QueryGenesisInfoRequest{} } +func (m *QueryGenesisInfoRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGenesisInfoRequest) ProtoMessage() {} +func (*QueryGenesisInfoRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_361b89f8abfb35e2, []int{4} +} +func (m *QueryGenesisInfoRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGenesisInfoRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGenesisInfoRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryGenesisInfoRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGenesisInfoRequest.Merge(m, src) +} +func (m *QueryGenesisInfoRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGenesisInfoRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGenesisInfoRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGenesisInfoRequest proto.InternalMessageInfo + +// QueryGenesisInfoResponse is the response type for the Query/GenesisInfo RPC +// method. +type QueryGenesisInfoResponse struct { + // genesis_info holds the genesis info of the rollapp + GenesisInfo GenesisInfo `protobuf:"bytes,1,opt,name=genesis_info,json=genesisInfo,proto3" json:"genesis_info"` +} + +func (m *QueryGenesisInfoResponse) Reset() { *m = QueryGenesisInfoResponse{} } +func (m *QueryGenesisInfoResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGenesisInfoResponse) ProtoMessage() {} +func (*QueryGenesisInfoResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_361b89f8abfb35e2, []int{5} +} +func (m *QueryGenesisInfoResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGenesisInfoResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGenesisInfoResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryGenesisInfoResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGenesisInfoResponse.Merge(m, src) +} +func (m *QueryGenesisInfoResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGenesisInfoResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGenesisInfoResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGenesisInfoResponse proto.InternalMessageInfo + +func (m *QueryGenesisInfoResponse) GetGenesisInfo() GenesisInfo { + if m != nil { + return m.GenesisInfo + } + return GenesisInfo{} +} + func init() { proto.RegisterType((*QueryParamsRequest)(nil), "rollapp.hub_genesis.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "rollapp.hub_genesis.QueryParamsResponse") proto.RegisterType((*QueryStateRequest)(nil), "rollapp.hub_genesis.QueryStateRequest") proto.RegisterType((*QueryStateResponse)(nil), "rollapp.hub_genesis.QueryStateResponse") + proto.RegisterType((*QueryGenesisInfoRequest)(nil), "rollapp.hub_genesis.QueryGenesisInfoRequest") + proto.RegisterType((*QueryGenesisInfoResponse)(nil), "rollapp.hub_genesis.QueryGenesisInfoResponse") } func init() { proto.RegisterFile("hub-genesis/query.proto", fileDescriptor_361b89f8abfb35e2) } var fileDescriptor_361b89f8abfb35e2 = []byte{ - // 361 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xb1, 0x4e, 0x3a, 0x31, - 0x1c, 0xc7, 0xaf, 0xe4, 0x0f, 0x43, 0xff, 0x93, 0x85, 0x44, 0x72, 0x9a, 0xd3, 0xdc, 0x20, 0x2c, - 0x5c, 0x0d, 0x46, 0x12, 0x56, 0x66, 0x07, 0x84, 0xcd, 0xc5, 0xf4, 0xa4, 0x39, 0x2e, 0x42, 0x5b, - 0xae, 0xbd, 0x84, 0x73, 0xf4, 0x05, 0x34, 0xe1, 0x41, 0x7c, 0x0d, 0x46, 0x12, 0x17, 0x27, 0x63, - 0xc0, 0x07, 0x31, 0xb4, 0x25, 0x42, 0x40, 0x71, 0x83, 0xfe, 0xbe, 0xbf, 0xef, 0xe7, 0x73, 0xbd, - 0x83, 0x87, 0xfd, 0x34, 0xac, 0x45, 0x94, 0x51, 0x19, 0x4b, 0x3c, 0x4a, 0x69, 0x92, 0x05, 0x22, - 0xe1, 0x8a, 0xa3, 0x62, 0xc2, 0x07, 0x03, 0x22, 0x44, 0xd0, 0x4f, 0xc3, 0x5b, 0x1b, 0x70, 0x4b, - 0x11, 0x8f, 0xb8, 0x9e, 0xe3, 0xe5, 0x2f, 0x13, 0x75, 0x8f, 0x23, 0xce, 0xa3, 0x01, 0xc5, 0x44, - 0xc4, 0x98, 0x30, 0xc6, 0x15, 0x51, 0x31, 0x67, 0xd2, 0x4e, 0xcb, 0xeb, 0x04, 0x41, 0x12, 0x32, - 0x5c, 0x4d, 0x36, 0xd8, 0x52, 0x11, 0x45, 0xcd, 0xc0, 0x2f, 0x41, 0x74, 0xbd, 0x54, 0x69, 0xeb, - 0x74, 0x87, 0x8e, 0x52, 0x2a, 0x95, 0xdf, 0x86, 0xc5, 0x8d, 0x53, 0x29, 0x38, 0x93, 0x14, 0x35, - 0x61, 0xc1, 0xb4, 0x96, 0xc1, 0x29, 0xa8, 0xfe, 0xaf, 0x1f, 0x05, 0x3b, 0xcc, 0x03, 0xb3, 0xd4, - 0xfa, 0x37, 0x7d, 0x3f, 0x71, 0x3a, 0x76, 0xc1, 0x2f, 0xc2, 0x03, 0xdd, 0xd8, 0x5d, 0xb2, 0x57, - 0x98, 0x2b, 0x0b, 0xb7, 0x87, 0x96, 0xd2, 0x80, 0x79, 0x6d, 0x68, 0x21, 0xee, 0x4e, 0x88, 0x5e, - 0xb1, 0x0c, 0x13, 0xaf, 0xbf, 0xe4, 0x60, 0x5e, 0xd7, 0xa1, 0x09, 0x80, 0x05, 0x63, 0x81, 0x2a, - 0x3b, 0xb7, 0xb7, 0x1f, 0xd9, 0xad, 0xee, 0x0f, 0x1a, 0x3f, 0xbf, 0xf1, 0xf8, 0xfa, 0x39, 0xc9, - 0x9d, 0xa3, 0x00, 0xf7, 0xb2, 0x21, 0x65, 0x32, 0xe6, 0x6c, 0x9c, 0x3d, 0x7c, 0xff, 0xa9, 0x25, - 0xbd, 0x7b, 0xbc, 0xfd, 0x26, 0xd0, 0x13, 0x80, 0x79, 0xad, 0x8d, 0xce, 0x7e, 0x66, 0xad, 0xdf, - 0x8f, 0x5b, 0xd9, 0x9b, 0xb3, 0x4a, 0x97, 0x5a, 0x09, 0xa3, 0xda, 0x5f, 0x95, 0xf4, 0x8d, 0xb5, - 0xba, 0xd3, 0xb9, 0x07, 0x66, 0x73, 0x0f, 0x7c, 0xcc, 0x3d, 0xf0, 0xbc, 0xf0, 0x9c, 0xd9, 0xc2, - 0x73, 0xde, 0x16, 0x9e, 0x73, 0xd3, 0x8c, 0x62, 0xd5, 0x4f, 0xc3, 0xe0, 0x8e, 0x0f, 0x7f, 0xab, - 0x1c, 0x6f, 0x94, 0xaa, 0x4c, 0x50, 0x19, 0x16, 0xf4, 0x87, 0x75, 0xf1, 0x15, 0x00, 0x00, 0xff, - 0xff, 0x4a, 0x6a, 0xbc, 0x50, 0xef, 0x02, 0x00, 0x00, + // 443 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xc1, 0xae, 0xd2, 0x40, + 0x14, 0x86, 0x3b, 0x2a, 0x2c, 0x06, 0x37, 0x0e, 0x37, 0xb9, 0x58, 0x4d, 0x25, 0x5d, 0x08, 0x0b, + 0xdb, 0x1a, 0x54, 0x12, 0x12, 0x57, 0x6c, 0x0c, 0x89, 0x0b, 0x84, 0x9d, 0x1b, 0xd2, 0xca, 0x50, + 0x1a, 0x61, 0xa6, 0x74, 0xa6, 0x09, 0x75, 0xe9, 0x0b, 0x68, 0xc2, 0x4b, 0xf8, 0x28, 0x2c, 0x49, + 0xdc, 0x18, 0x17, 0xc6, 0x80, 0x0f, 0x62, 0x98, 0x1e, 0x42, 0x49, 0xcb, 0x85, 0x55, 0xdb, 0x39, + 0xff, 0xf9, 0xbf, 0x7f, 0xce, 0x4c, 0xf1, 0xed, 0x34, 0xf6, 0x2c, 0x9f, 0x32, 0x2a, 0x02, 0xe1, + 0x2c, 0x62, 0x1a, 0x25, 0x76, 0x18, 0x71, 0xc9, 0x49, 0x35, 0xe2, 0xb3, 0x99, 0x1b, 0x86, 0xf6, + 0x34, 0xf6, 0x46, 0x20, 0xd0, 0x6f, 0x7c, 0xee, 0x73, 0x55, 0x77, 0xf6, 0x6f, 0xa9, 0x54, 0x7f, + 0xea, 0x73, 0xee, 0xcf, 0xa8, 0xe3, 0x86, 0x81, 0xe3, 0x32, 0xc6, 0xa5, 0x2b, 0x03, 0xce, 0x04, + 0x54, 0x6b, 0x59, 0x42, 0xe8, 0x46, 0xee, 0xfc, 0x50, 0x39, 0x61, 0x0b, 0xe9, 0x4a, 0x0a, 0x05, + 0x23, 0x5b, 0x80, 0xe7, 0x28, 0x60, 0x13, 0x00, 0x9a, 0x37, 0x98, 0x7c, 0xd8, 0x47, 0xed, 0x2b, + 0xb7, 0x01, 0x5d, 0xc4, 0x54, 0x48, 0xb3, 0x8f, 0xab, 0x27, 0xab, 0x22, 0xe4, 0x4c, 0x50, 0xd2, + 0xc1, 0xe5, 0x94, 0x5a, 0x43, 0x75, 0xd4, 0xac, 0xb4, 0x9e, 0xd8, 0x05, 0x3b, 0xb3, 0xd3, 0xa6, + 0xee, 0x83, 0xf5, 0x9f, 0x67, 0xda, 0x00, 0x1a, 0xcc, 0x2a, 0x7e, 0xa4, 0x1c, 0x87, 0xfb, 0x6c, + 0x07, 0xcc, 0x7b, 0x80, 0xc3, 0x22, 0x50, 0xda, 0xb8, 0xa4, 0x76, 0x00, 0x10, 0xbd, 0x10, 0xa2, + 0x5a, 0x80, 0x91, 0xca, 0xcd, 0xc7, 0xf8, 0x56, 0xb9, 0xbd, 0x4b, 0x25, 0x3d, 0x36, 0xe1, 0x07, + 0x10, 0xc5, 0xb5, 0x7c, 0x09, 0x70, 0x3d, 0xfc, 0x30, 0x3b, 0x17, 0xa0, 0xd6, 0x0b, 0xa9, 0x99, + 0x7e, 0x60, 0x57, 0xfc, 0xe3, 0x52, 0xeb, 0xf7, 0x7d, 0x5c, 0x52, 0x1c, 0xb2, 0x42, 0xb8, 0x9c, + 0xce, 0x81, 0x34, 0x0a, 0x9d, 0xf2, 0x43, 0xd7, 0x9b, 0x97, 0x85, 0x69, 0x64, 0xb3, 0xfd, 0xf5, + 0xe7, 0xbf, 0xd5, 0xbd, 0x97, 0xc4, 0x76, 0xc6, 0xc9, 0x9c, 0x32, 0x11, 0x70, 0xb6, 0x4c, 0xbe, + 0x1c, 0x3f, 0xac, 0x68, 0xfc, 0xd9, 0xc9, 0xdf, 0x15, 0xf2, 0x0d, 0xe1, 0x92, 0x1a, 0x1c, 0x79, + 0x7e, 0x9e, 0x95, 0x3d, 0x21, 0xbd, 0x71, 0x51, 0x07, 0x91, 0xde, 0xa8, 0x48, 0x0e, 0xb1, 0xae, + 0x8d, 0xa4, 0xce, 0x8c, 0xfc, 0x40, 0xb8, 0x92, 0x19, 0x2a, 0x79, 0x71, 0x9e, 0x97, 0x3f, 0x56, + 0xdd, 0xba, 0x52, 0x0d, 0x19, 0xdf, 0xaa, 0x8c, 0x6d, 0xf2, 0xfa, 0xda, 0x8c, 0xd9, 0x7b, 0xd1, + 0x1d, 0xae, 0xb7, 0x06, 0xda, 0x6c, 0x0d, 0xf4, 0x77, 0x6b, 0xa0, 0xef, 0x3b, 0x43, 0xdb, 0xec, + 0x0c, 0xed, 0xd7, 0xce, 0xd0, 0x3e, 0x76, 0xfc, 0x40, 0x4e, 0x63, 0xcf, 0xfe, 0xc4, 0xe7, 0x77, + 0x39, 0x2f, 0x4f, 0xbc, 0x65, 0x12, 0x52, 0xe1, 0x95, 0xd5, 0x5f, 0xf8, 0xea, 0x7f, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xaa, 0xa7, 0x45, 0xe6, 0x3c, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -247,6 +339,8 @@ type QueryClient interface { Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) // State returns the state of the genesis event. State(ctx context.Context, in *QueryStateRequest, opts ...grpc.CallOption) (*QueryStateResponse, error) + // GenesisInfo returns the genesis info of the rollapp. + GenesisInfo(ctx context.Context, in *QueryGenesisInfoRequest, opts ...grpc.CallOption) (*QueryGenesisInfoResponse, error) } type queryClient struct { @@ -275,12 +369,23 @@ func (c *queryClient) State(ctx context.Context, in *QueryStateRequest, opts ... return out, nil } +func (c *queryClient) GenesisInfo(ctx context.Context, in *QueryGenesisInfoRequest, opts ...grpc.CallOption) (*QueryGenesisInfoResponse, error) { + out := new(QueryGenesisInfoResponse) + err := c.cc.Invoke(ctx, "/rollapp.hub_genesis.Query/GenesisInfo", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { // Params returns the total set of hub-genesis parameters. Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) // State returns the state of the genesis event. State(context.Context, *QueryStateRequest) (*QueryStateResponse, error) + // GenesisInfo returns the genesis info of the rollapp. + GenesisInfo(context.Context, *QueryGenesisInfoRequest) (*QueryGenesisInfoResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -293,6 +398,9 @@ func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsReq func (*UnimplementedQueryServer) State(ctx context.Context, req *QueryStateRequest) (*QueryStateResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method State not implemented") } +func (*UnimplementedQueryServer) GenesisInfo(ctx context.Context, req *QueryGenesisInfoRequest) (*QueryGenesisInfoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GenesisInfo not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -334,6 +442,24 @@ func _Query_State_Handler(srv interface{}, ctx context.Context, dec func(interfa return interceptor(ctx, in, info, handler) } +func _Query_GenesisInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGenesisInfoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).GenesisInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/rollapp.hub_genesis.Query/GenesisInfo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).GenesisInfo(ctx, req.(*QueryGenesisInfoRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "rollapp.hub_genesis.Query", HandlerType: (*QueryServer)(nil), @@ -346,6 +472,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "State", Handler: _Query_State_Handler, }, + { + MethodName: "GenesisInfo", + Handler: _Query_GenesisInfo_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "hub-genesis/query.proto", @@ -463,6 +593,62 @@ func (m *QueryStateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *QueryGenesisInfoRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGenesisInfoRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGenesisInfoRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryGenesisInfoResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryGenesisInfoResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGenesisInfoResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.GenesisInfo.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -514,6 +700,26 @@ func (m *QueryStateResponse) Size() (n int) { return n } +func (m *QueryGenesisInfoRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryGenesisInfoResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.GenesisInfo.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -786,6 +992,139 @@ func (m *QueryStateResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryGenesisInfoRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryGenesisInfoRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGenesisInfoRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryGenesisInfoResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryGenesisInfoResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGenesisInfoResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field GenesisInfo", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.GenesisInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/hub-genesis/types/query.pb.gw.go b/x/hub-genesis/types/query.pb.gw.go index 16c5d1a9..844de7dd 100644 --- a/x/hub-genesis/types/query.pb.gw.go +++ b/x/hub-genesis/types/query.pb.gw.go @@ -69,6 +69,24 @@ func local_request_Query_State_0(ctx context.Context, marshaler runtime.Marshale } +func request_Query_GenesisInfo_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGenesisInfoRequest + var metadata runtime.ServerMetadata + + msg, err := client.GenesisInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_GenesisInfo_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGenesisInfoRequest + var metadata runtime.ServerMetadata + + msg, err := server.GenesisInfo(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -121,6 +139,29 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_GenesisInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_GenesisInfo_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GenesisInfo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -202,6 +243,26 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_GenesisInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_GenesisInfo_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_GenesisInfo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -209,10 +270,14 @@ var ( pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"dymensionxyz", "dymension-rdk", "hub-genesis", "params"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_State_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"dymensionxyz", "dymension-rdk", "hub-genesis", "state"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_GenesisInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"dymensionxyz", "dymension-rdk", "hub-genesis", "genesis_info"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( forward_Query_Params_0 = runtime.ForwardResponseMessage forward_Query_State_0 = runtime.ForwardResponseMessage + + forward_Query_GenesisInfo_0 = runtime.ForwardResponseMessage ) diff --git a/x/hub-genesis/types/state.go b/x/hub-genesis/types/state.go index 4813cfa5..8bd92e18 100644 --- a/x/hub-genesis/types/state.go +++ b/x/hub-genesis/types/state.go @@ -1,27 +1,20 @@ package types import ( - "reflect" - errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/dymensionxyz/gerr-cosmos/gerrc" - "github.com/dymensionxyz/sdk-utils/utils/uibc" + host "github.com/cosmos/ibc-go/v6/modules/core/24-host" ) func (s *State) Validate() error { - for _, a := range s.GetGenesisAccounts() { - if err := a.GetAmount().Validate(); err != nil { - return errorsmod.Wrap(err, "amount") - } - if uibc.IsIBCDenom(a.Amount.GetDenom()) { - return errorsmod.Wrapf(gerrc.ErrInvalidArgument, "ibc denoms not allowed in genesis accounts: %s", a.Amount) + if s.HubPortAndChannel != nil { + if err := host.PortIdentifierValidator(s.HubPortAndChannel.Port); err != nil { + return errorsmod.Wrapf(err, "invalid port Id: %s", s.HubPortAndChannel.Port) } - _, err := sdk.AccAddressFromBech32(a.GetAddress()) - if err != nil { - return errorsmod.Wrap(err, "address from bech 32") + if err := host.ChannelIdentifierValidator(s.HubPortAndChannel.Channel); err != nil { + return errorsmod.Wrapf(err, "invalid channel Id: %s", s.HubPortAndChannel.Channel) } } + return nil } @@ -30,7 +23,7 @@ func (s *State) IsCanonicalHubTransferChannel(port, channel string) bool { } func (s *State) CanonicalHubTransferChannelHasBeenSet() bool { - return !reflect.ValueOf(s.HubPortAndChannel).IsZero() + return s.HubPortAndChannel != nil } func (s *State) SetCanonicalTransferChannel(port, channel string) { diff --git a/x/hub-genesis/types/state.pb.go b/x/hub-genesis/types/state.pb.go index bf25ca94..a809800f 100644 --- a/x/hub-genesis/types/state.pb.go +++ b/x/hub-genesis/types/state.pb.go @@ -5,7 +5,6 @@ package types import ( fmt "fmt" - types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -26,11 +25,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // State holds the state of the genesis event type State struct { - // accounts on the Hub to fund with some bootstrapping transfers - GenesisAccounts []GenesisAccount `protobuf:"bytes,3,rep,name=genesis_accounts,json=genesisAccounts,proto3" json:"genesis_accounts"` - // the number of genesis transfers for which an ack has not yet been received - NumUnackedTransfers uint64 `protobuf:"varint,5,opt,name=num_unacked_transfers,json=numUnackedTransfers,proto3" json:"num_unacked_transfers,omitempty"` - // are outboundTransfersEnabled? This is only true if the genesis protocol has finished + // are outboundTransfersEnabled? This is only true if the genesis protocol has + // finished OutboundTransfersEnabled bool `protobuf:"varint,6,opt,name=outbound_transfers_enabled,json=outboundTransfersEnabled,proto3" json:"outbound_transfers_enabled,omitempty"` // the canonical transfer port and channel for the hub HubPortAndChannel *PortAndChannel `protobuf:"bytes,7,opt,name=hub_port_and_channel,json=hubPortAndChannel,proto3" json:"hub_port_and_channel,omitempty"` @@ -69,20 +65,6 @@ func (m *State) XXX_DiscardUnknown() { var xxx_messageInfo_State proto.InternalMessageInfo -func (m *State) GetGenesisAccounts() []GenesisAccount { - if m != nil { - return m.GenesisAccounts - } - return nil -} - -func (m *State) GetNumUnackedTransfers() uint64 { - if m != nil { - return m.NumUnackedTransfers - } - return 0 -} - func (m *State) GetOutboundTransfersEnabled() bool { if m != nil { return m.OutboundTransfersEnabled @@ -151,99 +133,34 @@ func (m *PortAndChannel) GetChannel() string { return "" } -// GenesisAccount is a struct for the genesis account for the rollapp -type GenesisAccount struct { - // amount of coins to be sent to the genesis address - Amount types.Coin `protobuf:"bytes,1,opt,name=amount,proto3" json:"amount"` - // address is a bech-32 address of the genesis account - Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` -} - -func (m *GenesisAccount) Reset() { *m = GenesisAccount{} } -func (m *GenesisAccount) String() string { return proto.CompactTextString(m) } -func (*GenesisAccount) ProtoMessage() {} -func (*GenesisAccount) Descriptor() ([]byte, []int) { - return fileDescriptor_1ad65c2fe0d953ab, []int{2} -} -func (m *GenesisAccount) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *GenesisAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_GenesisAccount.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *GenesisAccount) XXX_Merge(src proto.Message) { - xxx_messageInfo_GenesisAccount.Merge(m, src) -} -func (m *GenesisAccount) XXX_Size() int { - return m.Size() -} -func (m *GenesisAccount) XXX_DiscardUnknown() { - xxx_messageInfo_GenesisAccount.DiscardUnknown(m) -} - -var xxx_messageInfo_GenesisAccount proto.InternalMessageInfo - -func (m *GenesisAccount) GetAmount() types.Coin { - if m != nil { - return m.Amount - } - return types.Coin{} -} - -func (m *GenesisAccount) GetAddress() string { - if m != nil { - return m.Address - } - return "" -} - func init() { proto.RegisterType((*State)(nil), "rollapp.hub_genesis.State") proto.RegisterType((*PortAndChannel)(nil), "rollapp.hub_genesis.PortAndChannel") - proto.RegisterType((*GenesisAccount)(nil), "rollapp.hub_genesis.GenesisAccount") } func init() { proto.RegisterFile("hub-genesis/state.proto", fileDescriptor_1ad65c2fe0d953ab) } var fileDescriptor_1ad65c2fe0d953ab = []byte{ - // 433 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x52, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0xcd, 0x26, 0x6e, 0x1a, 0xb6, 0x52, 0x09, 0xdb, 0x22, 0x4c, 0x0e, 0xc6, 0x0a, 0x97, 0x5c, - 0xba, 0x56, 0xc3, 0x01, 0x21, 0x21, 0xa4, 0xb6, 0x42, 0x48, 0x3d, 0x21, 0x37, 0x5c, 0xb8, 0x58, - 0xbb, 0xf6, 0x62, 0x5b, 0x8d, 0x77, 0x2c, 0xef, 0x2e, 0x6a, 0xf8, 0x0a, 0x7e, 0x85, 0xbf, 0xe8, - 0xb1, 0x47, 0x4e, 0x08, 0x25, 0x3f, 0x82, 0xec, 0xb5, 0xa1, 0x96, 0xe8, 0xc9, 0x33, 0xf3, 0xde, - 0xcc, 0xf3, 0xce, 0x1b, 0xfc, 0x2c, 0x33, 0xfc, 0x24, 0x15, 0x52, 0xa8, 0x5c, 0x05, 0x4a, 0x33, - 0x2d, 0x68, 0x59, 0x81, 0x06, 0x72, 0x54, 0xc1, 0x7a, 0xcd, 0xca, 0x92, 0x66, 0x86, 0x47, 0x2d, - 0x61, 0x76, 0x9c, 0x42, 0x0a, 0x0d, 0x1e, 0xd4, 0x91, 0xa5, 0xce, 0xbc, 0x18, 0x54, 0x01, 0x2a, - 0xe0, 0x4c, 0x89, 0xe0, 0xeb, 0x29, 0x17, 0x9a, 0x9d, 0x06, 0x31, 0xe4, 0xd2, 0xe2, 0xf3, 0x1f, - 0x43, 0xbc, 0x77, 0x55, 0x8f, 0x26, 0x2b, 0x3c, 0x6d, 0x47, 0x45, 0x2c, 0x8e, 0xc1, 0x48, 0xad, - 0xdc, 0x91, 0x3f, 0x5a, 0x1c, 0x2c, 0x5f, 0xd2, 0xff, 0xe8, 0xd1, 0x0f, 0xf6, 0x7b, 0x66, 0xb9, - 0xe7, 0xce, 0xed, 0xaf, 0x17, 0x83, 0xf0, 0x71, 0xda, 0xab, 0x2a, 0xb2, 0xc4, 0x4f, 0xa5, 0x29, - 0x22, 0x23, 0x59, 0x7c, 0x2d, 0x92, 0x48, 0x57, 0x4c, 0xaa, 0x2f, 0xa2, 0x52, 0xee, 0x9e, 0x8f, - 0x16, 0x4e, 0x78, 0x24, 0x4d, 0xf1, 0xc9, 0x62, 0xab, 0x0e, 0x22, 0x6f, 0xf1, 0x0c, 0x8c, 0xe6, - 0x60, 0xe4, 0xbd, 0x86, 0x48, 0x48, 0xc6, 0xd7, 0x22, 0x71, 0xc7, 0x3e, 0x5a, 0x4c, 0x42, 0xb7, - 0x63, 0xfc, 0x6d, 0x7b, 0x6f, 0x71, 0xb2, 0xc2, 0xc7, 0xf5, 0x6f, 0x96, 0x50, 0xe9, 0x88, 0xc9, - 0x24, 0x8a, 0x33, 0x26, 0xa5, 0x58, 0xbb, 0xfb, 0x3e, 0x7a, 0xf0, 0x2d, 0x1f, 0xa1, 0xd2, 0x67, - 0x32, 0xb9, 0xb0, 0xd4, 0xf0, 0x49, 0x66, 0x78, 0xbf, 0x74, 0xe9, 0x4c, 0xd0, 0x74, 0x78, 0xe9, - 0x4c, 0x86, 0xd3, 0xd1, 0xfc, 0x1d, 0x3e, 0xec, 0xa3, 0x84, 0x60, 0xa7, 0xd6, 0x73, 0x91, 0x8f, - 0x16, 0x8f, 0xc2, 0x26, 0x26, 0x2e, 0xde, 0xef, 0xa4, 0x87, 0x4d, 0xb9, 0x4b, 0xe7, 0x31, 0x3e, - 0xec, 0x2f, 0x8f, 0xbc, 0xc6, 0x63, 0x56, 0xd4, 0x51, 0x33, 0xe1, 0x60, 0xf9, 0x9c, 0x5a, 0xdb, - 0x68, 0x6d, 0x1b, 0x6d, 0x6d, 0xa3, 0x17, 0x90, 0xcb, 0x76, 0xcf, 0x2d, 0xbd, 0x16, 0x61, 0x49, - 0x52, 0x09, 0xa5, 0x3a, 0x91, 0x36, 0x3d, 0xbf, 0xba, 0xdd, 0x7a, 0xe8, 0x6e, 0xeb, 0xa1, 0xdf, - 0x5b, 0x0f, 0x7d, 0xdf, 0x79, 0x83, 0xbb, 0x9d, 0x37, 0xf8, 0xb9, 0xf3, 0x06, 0x9f, 0xdf, 0xa4, - 0xb9, 0xce, 0x0c, 0xa7, 0x31, 0x14, 0x41, 0xb2, 0x29, 0x84, 0x54, 0x39, 0xc8, 0x9b, 0xcd, 0xb7, - 0x7f, 0xc9, 0x49, 0x95, 0x5c, 0x07, 0x37, 0xc1, 0xfd, 0xf3, 0xd3, 0x9b, 0x52, 0x28, 0x3e, 0x6e, - 0x8e, 0xe6, 0xd5, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x96, 0x91, 0xc3, 0xaf, 0x9a, 0x02, 0x00, - 0x00, + // 295 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xcf, 0x28, 0x4d, 0xd2, + 0x4d, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2f, 0x2e, 0x49, 0x2c, 0x49, 0xd5, 0x2b, 0x28, + 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x2e, 0xca, 0xcf, 0xc9, 0x49, 0x2c, 0x28, 0xd0, 0xcb, 0x28, 0x4d, + 0x8a, 0x87, 0x2a, 0x90, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xcb, 0xeb, 0x83, 0x58, 0x10, 0xa5, + 0x4a, 0x0b, 0x19, 0xb9, 0x58, 0x83, 0x41, 0x5a, 0x85, 0x6c, 0xb8, 0xa4, 0xf2, 0x4b, 0x4b, 0x92, + 0xf2, 0x4b, 0xf3, 0x52, 0xe2, 0x4b, 0x8a, 0x12, 0xf3, 0x8a, 0xd3, 0x52, 0x8b, 0x8a, 0xe3, 0x53, + 0xf3, 0x12, 0x93, 0x72, 0x52, 0x53, 0x24, 0xd8, 0x14, 0x18, 0x35, 0x38, 0x82, 0x24, 0x60, 0x2a, + 0x42, 0x60, 0x0a, 0x5c, 0x21, 0xf2, 0x42, 0x21, 0x5c, 0x22, 0x20, 0xcb, 0x0a, 0xf2, 0x8b, 0x4a, + 0xe2, 0x13, 0xf3, 0x52, 0xe2, 0x93, 0x33, 0x12, 0xf3, 0xf2, 0x52, 0x73, 0x24, 0xd8, 0x15, 0x18, + 0x35, 0xb8, 0x8d, 0x94, 0xf5, 0xb0, 0xb8, 0x48, 0x2f, 0x20, 0xbf, 0xa8, 0xc4, 0x31, 0x2f, 0xc5, + 0x19, 0xa2, 0x34, 0x48, 0x30, 0xa3, 0x34, 0x09, 0x55, 0xc8, 0x8b, 0x85, 0x83, 0x51, 0x80, 0x4d, + 0xc9, 0x8e, 0x8b, 0x0f, 0x55, 0x5c, 0x48, 0x88, 0x8b, 0x05, 0x64, 0x93, 0x04, 0xa3, 0x02, 0xa3, + 0x06, 0x67, 0x10, 0x98, 0x2d, 0x24, 0xc1, 0xc5, 0x0e, 0xb3, 0x94, 0x09, 0x2c, 0x0c, 0xe3, 0x3a, + 0x05, 0x9f, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, + 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x65, 0x7a, 0x66, 0x49, + 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x4a, 0x65, 0x6e, 0x6a, 0x5e, 0x71, 0x66, 0x7e, + 0x5e, 0x45, 0x65, 0x15, 0x82, 0xa3, 0x5b, 0x94, 0x92, 0xad, 0x5f, 0xa1, 0x8f, 0x1c, 0xd2, 0x25, + 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0xf0, 0x33, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xc4, + 0xa0, 0x37, 0x1e, 0x85, 0x01, 0x00, 0x00, } func (m *State) Marshal() (dAtA []byte, err error) { @@ -288,25 +205,6 @@ func (m *State) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x30 } - if m.NumUnackedTransfers != 0 { - i = encodeVarintState(dAtA, i, uint64(m.NumUnackedTransfers)) - i-- - dAtA[i] = 0x28 - } - if len(m.GenesisAccounts) > 0 { - for iNdEx := len(m.GenesisAccounts) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.GenesisAccounts[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintState(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - } return len(dAtA) - i, nil } @@ -347,46 +245,6 @@ func (m *PortAndChannel) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *GenesisAccount) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *GenesisAccount) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *GenesisAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Address) > 0 { - i -= len(m.Address) - copy(dAtA[i:], m.Address) - i = encodeVarintState(dAtA, i, uint64(len(m.Address))) - i-- - dAtA[i] = 0x12 - } - { - size, err := m.Amount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintState(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - func encodeVarintState(dAtA []byte, offset int, v uint64) int { offset -= sovState(v) base := offset @@ -404,15 +262,6 @@ func (m *State) Size() (n int) { } var l int _ = l - if len(m.GenesisAccounts) > 0 { - for _, e := range m.GenesisAccounts { - l = e.Size() - n += 1 + l + sovState(uint64(l)) - } - } - if m.NumUnackedTransfers != 0 { - n += 1 + sovState(uint64(m.NumUnackedTransfers)) - } if m.OutboundTransfersEnabled { n += 2 } @@ -440,21 +289,6 @@ func (m *PortAndChannel) Size() (n int) { return n } -func (m *GenesisAccount) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.Amount.Size() - n += 1 + l + sovState(uint64(l)) - l = len(m.Address) - if l > 0 { - n += 1 + l + sovState(uint64(l)) - } - return n -} - func sovState(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -490,59 +324,6 @@ func (m *State) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: State: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field GenesisAccounts", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowState - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthState - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthState - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.GenesisAccounts = append(m.GenesisAccounts, GenesisAccount{}) - if err := m.GenesisAccounts[len(m.GenesisAccounts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field NumUnackedTransfers", wireType) - } - m.NumUnackedTransfers = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowState - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.NumUnackedTransfers |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } case 6: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field OutboundTransfersEnabled", wireType) @@ -734,121 +515,6 @@ func (m *PortAndChannel) Unmarshal(dAtA []byte) error { } return nil } -func (m *GenesisAccount) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowState - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: GenesisAccount: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: GenesisAccount: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowState - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthState - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthState - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowState - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthState - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthState - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Address = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipState(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthState - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func skipState(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/mint/keeper/keeper.go b/x/mint/keeper/keeper.go index df7c9f90..11502260 100644 --- a/x/mint/keeper/keeper.go +++ b/x/mint/keeper/keeper.go @@ -116,3 +116,8 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { k.paramSpace.SetParamSet(ctx, ¶ms) } + +// MintDenom returns the minting denomination. +func (k Keeper) MintDenom(ctx sdk.Context) string { + return k.GetParams(ctx).MintDenom +}