From ed8bf1258ae4ff63ec186052fb9110d8f22216be Mon Sep 17 00:00:00 2001 From: Steve Miskovetz Date: Fri, 27 Oct 2023 16:49:20 -0600 Subject: [PATCH 1/2] ISM refactor, add custom ISMs --- docs/proto/proto-docs.md | 243 ++--- interchaintest/tests/cosmos_e2e_test.go | 3 +- proto/hyperlane/ism/v1/genesis.proto | 4 +- proto/hyperlane/ism/v1/ism.proto | 10 +- proto/hyperlane/ism/v1/query.proto | 25 +- proto/hyperlane/ism/v1/tx.proto | 40 +- x/igp/keeper/test_data_test.go | 2 +- x/igp/placeholder | 0 x/ism/keeper/genesis.go | 68 +- x/ism/keeper/genesis_test.go | 46 +- x/ism/keeper/grpc_query.go | 60 +- x/ism/keeper/grpc_query_test.go | 185 +++- x/ism/keeper/keeper.go | 13 +- x/ism/keeper/keeper_test.go | 2 +- x/ism/keeper/msg_server.go | 49 +- x/ism/keeper/msg_server_test.go | 61 +- x/ism/keeper/store.go | 153 +++ x/ism/keeper/test_data_test.go | 2 +- x/ism/module.go | 3 +- x/ism/types/abstract_ism.go | 3 +- x/ism/types/codec.go | 5 + x/ism/types/events.go | 5 +- x/ism/types/genesis.pb.go | 95 +- x/ism/types/ism.pb.go | 299 +++++- x/ism/types/keys.go | 10 +- .../types/legacy_multisig/legacy_multisig.go | 23 +- .../merkle_root_multisig.go | 23 +- .../message_id_mulitsig.go | 23 +- x/ism/types/msgs.go | 54 +- x/ism/types/query.go | 56 ++ x/ism/types/query.pb.go | 903 ++++++++++++++++-- x/ism/types/query.pb.gw.go | 138 +++ x/ism/types/tx.pb.go | 499 +++++++++- x/mailbox/keeper/msg_server.go | 4 +- 34 files changed, 2717 insertions(+), 392 deletions(-) delete mode 100644 x/igp/placeholder create mode 100644 x/ism/keeper/store.go create mode 100644 x/ism/types/query.go diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index 83dcbf0..fcbf232 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -4,102 +4,95 @@ ## Table of Contents -- [hyperlane/mailbox/v1/types.proto](#hyperlane/mailbox/v1/types.proto) - - [MessageDelivered](#hyperlane.mailbox.v1.MessageDelivered) - - [Tree](#hyperlane.mailbox.v1.Tree) +- [hyperlane/announce/v1/types.proto](#hyperlane/announce/v1/types.proto) + - [GenesisAnnouncement](#hyperlane.announce.v1.GenesisAnnouncement) + - [StorageMetadata](#hyperlane.announce.v1.StorageMetadata) + - [StoredAnnouncement](#hyperlane.announce.v1.StoredAnnouncement) + - [StoredAnnouncements](#hyperlane.announce.v1.StoredAnnouncements) -- [hyperlane/mailbox/v1/genesis.proto](#hyperlane/mailbox/v1/genesis.proto) - - [GenesisState](#hyperlane.mailbox.v1.GenesisState) +- [hyperlane/announce/v1/genesis.proto](#hyperlane/announce/v1/genesis.proto) + - [GenesisState](#hyperlane.announce.v1.GenesisState) -- [hyperlane/mailbox/v1/query.proto](#hyperlane/mailbox/v1/query.proto) - - [QueryCurrentTreeMetadataRequest](#hyperlane.mailbox.v1.QueryCurrentTreeMetadataRequest) - - [QueryCurrentTreeMetadataResponse](#hyperlane.mailbox.v1.QueryCurrentTreeMetadataResponse) - - [QueryCurrentTreeRequest](#hyperlane.mailbox.v1.QueryCurrentTreeRequest) - - [QueryCurrentTreeResponse](#hyperlane.mailbox.v1.QueryCurrentTreeResponse) - - [QueryDomainRequest](#hyperlane.mailbox.v1.QueryDomainRequest) - - [QueryDomainResponse](#hyperlane.mailbox.v1.QueryDomainResponse) - - [QueryMsgDeliveredRequest](#hyperlane.mailbox.v1.QueryMsgDeliveredRequest) - - [QueryMsgDeliveredResponse](#hyperlane.mailbox.v1.QueryMsgDeliveredResponse) +- [hyperlane/announce/v1/query.proto](#hyperlane/announce/v1/query.proto) + - [GetAnnouncedStorageLocationsRequest](#hyperlane.announce.v1.GetAnnouncedStorageLocationsRequest) + - [GetAnnouncedStorageLocationsResponse](#hyperlane.announce.v1.GetAnnouncedStorageLocationsResponse) + - [GetAnnouncedValidatorsRequest](#hyperlane.announce.v1.GetAnnouncedValidatorsRequest) + - [GetAnnouncedValidatorsResponse](#hyperlane.announce.v1.GetAnnouncedValidatorsResponse) - - [Query](#hyperlane.mailbox.v1.Query) + - [Query](#hyperlane.announce.v1.Query) -- [hyperlane/mailbox/v1/tx.proto](#hyperlane/mailbox/v1/tx.proto) - - [MsgDispatch](#hyperlane.mailbox.v1.MsgDispatch) - - [MsgDispatchResponse](#hyperlane.mailbox.v1.MsgDispatchResponse) - - [MsgProcess](#hyperlane.mailbox.v1.MsgProcess) - - [MsgProcessResponse](#hyperlane.mailbox.v1.MsgProcessResponse) +- [hyperlane/announce/v1/tx.proto](#hyperlane/announce/v1/tx.proto) + - [MsgAnnouncement](#hyperlane.announce.v1.MsgAnnouncement) + - [MsgAnnouncementResponse](#hyperlane.announce.v1.MsgAnnouncementResponse) - - [Msg](#hyperlane.mailbox.v1.Msg) + - [Msg](#hyperlane.announce.v1.Msg) - [Scalar Value Types](#scalar-value-types) - +

Top

-## hyperlane/mailbox/v1/types.proto +## hyperlane/announce/v1/types.proto - + -### MessageDelivered -Mailbox delivered message +### GenesisAnnouncement +Genesis helper type for Hyperlane's Announcement. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `id` | [string](#string) | | Message id (hash) | +| `announcements` | [StoredAnnouncements](#hyperlane.announce.v1.StoredAnnouncements) | | | +| `validator` | [bytes](#bytes) | | The validator (in eth address format) that announced | - + -### Tree -Hyperlane's tree +### StorageMetadata +Helper type for Hyperlane's getAnnouncedStorageLocations. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `count` | [uint32](#uint32) | | Count of items inserted to tree | -| `branch` | [bytes](#bytes) | repeated | Each item inserted | +| `metadata` | [string](#string) | repeated | | - - + - +### StoredAnnouncement +Helper type for Hyperlane's Announcement. - +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `storage_location` | [string](#string) | | location where signatures will be stored | - -

Top

-## hyperlane/mailbox/v1/genesis.proto - + -### GenesisState -Hyperlane mailbox's keeper genesis state +### StoredAnnouncements +Helper type for Hyperlane's Announcement. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `tree` | [Tree](#hyperlane.mailbox.v1.Tree) | | Each genesis tree entry | -| `delivered_messages` | [MessageDelivered](#hyperlane.mailbox.v1.MessageDelivered) | repeated | Each message that has been delivered | -| `domain` | [uint32](#uint32) | | The domain of this chain module, assigned by hyperlane | +| `announcement` | [StoredAnnouncement](#hyperlane.announce.v1.StoredAnnouncement) | repeated | | @@ -115,118 +108,97 @@ Hyperlane mailbox's keeper genesis state - +

Top

-## hyperlane/mailbox/v1/query.proto - - - - - -### QueryCurrentTreeMetadataRequest -QueryCurrentTreeMetadataRequest is the request type for the Query/Tree -metadata RPC method. - - - +## hyperlane/announce/v1/genesis.proto - + -### QueryCurrentTreeMetadataResponse -QueryCurrentTreeResponseResponse is the response type for the Query/Tree -metadata RPC method. +### GenesisState +Hyperlane Announce's keeper genesis state | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `root` | [bytes](#bytes) | | | -| `count` | [uint32](#uint32) | | | - - - +| `announcements` | [GenesisAnnouncement](#hyperlane.announce.v1.GenesisAnnouncement) | repeated | | - - -### QueryCurrentTreeRequest -QueryCurrentTreeRequest is the request type for the Query/Tree RPC method - + + + - + -### QueryCurrentTreeResponse -QueryCurrentTreeResponse is the response type for the Query/Tree RPC method -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `branches` | [bytes](#bytes) | repeated | | -| `count` | [uint32](#uint32) | | | + +

Top

+## hyperlane/announce/v1/query.proto + +### GetAnnouncedStorageLocationsRequest +GetAnnouncedStorageLocationsRequest is the request type for the +GetAnnouncedStorageLocations RPC method. - -### QueryDomainRequest -QueryDomain is the request type for the Query/Domain RPC -method. +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `validator` | [bytes](#bytes) | repeated | list of validators where each validator is in hex-encoded eth address format (20 bytes) | - + -### QueryDomainResponse -QueryDomainResponse is the response type for the Query/Domain RPC method. +### GetAnnouncedStorageLocationsResponse +GetAnnouncedStorageLocationsResponse is the response type for the +GetAnnouncedStorageLocations RPC method. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `domain` | [uint32](#uint32) | | | - +| `metadata` | [StorageMetadata](#hyperlane.announce.v1.StorageMetadata) | repeated | | - -### QueryMsgDeliveredRequest -QueryMsgDeliveredRequest is the request type to check if message was -delivered + +### GetAnnouncedValidatorsRequest +GetAnnouncedValidatorsRequest is the request type for the +GetAnnouncedValidators RPC method. -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `message_id` | [bytes](#bytes) | | | + - - -### QueryMsgDeliveredResponse -QueryMsgDeliveredResponse is the response type if message was delivered +### GetAnnouncedValidatorsResponse +GetAnnouncedValidatorsResponse is the response type for the +GetAnnouncedValidators RPC method. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `delivered` | [bool](#bool) | | | +| `validator` | [string](#string) | repeated | list of validators where each validator is in hex-encoded eth address format (20 bytes) | @@ -239,83 +211,49 @@ QueryMsgDeliveredResponse is the response type if message was delivered - + ### Query -Query service for hyperlane mailbox module +Query service for hyperlane announce module | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `CurrentTreeMetadata` | [QueryCurrentTreeMetadataRequest](#hyperlane.mailbox.v1.QueryCurrentTreeMetadataRequest) | [QueryCurrentTreeMetadataResponse](#hyperlane.mailbox.v1.QueryCurrentTreeMetadataResponse) | Get current tree metadata | GET|/hyperlane/mailbox/v1/tree_metadata| -| `Domain` | [QueryDomainRequest](#hyperlane.mailbox.v1.QueryDomainRequest) | [QueryDomainResponse](#hyperlane.mailbox.v1.QueryDomainResponse) | Get domain | GET|/hyperlane/mailbox/v1/domain| -| `CurrentTree` | [QueryCurrentTreeRequest](#hyperlane.mailbox.v1.QueryCurrentTreeRequest) | [QueryCurrentTreeResponse](#hyperlane.mailbox.v1.QueryCurrentTreeResponse) | Get current tree | GET|/hyperlane/mailbox/v1/tree| -| `MsgDelivered` | [QueryMsgDeliveredRequest](#hyperlane.mailbox.v1.QueryMsgDeliveredRequest) | [QueryMsgDeliveredResponse](#hyperlane.mailbox.v1.QueryMsgDeliveredResponse) | Check if message was delivered | GET|/hyperlane/mailbox/v1/delivered| +| `GetAnnouncedStorageLocations` | [GetAnnouncedStorageLocationsRequest](#hyperlane.announce.v1.GetAnnouncedStorageLocationsRequest) | [GetAnnouncedStorageLocationsResponse](#hyperlane.announce.v1.GetAnnouncedStorageLocationsResponse) | Gets the announced storage locations (where signatures are stored) for the requested validators | GET|/hyperlane/announce/v1/get_announced_storage_locations| +| `GetAnnouncedValidators` | [GetAnnouncedValidatorsRequest](#hyperlane.announce.v1.GetAnnouncedValidatorsRequest) | [GetAnnouncedValidatorsResponse](#hyperlane.announce.v1.GetAnnouncedValidatorsResponse) | Gets a list of validators that have made announcements | GET|/hyperlane/announce/v1/get_announced_validators| - +

Top

-## hyperlane/mailbox/v1/tx.proto - - - - - -### MsgDispatch -MsgDispatch defines the request type for the Dispatch rpc. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `sender` | [string](#string) | | | -| `destination_domain` | [uint32](#uint32) | | | -| `recipient_address` | [string](#string) | | | -| `message_body` | [string](#string) | | | - - - - - - - - -### MsgDispatchResponse -MsgDispatchResponse defines the Dispatch response type. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `message_id` | [string](#string) | | | - - - +## hyperlane/announce/v1/tx.proto - + -### MsgProcess -MsgProcess defines the request type for the Process rpc. +### MsgAnnouncement +MsgAnnouncement Announces a validator signature storage location | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `sender` | [string](#string) | | | -| `metadata` | [string](#string) | | | -| `message` | [string](#string) | | | +| `validator` | [bytes](#bytes) | | The validator (in eth address format) that is announcing its storage location | +| `storage_location` | [string](#string) | | location where signatures will be stored | +| `signature` | [bytes](#bytes) | | signed validator announcement | - + -### MsgProcessResponse -MsgProcessResponse defines the Process response type. +### MsgAnnouncementResponse +MsgAnnouncementResponse defines the MsgAnnouncementResponse response type. @@ -328,15 +266,14 @@ MsgProcessResponse defines the Process response type. - + ### Msg -Msg defines the hyperlane mailbox Msg service. +Msg defines the hyperlane announce Msg service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `Dispatch` | [MsgDispatch](#hyperlane.mailbox.v1.MsgDispatch) | [MsgDispatchResponse](#hyperlane.mailbox.v1.MsgDispatchResponse) | Dispatch sends interchain messages | | -| `Process` | [MsgProcess](#hyperlane.mailbox.v1.MsgProcess) | [MsgProcessResponse](#hyperlane.mailbox.v1.MsgProcessResponse) | Process delivers interchain messages | | +| `Announcement` | [MsgAnnouncement](#hyperlane.announce.v1.MsgAnnouncement) | [MsgAnnouncementResponse](#hyperlane.announce.v1.MsgAnnouncementResponse) | Announces a validator signature storage location | | diff --git a/interchaintest/tests/cosmos_e2e_test.go b/interchaintest/tests/cosmos_e2e_test.go index 9ed6257..d2e353c 100644 --- a/interchaintest/tests/cosmos_e2e_test.go +++ b/interchaintest/tests/cosmos_e2e_test.go @@ -12,7 +12,7 @@ import ( "strings" "testing" "time" - + "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -271,7 +271,6 @@ func TestHyperlaneCosmosE2E(t *testing.T) { require.NoError(t, err) require.Equal(t, simd1Oracle.FormattedAddress(), oracleEvtAddr) - // This should succeed, and we verify the events contain the expected domain/exchange rate/gas price. setGasOutput := helpers.CallSetGasPriceMsg(t, ctx, simd1, simd1Oracle.KeyName(), igpId, destDomainStr, gasPrice.String(), exchangeRate.String()) setGasTxHash2 := helpers.ParseTxHash(string(setGasOutput)) diff --git a/proto/hyperlane/ism/v1/genesis.proto b/proto/hyperlane/ism/v1/genesis.proto index 1364133..859734e 100644 --- a/proto/hyperlane/ism/v1/genesis.proto +++ b/proto/hyperlane/ism/v1/genesis.proto @@ -9,5 +9,7 @@ option go_package = "github.com/strangelove-ventures/hyperlane-cosmos/x/ism/type // Hyperlane ISM's keeper genesis state message GenesisState { // Genesis default ISM - repeated Ism default_ism = 1 [ (gogoproto.nullable) = false ]; + repeated DefaultIsm default_ism = 1 [ (gogoproto.nullable) = false ]; + // Custom Isms + repeated CustomIsm custom_ism = 2 [ (gogoproto.nullable) = false ]; } \ No newline at end of file diff --git a/proto/hyperlane/ism/v1/ism.proto b/proto/hyperlane/ism/v1/ism.proto index b6ab379..18c3dcb 100644 --- a/proto/hyperlane/ism/v1/ism.proto +++ b/proto/hyperlane/ism/v1/ism.proto @@ -7,7 +7,13 @@ import "google/protobuf/any.proto"; option go_package = "github.com/strangelove-ventures/hyperlane-cosmos/x/ism/types"; // Hyperlane's default ISM -message Ism { +message DefaultIsm { uint32 origin = 1; google.protobuf.Any abstract_ism = 2; -} \ No newline at end of file +} + +// Hyperlane's custom ISM +message CustomIsm { + uint32 index = 1; + google.protobuf.Any abstract_ism = 2; +} diff --git a/proto/hyperlane/ism/v1/query.proto b/proto/hyperlane/ism/v1/query.proto index c1be003..b8d6572 100644 --- a/proto/hyperlane/ism/v1/query.proto +++ b/proto/hyperlane/ism/v1/query.proto @@ -19,6 +19,15 @@ service Query { returns (QueryAllDefaultIsmsResponse) { option (google.api.http).get = "/hyperlane/ism/v1/all_default_isms"; } + // Get custom ISM + rpc CustomIsm(QueryCustomIsmRequest) returns (QueryCustomIsmResponse) { + option (google.api.http).get = "/hyperlane/ism/v1/custom_ism"; + } + // Get all custom ISMs + rpc AllCustomIsms(QueryAllCustomIsmsRequest) + returns (QueryAllCustomIsmsResponse) { + option (google.api.http).get = "/hyperlane/ism/v1/all_custom_isms"; + } } // QueryDefaultIsmRequest is the request type for the DefaultIsm RPC method. @@ -33,4 +42,18 @@ message QueryAllDefaultIsmsRequest {} // QueryAllDefaultIsmResponse is the response type for the AllDefaultIsms RPC // method. -message QueryAllDefaultIsmsResponse { repeated Ism default_isms = 1; } \ No newline at end of file +message QueryAllDefaultIsmsResponse { repeated DefaultIsm default_isms = 1; } + +// QueryCustomIsmRequest is the request type for the CustomIsm RPC method. +message QueryCustomIsmRequest { uint32 ism_id = 1; } + +// QueryCustomIsmResponse is the response type for the CustomIsm RPC method. +message QueryCustomIsmResponse { google.protobuf.Any custom_ism = 1; } + +// QueryAllCustomIsmRequest is the request type for the AllCustomIsms RPC +// method. +message QueryAllCustomIsmsRequest {} + +// QueryAllCustomIsmResponse is the response type for the AllCustomIsms RPC +// method. +message QueryAllCustomIsmsResponse { repeated CustomIsm custom_isms = 1; } \ No newline at end of file diff --git a/proto/hyperlane/ism/v1/tx.proto b/proto/hyperlane/ism/v1/tx.proto index cbba0e8..8b0652a 100644 --- a/proto/hyperlane/ism/v1/tx.proto +++ b/proto/hyperlane/ism/v1/tx.proto @@ -1,21 +1,55 @@ syntax = "proto3"; package hyperlane.ism.v1; +import "amino/amino.proto"; +import "cosmos/msg/v1/msg.proto"; +import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; +import "google/protobuf/any.proto"; import "hyperlane/ism/v1/ism.proto"; option go_package = "github.com/strangelove-ventures/hyperlane-cosmos/x/ism/types"; // Msg defines the hyperlane ISM Msg service. service Msg { + option (cosmos.msg.v1.service) = true; + + // Create a custom ISM + rpc CreateIsm(MsgCreateIsm) returns (MsgCreateIsmResponse); + // SetDefaultIsm defines a rpc handler method for MsgSetDefaultIsm. rpc SetDefaultIsm(MsgSetDefaultIsm) returns (MsgSetDefaultIsmResponse); } // MsgSetDefaultIsm defines the request type for the SetDefaultIsm rpc. message MsgSetDefaultIsm { - string signer = 1; - repeated Ism isms = 2; + option (cosmos.msg.v1.signer) = "sender"; + option (amino.name) = "hyperlane-ism/MsgSetDefaultIsm"; + + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string signer = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + repeated DefaultIsm isms = 2; } // MsgSetDefaultIsmResponse defines the Msg/SetDefaultIsm response type -message MsgSetDefaultIsmResponse {} \ No newline at end of file +message MsgSetDefaultIsmResponse {} + +// MsgCreateIsm defines the request type to create a hyperlane ISM +message MsgCreateIsm { + option (cosmos.msg.v1.signer) = "sender"; + option (amino.name) = "hyperlane-ism/MsgCreateIsm"; + + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + string signer = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + google.protobuf.Any ism = 2; +} + +// MsgCreateIsmResponse deines the MsgCreateIsm response type +message MsgCreateIsmResponse { + // The unique ID assigned to the newly created ISM + uint32 ism_id = 1; +} \ No newline at end of file diff --git a/x/igp/keeper/test_data_test.go b/x/igp/keeper/test_data_test.go index 7c41e45..bd9cd9f 100644 --- a/x/igp/keeper/test_data_test.go +++ b/x/igp/keeper/test_data_test.go @@ -22,7 +22,7 @@ var messages = [...]string{ "000000045a000000010000000000000000000000009311cee522a7c122b843b66cc31c6a63e2f926410000a86a0000000000000000000000002a925cd8a5d919c5c6599633090c37fe38a561b648656c6c6f21", } -var defaultIsms = []*types.Ism{ +var defaultIsms = []*types.DefaultIsm{ { Origin: 1, // Ethereum origin AbstractIsm: types.MustPackAbstractIsm( diff --git a/x/igp/placeholder b/x/igp/placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/x/ism/keeper/genesis.go b/x/ism/keeper/genesis.go index 08603e3..f8a541e 100644 --- a/x/ism/keeper/genesis.go +++ b/x/ism/keeper/genesis.go @@ -10,7 +10,7 @@ import ( "github.com/strangelove-ventures/hyperlane-cosmos/x/ism/types" ) -// InitGenesis initializes the hyperlane mailbox module's state from a provided genesis +// InitGenesis initializes the hyperlane ISM module's state from a provided genesis // state. func (k Keeper) InitGenesis(ctx sdk.Context, gs types.GenesisState) error { for _, originIsm := range gs.DefaultIsm { @@ -18,21 +18,42 @@ func (k Keeper) InitGenesis(ctx sdk.Context, gs types.GenesisState) error { if err != nil { return err } - k.defaultIsm[originIsm.Origin] = ism + err = k.storeDefaultIsm(ctx, originIsm.Origin, ism) + if err != nil { + return err + } + } + for _, customIsm := range gs.CustomIsm { + ism, err := types.UnpackAbstractIsm(customIsm.AbstractIsm) + if err != nil { + return err + } + err = k.storeCustomIsm(ctx, customIsm.Index, ism) + if err != nil { + return err + } } return nil } -// ExportGenesis returns the hyperlane mailbox module's exported genesis. +// ExportGenesis returns the hyperlane ISM module's exported genesis. func (k Keeper) ExportGenesis(ctx sdk.Context) types.GenesisState { + return types.GenesisState{ + DefaultIsm: k.ExportDefaultIsms(ctx), + CustomIsm: k.ExportCustomIsms(ctx), + } +} + +// ExportDefaultIsms return the default ISMs +func (k Keeper) ExportDefaultIsms(ctx sdk.Context) []types.DefaultIsm { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, []byte(types.KeyOriginsDefaultIsm)) defer iterator.Close() - var genesisState types.GenesisState + var defaultIsms []types.DefaultIsm for ; iterator.Valid(); iterator.Next() { - originBytes := bytes.TrimPrefix(iterator.Key(), []byte(fmt.Sprintf("%s/", types.KeyOriginsDefaultIsm))) - origin, err := strconv.ParseUint(string(originBytes), 10, 32) + originBz := bytes.TrimPrefix(iterator.Key(), []byte(fmt.Sprintf("%s/", types.KeyOriginsDefaultIsm))) + origin, err := strconv.ParseUint(string(originBz), 10, 32) if err != nil { panic(err) } @@ -45,11 +66,42 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) types.GenesisState { if err != nil { panic(err) } - genesisState.DefaultIsm = append(genesisState.DefaultIsm, types.Ism{ + defaultIsms = append(defaultIsms, types.DefaultIsm{ Origin: uint32(origin), AbstractIsm: ismAny, }) } - return genesisState + return defaultIsms } + +// ExportCustomIsms return the custom ISMs +func (k Keeper) ExportCustomIsms(ctx sdk.Context) []types.CustomIsm { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, []byte(types.KeyCustomIsm)) + defer iterator.Close() + + var customIsms []types.CustomIsm + for ; iterator.Valid(); iterator.Next() { + indexBz := bytes.TrimPrefix(iterator.Key(), []byte(fmt.Sprintf("%s/", types.KeyCustomIsm))) + index, err := strconv.ParseUint(string(indexBz), 10, 32) + if err != nil { + panic(err) + } + var ism types.AbstractIsm + err = k.cdc.UnmarshalInterface(iterator.Value(), &ism) + if err != nil { + panic(err) + } + ismAny, err := types.PackAbstractIsm(ism) + if err != nil { + panic(err) + } + customIsms = append(customIsms, types.CustomIsm{ + Index: uint32(index), + AbstractIsm: ismAny, + }) + } + + return customIsms +} \ No newline at end of file diff --git a/x/ism/keeper/genesis_test.go b/x/ism/keeper/genesis_test.go index 4b51a4d..54e275f 100644 --- a/x/ism/keeper/genesis_test.go +++ b/x/ism/keeper/genesis_test.go @@ -16,12 +16,28 @@ func (suite *KeeperTestSuite) TestGenesis() { _, err := suite.msgServer.SetDefaultIsm(suite.ctx, msg) suite.Require().NoError(err) + customIsmMsg1 := types.NewMsgCreateIsm(signer, defaultIsms[0].AbstractIsm) + _, err = suite.msgServer.CreateIsm(suite.ctx, customIsmMsg1) + suite.Require().NoError(err) + + customIsmMsg2 := types.NewMsgCreateIsm(signer, defaultIsms[1].AbstractIsm) + _, err = suite.msgServer.CreateIsm(suite.ctx, customIsmMsg2) + suite.Require().NoError(err) + + customIsmMsg3 := types.NewMsgCreateIsm(signer, defaultIsms[2].AbstractIsm) + _, err = suite.msgServer.CreateIsm(suite.ctx, customIsmMsg3) + suite.Require().NoError(err) + gs := suite.keeper.ExportGenesis(suite.ctx) for i := 0; i < len(defaultIsms); i++ { expectedIsm := types.MustUnpackAbstractIsm(defaultIsms[i].AbstractIsm) - actualIsm := types.MustUnpackAbstractIsm(gs.DefaultIsm[i].AbstractIsm) + actualDefaultIsm := types.MustUnpackAbstractIsm(gs.DefaultIsm[i].AbstractIsm) suite.Require().Equal(defaultIsms[i].Origin, gs.DefaultIsm[i].Origin) - suite.Require().Equal(expectedIsm, actualIsm) + suite.Require().Equal(expectedIsm, actualDefaultIsm) + + actualCustomIsm := types.MustUnpackAbstractIsm(gs.CustomIsm[i].AbstractIsm) + suite.Require().Equal(uint32(i+1), gs.CustomIsm[i].Index) + suite.Require().Equal(expectedIsm, actualCustomIsm) } suite.SetupTest() @@ -30,14 +46,36 @@ func (suite *KeeperTestSuite) TestGenesis() { suite.Require().NoError(err) metadata, err := hex.DecodeString(metadatas[0]) suite.Require().NoError(err) - pass, err := suite.keeper.Verify(metadata, message) + pass, err := suite.keeper.Verify(suite.ctx, metadata, message) suite.Require().Error(err) suite.Require().False(pass) err = suite.keeper.InitGenesis(suite.ctx, gs) suite.Require().NoError(err) - pass, err = suite.keeper.Verify(metadata, message) + pass, err = suite.keeper.Verify(suite.ctx, metadata, message) suite.Require().NoError(err) suite.Require().True(pass) + + for i := 0; i < len(defaultIsms); i++ { + expectedIsm := types.MustUnpackAbstractIsm(defaultIsms[i].AbstractIsm) + + defaultIsmReq := types.QueryOriginsDefaultIsmRequest{ + Origin: defaultIsms[i].Origin, + } + defaultIsmResp, err := suite.queryClient.OriginsDefaultIsm(suite.ctx, &defaultIsmReq) + suite.Require().NoError(err) + actualDefaultIsm := types.MustUnpackAbstractIsm(defaultIsmResp.DefaultIsm) + suite.Require().Equal(defaultIsms[i].Origin, gs.DefaultIsm[i].Origin) + suite.Require().Equal(expectedIsm, actualDefaultIsm) + + customIsmReq := types.QueryCustomIsmRequest{ + IsmId: uint32(i+1), + } + customIsmResp, err := suite.queryClient.CustomIsm(suite.ctx, &customIsmReq) + suite.Require().NoError(err) + actualCustomIsm := types.MustUnpackAbstractIsm(customIsmResp.CustomIsm) + suite.Require().Equal(uint32(i+1), gs.CustomIsm[i].Index) + suite.Require().Equal(expectedIsm, actualCustomIsm) + } } diff --git a/x/ism/keeper/grpc_query.go b/x/ism/keeper/grpc_query.go index cf38677..748d52d 100644 --- a/x/ism/keeper/grpc_query.go +++ b/x/ism/keeper/grpc_query.go @@ -5,6 +5,8 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/strangelove-ventures/hyperlane-cosmos/x/ism/types" ) @@ -13,11 +15,15 @@ var _ types.QueryServer = (*Keeper)(nil) // OriginsDefaultIsm implements the Query origins default ISM gRPC method func (k Keeper) OriginsDefaultIsm(c context.Context, req *types.QueryOriginsDefaultIsmRequest) (*types.QueryOriginsDefaultIsmResponse, error) { + ctx := sdk.UnwrapSDKContext(c) if req == nil || *req == (types.QueryOriginsDefaultIsmRequest{}) { return nil, status.Error(codes.InvalidArgument, "empty request") } - defaultIsm := k.defaultIsm[req.Origin] + defaultIsm, err := k.getDefaultIsm(ctx, req.Origin) + if err != nil { + return nil, err + } if defaultIsm != nil { ismAny, err := types.PackAbstractIsm(defaultIsm) if err != nil { @@ -32,23 +38,55 @@ func (k Keeper) OriginsDefaultIsm(c context.Context, req *types.QueryOriginsDefa // AllDefaultIsms implements the Query all default ISMs gRPC method func (k Keeper) AllDefaultIsms(c context.Context, req *types.QueryAllDefaultIsmsRequest) (*types.QueryAllDefaultIsmsResponse, error) { + ctx := sdk.UnwrapSDKContext(c) if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } - var allDefaultIsms types.QueryAllDefaultIsmsResponse - for origin := range k.defaultIsm { - ism := k.defaultIsm[origin] - ismAny, err := types.PackAbstractIsm(ism) + defaultIsms, err := k.getAllDefaultIsms(ctx) + if err != nil { + return nil, err + } + return &types.QueryAllDefaultIsmsResponse{ + DefaultIsms: defaultIsms, + }, nil +} + +// CustomIsm implements the Query custom ISM gRPC method +func (k Keeper) CustomIsm(c context.Context, req *types.QueryCustomIsmRequest) (*types.QueryCustomIsmResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + if req == nil || *req == (types.QueryCustomIsmRequest{}) { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + customIsm, err := k.getCustomIsm(ctx, req.IsmId) + if err != nil { + return nil, err + } + if customIsm != nil { + ismAny, err := types.PackAbstractIsm(customIsm) if err != nil { return nil, err } - allDefaultIsms.DefaultIsms = append(allDefaultIsms.DefaultIsms, &types.Ism{ - Origin: origin, - AbstractIsm: ismAny, - }) + return &types.QueryCustomIsmResponse{ + CustomIsm: ismAny, + }, nil } - return &allDefaultIsms, nil + return &types.QueryCustomIsmResponse{}, nil } -// TODO: do these queries need UnpackInterfaces? See: https://github.com/cosmos/cosmos-sdk/issues/8327 +// AllCustomIsms implements the Query all custom ISMs gRPC method +func (k Keeper) AllCustomIsms(c context.Context, req *types.QueryAllCustomIsmsRequest) (*types.QueryAllCustomIsmsResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + customIsms, err := k.getAllCustomIsms(ctx) + if err != nil { + return nil, err + } + return &types.QueryAllCustomIsmsResponse{ + CustomIsms: customIsms, + }, nil +} diff --git a/x/ism/keeper/grpc_query_test.go b/x/ism/keeper/grpc_query_test.go index 923320a..c475ce3 100644 --- a/x/ism/keeper/grpc_query_test.go +++ b/x/ism/keeper/grpc_query_test.go @@ -76,4 +76,187 @@ func (suite *KeeperTestSuite) TestQueryOriginsDefaultIsm() { } } -// TODO: add test case for querying all ISMs +func (suite *KeeperTestSuite) TestQueryAllDefaultIsms() { + var req *types.QueryAllDefaultIsmsRequest + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + { + "success", + func() { + req = &types.QueryAllDefaultIsmsRequest{} + }, + true, + }, + } + + for _, tc := range testCases { + suite.Run(tc.name, func() { + suite.SetupTest() + + signer := authtypes.NewModuleAddress(govtypes.ModuleName).String() + msg := types.NewMsgSetDefaultIsm(signer, defaultIsms) + + _, err := suite.keeper.SetDefaultIsm(suite.ctx, msg) + suite.Require().NoError(err) + + tc.malleate() + + res, err := suite.queryClient.AllDefaultIsms(suite.ctx, req) + + if tc.expPass { + suite.Require().NoError(err) + suite.Require().NotNil(res) + suite.Require().NotEmpty(res.DefaultIsms) + suite.Require().Equal(defaultIsms[0].String(), res.DefaultIsms[0].String()) + suite.Require().Equal(defaultIsms[1].String(), res.DefaultIsms[1].String()) + suite.Require().Equal(defaultIsms[2].String(), res.DefaultIsms[2].String()) + } else { + suite.Require().Error(err) + } + }) + } +} + + +func (suite *KeeperTestSuite) TestQueryCustomIsm() { + var req *types.QueryCustomIsmRequest + var index uint32 + + signer := authtypes.NewModuleAddress(govtypes.ModuleName).String() + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + { + "success with index 1", + func() { + index = 1 + req = &types.QueryCustomIsmRequest{IsmId: index} + msg := types.NewMsgCreateIsm(signer, defaultIsms[index-1].AbstractIsm) + _, err := suite.keeper.CreateIsm(suite.ctx, msg) + suite.Require().NoError(err) + }, + true, + }, + { + "success with index 1", + func() { + index = 2 + req = &types.QueryCustomIsmRequest{IsmId: index} + msg := types.NewMsgCreateIsm(signer, defaultIsms[index-1].AbstractIsm) + _, err := suite.keeper.CreateIsm(suite.ctx, msg) + suite.Require().NoError(err) + }, + true, + }, + { + "success with index 3", + func() { + index = 3 + req = &types.QueryCustomIsmRequest{IsmId: index} + msg := types.NewMsgCreateIsm(signer, defaultIsms[index-1].AbstractIsm) + _, err := suite.keeper.CreateIsm(suite.ctx, msg) + suite.Require().NoError(err) + }, + true, + }, + { + "fails with empty request", + func() { + req = &types.QueryCustomIsmRequest{} + }, + false, + }, + { + "fails with index 0", + func() { + index = 0 + req = &types.QueryCustomIsmRequest{IsmId: index} + }, + false, + }, + } + + for _, tc := range testCases { + suite.Run(tc.name, func() { + + tc.malleate() + res, err := suite.queryClient.CustomIsm(suite.ctx, req) + + if tc.expPass { + suite.Require().NoError(err) + suite.Require().NotNil(res) + suite.Require().NotEmpty(res.CustomIsm) + suite.Require().Equal(defaultIsms[index-1].AbstractIsm.String(), res.CustomIsm.String()) + } else { + suite.Require().Error(err) + } + }) + } +} + +func (suite *KeeperTestSuite) TestQueryAllCustomIsms() { + var req *types.QueryAllCustomIsmsRequest + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + { + "success", + func() { + req = &types.QueryAllCustomIsmsRequest{} + }, + true, + }, + } + + for _, tc := range testCases { + suite.Run(tc.name, func() { + suite.SetupTest() + + signer := authtypes.NewModuleAddress(govtypes.ModuleName).String() + + msg := types.NewMsgCreateIsm(signer, defaultIsms[0].AbstractIsm) + resp1, err := suite.keeper.CreateIsm(suite.ctx, msg) + suite.Require().NoError(err) + + msg = types.NewMsgCreateIsm(signer, defaultIsms[1].AbstractIsm) + resp2, err := suite.keeper.CreateIsm(suite.ctx, msg) + suite.Require().NoError(err) + + msg = types.NewMsgCreateIsm(signer, defaultIsms[2].AbstractIsm) + resp3, err := suite.keeper.CreateIsm(suite.ctx, msg) + suite.Require().NoError(err) + + tc.malleate() + + res, err := suite.queryClient.AllCustomIsms(suite.ctx, req) + + if tc.expPass { + suite.Require().NoError(err) + suite.Require().NotNil(res) + suite.Require().Equal(resp1.IsmId, uint32(1)) + suite.Require().Equal(resp2.IsmId, uint32(2)) + suite.Require().Equal(resp3.IsmId, uint32(3)) + suite.Require().NotEmpty(res.CustomIsms) + suite.Require().Equal(defaultIsms[0].AbstractIsm.String(), res.CustomIsms[0].AbstractIsm.String()) + suite.Require().Equal(defaultIsms[1].AbstractIsm.String(), res.CustomIsms[1].AbstractIsm.String()) + suite.Require().Equal(defaultIsms[2].AbstractIsm.String(), res.CustomIsms[2].AbstractIsm.String()) + suite.Require().Equal(uint32(1), res.CustomIsms[0].Index) + suite.Require().Equal(uint32(2), res.CustomIsms[1].Index) + suite.Require().Equal(uint32(3), res.CustomIsms[2].Index) + } else { + suite.Require().Error(err) + } + }) + } +} + diff --git a/x/ism/keeper/keeper.go b/x/ism/keeper/keeper.go index 131ed72..a077329 100644 --- a/x/ism/keeper/keeper.go +++ b/x/ism/keeper/keeper.go @@ -1,7 +1,10 @@ package keeper import ( + "context" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" common "github.com/strangelove-ventures/hyperlane-cosmos/x/common" @@ -15,7 +18,6 @@ type Keeper struct { storeKey storetypes.StoreKey cdc codec.BinaryCodec authority string - defaultIsm map[uint32]types.AbstractIsm } func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, authority string) Keeper { @@ -23,14 +25,17 @@ func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, authority string) cdc: cdc, storeKey: key, authority: authority, - defaultIsm: map[uint32]types.AbstractIsm{}, } } -func (k Keeper) Verify(metadata, message []byte) (bool, error) { +func (k Keeper) Verify(goCtx context.Context, metadata, message []byte) (bool, error) { + ctx := sdk.UnwrapSDKContext(goCtx) msgOrigin := common.Origin(message) // Look up recipient contract's ISM, if 0, use default multi sig (just use default for now) - ism := k.defaultIsm[msgOrigin] + ism, err := k.getDefaultIsm(ctx, msgOrigin) + if err != nil { + return false, err + } if ism != nil { return ism.Verify(metadata, message) } diff --git a/x/ism/keeper/keeper_test.go b/x/ism/keeper/keeper_test.go index 1e6d3a1..ca4d6f1 100644 --- a/x/ism/keeper/keeper_test.go +++ b/x/ism/keeper/keeper_test.go @@ -108,7 +108,7 @@ func (suite *KeeperTestSuite) TestVerify() { _, err := suite.msgServer.SetDefaultIsm(suite.ctx, msg) suite.Require().NoError(err) - pass, err := suite.keeper.Verify(tc.metadata, tc.message) + pass, err := suite.keeper.Verify(suite.ctx, tc.metadata, tc.message) if tc.expPass { suite.Require().True(pass) diff --git a/x/ism/keeper/msg_server.go b/x/ism/keeper/msg_server.go index 09854b1..dbe8656 100644 --- a/x/ism/keeper/msg_server.go +++ b/x/ism/keeper/msg_server.go @@ -17,7 +17,7 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer { return keeper } -// StoreCode defines a rpc handler method for MsgStoreCode +// SetDefaultIsm defines a rpc handler method for MsgSetDefaultIsm func (k Keeper) SetDefaultIsm(goCtx context.Context, msg *types.MsgSetDefaultIsm) (*types.MsgSetDefaultIsmResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -25,28 +25,18 @@ func (k Keeper) SetDefaultIsm(goCtx context.Context, msg *types.MsgSetDefaultIsm return nil, sdkerrors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority: expected %s, got %s", k.authority, msg.Signer) } - ismBzMap := map[uint32][]byte{} - ismMap := map[uint32]types.AbstractIsm{} events := sdk.Events{} for _, originIsm := range msg.Isms { ism, err := types.UnpackAbstractIsm(originIsm.AbstractIsm) if err != nil { return &types.MsgSetDefaultIsmResponse{}, err } - ismMap[originIsm.Origin] = ism - - ismBz, err := k.cdc.MarshalInterface(ism) + err = k.storeDefaultIsm(ctx, originIsm.Origin, ism) if err != nil { return &types.MsgSetDefaultIsmResponse{}, err } - ismBzMap[originIsm.Origin] = ismBz - events.AppendEvent(ism.Event(originIsm.Origin)) - } - store := ctx.KVStore(k.storeKey) - for _, originIsm := range msg.Isms { - k.defaultIsm[originIsm.Origin] = ismMap[originIsm.Origin] - store.Set(types.OriginKey(originIsm.Origin), ismBzMap[originIsm.Origin]) + events.AppendEvent(ism.DefaultIsmEvent(originIsm.Origin)) } events.AppendEvent(sdk.NewEvent( @@ -57,3 +47,36 @@ func (k Keeper) SetDefaultIsm(goCtx context.Context, msg *types.MsgSetDefaultIsm return &types.MsgSetDefaultIsmResponse{}, nil } + +// CreateIsm defines a rpc handler method for MsgCreateIsm +func (k Keeper) CreateIsm(goCtx context.Context, msg *types.MsgCreateIsm) (*types.MsgCreateIsmResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + ismId, err := k.getNextCustomIsmIndex(ctx) + if err != nil { + return nil, err + } + + ism, err := types.UnpackAbstractIsm(msg.Ism) + if err != nil { + return nil, err + } + + err = k.storeCustomIsm(ctx, ismId, ism) + if err != nil { + return nil, err + } + + events := sdk.Events{} + events.AppendEvent(ism.CustomIsmEvent(ismId)) + + events.AppendEvent(sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + )) + ctx.EventManager().EmitEvents(events) + + return &types.MsgCreateIsmResponse{ + IsmId: ismId, + }, nil +} diff --git a/x/ism/keeper/msg_server_test.go b/x/ism/keeper/msg_server_test.go index 6e1802c..8e08fce 100644 --- a/x/ism/keeper/msg_server_test.go +++ b/x/ism/keeper/msg_server_test.go @@ -58,7 +58,7 @@ func (suite *KeeperTestSuite) TestMsgSetDefaultIsm() { expectedEvents := sdk.Events{} for _, originIsm := range defaultIsms { ism := types.MustUnpackAbstractIsm(originIsm.AbstractIsm) - expectedEvents.AppendEvent(ism.Event(originIsm.Origin)) + expectedEvents.AppendEvent(ism.DefaultIsmEvent(originIsm.Origin)) } expectedEvents.AppendEvent(sdk.NewEvent( sdk.EventTypeMessage, @@ -76,3 +76,62 @@ func (suite *KeeperTestSuite) TestMsgSetDefaultIsm() { }) } } + +func (suite *KeeperTestSuite) TestMsgCreateIsm() { + var ( + msg *types.MsgCreateIsm + signer string + ) + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + { + "success", + func() { + msg = types.NewMsgCreateIsm(signer, defaultIsms[0].AbstractIsm) + }, + true, + }, + } + + for _, tc := range testCases { + suite.Run(tc.name, func() { + suite.SetupTest() + + signer = authtypes.NewModuleAddress(types.ModuleName).String() + + tc.malleate() + + err := msg.ValidateBasic() + suite.Require().NoError(err) + + res, err := suite.msgServer.CreateIsm(suite.ctx, msg) + events := suite.ctx.EventManager().Events() + + if tc.expPass { + suite.Require().NoError(err) + suite.Require().NotNil(res) + + // Verify events + expectedEvents := sdk.Events{} + ism := types.MustUnpackAbstractIsm(defaultIsms[0].AbstractIsm) + expectedEvents.AppendEvent(ism.CustomIsmEvent(1)) + expectedEvents.AppendEvent(sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + )) + + for _, evt := range expectedEvents { + suite.Require().Contains(events, evt) + } + } else { + suite.Require().Error(err) + suite.Require().Nil(res) + suite.Require().Empty(events) + } + }) + } +} \ No newline at end of file diff --git a/x/ism/keeper/store.go b/x/ism/keeper/store.go new file mode 100644 index 0000000..09468f0 --- /dev/null +++ b/x/ism/keeper/store.go @@ -0,0 +1,153 @@ +package keeper + +import ( + "bytes" + "fmt" + "strconv" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/strangelove-ventures/hyperlane-cosmos/x/ism/types" +) + +// getDefaultIsm returns the default ISM +func (k Keeper) getDefaultIsm(ctx sdk.Context, origin uint32) (types.AbstractIsm, error) { + store := ctx.KVStore(k.storeKey) + ismBz := store.Get(types.DefaultIsmKey(origin)) + + var ism types.AbstractIsm + err := k.cdc.UnmarshalInterface(ismBz, &ism) + if err != nil { + return nil, err + } + + return ism, nil +} + +// getAllDefaultIsms returns the default ISMs +func (k Keeper) getAllDefaultIsms(ctx sdk.Context) ([]*types.DefaultIsm, error) { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, []byte(types.KeyOriginsDefaultIsm)) + defer iterator.Close() + + var defaultIsms []*types.DefaultIsm + for ; iterator.Valid(); iterator.Next() { + originBz := bytes.TrimPrefix(iterator.Key(), []byte(fmt.Sprintf("%s/", types.KeyOriginsDefaultIsm))) + origin64, err := strconv.ParseUint(string(originBz), 10, 32) + if err != nil { + return nil, err + } + + var ism types.AbstractIsm + err = k.cdc.UnmarshalInterface(iterator.Value(), &ism) + if err != nil { + return nil, err + } + + ismAny, err := types.PackAbstractIsm(ism) + if err != nil { + return nil, err + } + + defaultIsms = append(defaultIsms, &types.DefaultIsm{ + Origin: uint32(origin64), + AbstractIsm: ismAny, + }) + } + + return defaultIsms, nil +} + +// setDefaultIsm stores the default ISM +func (k Keeper) storeDefaultIsm(ctx sdk.Context, origin uint32, ism types.AbstractIsm) error { + store := ctx.KVStore(k.storeKey) + + ismBz, err := k.cdc.MarshalInterface(ism) + if err != nil { + return err + } + store.Set(types.DefaultIsmKey(origin), ismBz) + + return nil +} + +// getCustomIsm returns the custom ISM +func (k Keeper) getCustomIsm(ctx sdk.Context, ismId uint32) (types.AbstractIsm, error) { + store := ctx.KVStore(k.storeKey) + ismBz := store.Get(types.CustomIsmKey(ismId)) + + var ism types.AbstractIsm + err := k.cdc.UnmarshalInterface(ismBz, &ism) + if err != nil { + return nil, err + } + + return ism, nil +} + +// getAllCustomIsms returns the custom ISMs +func (k Keeper) getAllCustomIsms(ctx sdk.Context) ([]*types.CustomIsm, error) { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, []byte(types.KeyCustomIsm)) + defer iterator.Close() + + var customIsms []*types.CustomIsm + for ; iterator.Valid(); iterator.Next() { + indexBz := bytes.TrimPrefix(iterator.Key(), []byte(fmt.Sprintf("%s/", types.KeyCustomIsm))) + index64, err := strconv.ParseUint(string(indexBz), 10, 32) + if err != nil { + return nil, err + } + + var ism types.AbstractIsm + err = k.cdc.UnmarshalInterface(iterator.Value(), &ism) + if err != nil { + return nil, err + } + + ismAny, err := types.PackAbstractIsm(ism) + if err != nil { + return nil, err + } + + customIsms = append(customIsms, &types.CustomIsm{ + Index: uint32(index64), + AbstractIsm: ismAny, + }) + } + + return customIsms, nil +} + +// storeCustomIsm store the custom ISM +func (k Keeper) storeCustomIsm(ctx sdk.Context, index uint32, ism types.AbstractIsm) error { + store := ctx.KVStore(k.storeKey) + + ismBz, err := k.cdc.MarshalInterface(ism) + if err != nil { + return err + } + store.Set(types.CustomIsmKey(index), ismBz) + + return nil +} + +// getNextCustomIsmIndex gets the next index to be used +func (k Keeper) getNextCustomIsmIndex(ctx sdk.Context) (uint32, error) { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStoreReversePrefixIterator(store, []byte(types.KeyCustomIsm)) + defer iterator.Close() + + index := uint32(1) + if iterator.Valid() { + indexBz := bytes.TrimPrefix(iterator.Key(), []byte(fmt.Sprintf("%s/", types.KeyCustomIsm))) + index64, err := strconv.ParseUint(string(indexBz), 10, 32) + if err != nil { + return 0, err + } + index64++ + index = uint32(index64) + } + + return index, nil +} \ No newline at end of file diff --git a/x/ism/keeper/test_data_test.go b/x/ism/keeper/test_data_test.go index cb2b886..9a70b77 100644 --- a/x/ism/keeper/test_data_test.go +++ b/x/ism/keeper/test_data_test.go @@ -31,7 +31,7 @@ var metadatas = [...]string{ "c2e8f82906b56bcaac5af08a5a6fc3f7ce0cfa1c44571826363c9c72a532b30b0000045a00000000000000000000000035231d4c2d8b8adcb5617a638a0c4548684c7c70000000000000000000000000000000000000000000000000000000000000000046cd745fccccae885fcfea0fad4701dcd5a1bb48794c9e8746324a1b530b0314b4c11951957c6f8f642c4af61cd6b24640fec6dc7fc607ee8206a99e92410d30c6f6b7ec8cfe49eb189d8573532d5517fe16e9dca77493f13331e7b41f6263acf9c383ed70c357c3e9157e1a96cc15694e362cfa1e900bfcde8f4dc18005769b0eb01ebfc9ed27500cd4dfc979272d1f0913cc9f66540d7e8005811109e1cf2d6e3fb8b75586d0f9c9826b06e6b4408b7e6a55a56830343d0632e03a98e400a8ffd70157e48063fc33c97a050f7f640233bf646cc98d9524c6b92bcf3ab56f839867cc5f7f196b93bae1e27e6320742445d290f2263827498b54fec539f756afcefad4e508c098b9a7e1d8feb19955fb02ba9675585078710969d3440f5054e00f25f5fa494636481b4b00f7d402df0fd4e3474a68241e525a3e94e1b0c23233f8b13a49e282f609c317a833fb8d976d11517c571d1221a265d25af778ecf8923490c6ceeb450aecdc82e28293031d10c7d73bf85e57bf041a97360aa2c5d99cc1df82d9c4b87413eae2ef048f94b4d3554cea73d92b0f7af96e0271c691e2bb5c67add7c6caf302256adedf7ab114da0acfe870d449a3a489f781d659e8beccda7bce9f4e8618b6bd2f4132ce798cdc7a60e7e1460a7299e3c6342a579626d22733e50f526ec2fa19a22b31e8ed50f23cd1fdf94c9154ed3a7609a2f1ff981fe1d3b5c807b281e4683cc6d6315cf95b9ade8641defcb32372f1c126e398ef7a5a2dce0a8a7f68bb74560f8f71837c2c2ebbcbf7fffb42ae1896f13f7c7479a0b46a28b6f55540f89444f63de0378e3d121be09e06cc9ded1c20e65876d36aa0c65e9645644786b620e2dd2ad648ddfcbf4a7e5b1a3a4ecfe7f64667a3f0b7e2f4418588ed35a2458cffeb39b93d26f18d2ab13bdce6aee58e7b99359ec2dfd95a9c16dc00d6ef18b7933a6f8dc65ccb55667138776f7dea101070dc8796e3774df84f40ae0c8229d0d6069e5c8f39a7c299677a09d367fc7b05e3bc380ee652cdc72595f74c7b1043d0e1ffbab734648c838dfb0527d971b602bc216c9619ef0abf5ac974a1ed57f4050aa510dd9c74f508277b39d7973bb2dfccc5eeb0618db8cd74046ff337f0a7bf2c8e03e10f642c1886798d71806ab1e888d9e5ee87d0838c5655cb21c6cb83313b5a631175dff4963772cce9108188b34ac87c81c41e662ee4dd2dd7b2bc707961b1e646c4047669dcb6584f0d8d770daf5d7e7deb2e388ab20e2573d171a88108e79d820e98f26c0b84aa8b2f4aa4968dbb818ea32293237c50ba75ee485f4c22adf2f741400bdf8d6a9cc7df7ecae576221665d7358448818bb4ae4562849e949e17ac16e0be16688e156b5cf15e098c627c0056a90416ba10348c004f0233942335099a767a092a8a0429de954522ecc2d785a855e8473b1e65bcf6d07ce8d43a6efd60f28a5c8d57be3875489c2245dc4c9243f2381cf43f08a126f1be03fd3d7b6e9221745673b33d3555b81b8a1cfccc70e8f6a68a27dd800507edfe6e8eea9c7fc2e140eb07cdfc06e225840e425203b01c74a55e1cceb2cc15128eb8ba22e3b3c69bc13680787719af5708ecf273138793b9c183a01f39be66b119131a61a222482b5f74e1d3fa03c719d7071d272670cbf03887a61bea0c40b3b397cf2ae4b6dd377957335eb3b1e96971b63df4a873758513f98adc748776cbd8210dd0564b462f8548d0f71a74d4454004c31bb5bdf284499404361c0000000000000000000000004c327ccb881a7542be77500b2833dc84c839e7b7000000000000000000000000892dc66f5b2f8c438e03f6323394e34a9c24f2d6000000000000000000000000d4c1211f0eefb97a846c4e6d6589832e52fc03db00000000000000000000000084cb373148ef9112b277e68acf676fefa9a9a9a00000000000000000000000000d860c2b28bec3af4fd3a5997283e460ff6f2789000000000000000000000000600c90404d5c9df885404d2cc5350c9b314ea3a2", } -var defaultIsms = []*types.Ism{ +var defaultIsms = []*types.DefaultIsm{ { Origin: 1, // Ethereum origin AbstractIsm: types.MustPackAbstractIsm( diff --git a/x/ism/module.go b/x/ism/module.go index edb2b27..ce3903a 100644 --- a/x/ism/module.go +++ b/x/ism/module.go @@ -51,7 +51,8 @@ func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) // DefaultGenesis returns an empty state func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { return cdc.MustMarshalJSON(&types.GenesisState{ - DefaultIsm: []types.Ism{}, + DefaultIsm: []types.DefaultIsm{}, + CustomIsm: []types.CustomIsm{}, }) } diff --git a/x/ism/types/abstract_ism.go b/x/ism/types/abstract_ism.go index 056095e..7b24094 100644 --- a/x/ism/types/abstract_ism.go +++ b/x/ism/types/abstract_ism.go @@ -10,5 +10,6 @@ type AbstractIsm interface { Validate() error Verify(metadata []byte, message []byte) (bool, error) - Event(origin uint32) sdk.Event + DefaultIsmEvent(origin uint32) sdk.Event + CustomIsmEvent(index uint32) sdk.Event } diff --git a/x/ism/types/codec.go b/x/ism/types/codec.go index c99c19c..9610e42 100644 --- a/x/ism/types/codec.go +++ b/x/ism/types/codec.go @@ -1,6 +1,7 @@ package types import ( + "fmt" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -18,6 +19,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterImplementations( (*sdk.Msg)(nil), &MsgSetDefaultIsm{}, + &MsgCreateIsm{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) @@ -47,11 +49,13 @@ func MustPackAbstractIsm(ism AbstractIsm) *codectypes.Any { func UnpackAbstractIsm(any *codectypes.Any) (AbstractIsm, error) { if any == nil { + fmt.Println("Panic2") return nil, sdkerrors.Wrap(ErrUnpackAny, "protobuf Any message cannot be nil") } ism, ok := any.GetCachedValue().(AbstractIsm) if !ok { + fmt.Println("Panic3") return nil, sdkerrors.Wrapf(ErrUnpackAny, "cannot unpack Any into Ism %T", any) } @@ -61,6 +65,7 @@ func UnpackAbstractIsm(any *codectypes.Any) (AbstractIsm, error) { func MustUnpackAbstractIsm(any *codectypes.Any) AbstractIsm { ism, err := UnpackAbstractIsm(any) if err != nil { + fmt.Println("Panic1") panic(err) } return ism diff --git a/x/ism/types/events.go b/x/ism/types/events.go index 2454556..3012cf5 100644 --- a/x/ism/types/events.go +++ b/x/ism/types/events.go @@ -2,13 +2,14 @@ package types // Hyperlane ISM event types const ( - EventTypeSetDefaultIsm = "set_default_ism" + EventTypeSetDefaultIsm = "set_default_ism" + EventTypeCreateCustomIsm = "create_custom_ism" ) // Hyperlane ISM attribute keys const ( - AttributeKeySetDefaultIsm = "updated_ism" AttributeKeyOrigin = "origin" + AttributeKeyIndex = "index" AttributeKeyThreshold = "threshold" AttributeKeyValidator = "validator" ) diff --git a/x/ism/types/genesis.pb.go b/x/ism/types/genesis.pb.go index 3cf409e..4b27f98 100644 --- a/x/ism/types/genesis.pb.go +++ b/x/ism/types/genesis.pb.go @@ -29,7 +29,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Hyperlane ISM's keeper genesis state type GenesisState struct { // Genesis default ISM - DefaultIsm []Ism `protobuf:"bytes,1,rep,name=default_ism,json=defaultIsm,proto3" json:"default_ism"` + DefaultIsm []DefaultIsm `protobuf:"bytes,1,rep,name=default_ism,json=defaultIsm,proto3" json:"default_ism"` + // Custom Isms + CustomIsm []CustomIsm `protobuf:"bytes,2,rep,name=custom_ism,json=customIsm,proto3" json:"custom_ism"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -70,13 +72,20 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo -func (m *GenesisState) GetDefaultIsm() []Ism { +func (m *GenesisState) GetDefaultIsm() []DefaultIsm { if m != nil { return m.DefaultIsm } return nil } +func (m *GenesisState) GetCustomIsm() []CustomIsm { + if m != nil { + return m.CustomIsm + } + return nil +} + func init() { proto.RegisterType((*GenesisState)(nil), "hyperlane.ism.v1.GenesisState") } @@ -84,22 +93,24 @@ func init() { func init() { proto.RegisterFile("hyperlane/ism/v1/genesis.proto", fileDescriptor_8c34a26270c6c79c) } var fileDescriptor_8c34a26270c6c79c = []byte{ - // 226 bytes of a gzipped FileDescriptorProto + // 257 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcb, 0xa8, 0x2c, 0x48, 0x2d, 0xca, 0x49, 0xcc, 0x4b, 0xd5, 0xcf, 0x2c, 0xce, 0xd5, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x80, 0xcb, 0xeb, 0x65, 0x16, 0xe7, 0xea, 0x95, 0x19, 0x4a, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x25, 0xf5, 0x41, 0x2c, - 0x88, 0x3a, 0x29, 0x29, 0x0c, 0x73, 0x40, 0xca, 0xc1, 0x72, 0x4a, 0x3e, 0x5c, 0x3c, 0xee, 0x10, - 0x43, 0x83, 0x4b, 0x12, 0x4b, 0x52, 0x85, 0x6c, 0xb8, 0xb8, 0x53, 0x52, 0xd3, 0x12, 0x4b, 0x73, - 0x4a, 0xe2, 0x33, 0x8b, 0x73, 0x25, 0x18, 0x15, 0x98, 0x35, 0xb8, 0x8d, 0x44, 0xf5, 0xd0, 0x6d, - 0xd2, 0xf3, 0x2c, 0xce, 0x75, 0x62, 0x39, 0x71, 0x4f, 0x9e, 0x21, 0x88, 0x0b, 0xaa, 0x1e, 0x24, - 0x12, 0x76, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, - 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x36, 0xe9, 0x99, 0x25, - 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xc5, 0x25, 0x45, 0x89, 0x79, 0xe9, 0xa9, 0x39, - 0xf9, 0x65, 0xa9, 0xba, 0x65, 0xa9, 0x79, 0x25, 0xa5, 0x45, 0xa9, 0xc5, 0xfa, 0x70, 0x1b, 0x74, - 0x93, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xf5, 0x2b, 0xc0, 0x8e, 0x2d, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, - 0x62, 0x03, 0x3b, 0xd6, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x4a, 0x40, 0x66, 0xcc, 0x12, 0x01, - 0x00, 0x00, + 0x88, 0x3a, 0x29, 0x29, 0x0c, 0x73, 0x40, 0xca, 0xc1, 0x72, 0x4a, 0x53, 0x19, 0xb9, 0x78, 0xdc, + 0x21, 0xa6, 0x06, 0x97, 0x24, 0x96, 0xa4, 0x0a, 0x39, 0x73, 0x71, 0xa7, 0xa4, 0xa6, 0x25, 0x96, + 0xe6, 0x94, 0xc4, 0x67, 0x16, 0xe7, 0x4a, 0x30, 0x2a, 0x30, 0x6b, 0x70, 0x1b, 0xc9, 0xe8, 0xa1, + 0x5b, 0xa5, 0xe7, 0x02, 0x51, 0xe4, 0x59, 0x9c, 0xeb, 0xc4, 0x72, 0xe2, 0x9e, 0x3c, 0x43, 0x10, + 0x57, 0x0a, 0x5c, 0x44, 0xc8, 0x81, 0x8b, 0x2b, 0xb9, 0xb4, 0xb8, 0x24, 0x3f, 0x17, 0x6c, 0x06, + 0x13, 0xd8, 0x0c, 0x69, 0x4c, 0x33, 0x9c, 0xc1, 0x6a, 0x10, 0x46, 0x70, 0x26, 0xc3, 0x05, 0xc2, + 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, + 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x26, 0x3d, 0xb3, 0x24, 0xa3, + 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0xbf, 0xb8, 0xa4, 0x28, 0x31, 0x2f, 0x3d, 0x35, 0x27, 0xbf, + 0x2c, 0x55, 0xb7, 0x2c, 0x35, 0xaf, 0xa4, 0xb4, 0x28, 0xb5, 0x58, 0x1f, 0x6e, 0x8d, 0x6e, 0x72, + 0x7e, 0x71, 0x6e, 0x7e, 0xb1, 0x7e, 0x05, 0xd8, 0xdb, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, + 0x60, 0x6f, 0x1b, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x82, 0x9b, 0xf9, 0xa4, 0x5c, 0x01, 0x00, + 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -122,6 +133,20 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.CustomIsm) > 0 { + for iNdEx := len(m.CustomIsm) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.CustomIsm[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } if len(m.DefaultIsm) > 0 { for iNdEx := len(m.DefaultIsm) - 1; iNdEx >= 0; iNdEx-- { { @@ -163,6 +188,12 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } + if len(m.CustomIsm) > 0 { + for _, e := range m.CustomIsm { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } return n } @@ -232,11 +263,45 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.DefaultIsm = append(m.DefaultIsm, Ism{}) + m.DefaultIsm = append(m.DefaultIsm, DefaultIsm{}) if err := m.DefaultIsm[len(m.DefaultIsm)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CustomIsm", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CustomIsm = append(m.CustomIsm, CustomIsm{}) + if err := m.CustomIsm[len(m.CustomIsm)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/ism/types/ism.pb.go b/x/ism/types/ism.pb.go index 3c3c815..d7b27aa 100644 --- a/x/ism/types/ism.pb.go +++ b/x/ism/types/ism.pb.go @@ -27,25 +27,25 @@ var ( const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Hyperlane's default ISM -type Ism struct { +type DefaultIsm struct { Origin uint32 `protobuf:"varint,1,opt,name=origin,proto3" json:"origin,omitempty"` AbstractIsm *types.Any `protobuf:"bytes,2,opt,name=abstract_ism,json=abstractIsm,proto3" json:"abstract_ism,omitempty"` } -func (m *Ism) Reset() { *m = Ism{} } -func (m *Ism) String() string { return proto.CompactTextString(m) } -func (*Ism) ProtoMessage() {} -func (*Ism) Descriptor() ([]byte, []int) { +func (m *DefaultIsm) Reset() { *m = DefaultIsm{} } +func (m *DefaultIsm) String() string { return proto.CompactTextString(m) } +func (*DefaultIsm) ProtoMessage() {} +func (*DefaultIsm) Descriptor() ([]byte, []int) { return fileDescriptor_425ee6960ca43e9a, []int{0} } -func (m *Ism) XXX_Unmarshal(b []byte) error { +func (m *DefaultIsm) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *Ism) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *DefaultIsm) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_Ism.Marshal(b, m, deterministic) + return xxx_messageInfo_DefaultIsm.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -56,28 +56,86 @@ func (m *Ism) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { } } -func (m *Ism) XXX_Merge(src proto.Message) { - xxx_messageInfo_Ism.Merge(m, src) +func (m *DefaultIsm) XXX_Merge(src proto.Message) { + xxx_messageInfo_DefaultIsm.Merge(m, src) } -func (m *Ism) XXX_Size() int { +func (m *DefaultIsm) XXX_Size() int { return m.Size() } -func (m *Ism) XXX_DiscardUnknown() { - xxx_messageInfo_Ism.DiscardUnknown(m) +func (m *DefaultIsm) XXX_DiscardUnknown() { + xxx_messageInfo_DefaultIsm.DiscardUnknown(m) } -var xxx_messageInfo_Ism proto.InternalMessageInfo +var xxx_messageInfo_DefaultIsm proto.InternalMessageInfo -func (m *Ism) GetOrigin() uint32 { +func (m *DefaultIsm) GetOrigin() uint32 { if m != nil { return m.Origin } return 0 } -func (m *Ism) GetAbstractIsm() *types.Any { +func (m *DefaultIsm) GetAbstractIsm() *types.Any { + if m != nil { + return m.AbstractIsm + } + return nil +} + +// Hyperlane's custom ISM +type CustomIsm struct { + Index uint32 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"` + AbstractIsm *types.Any `protobuf:"bytes,2,opt,name=abstract_ism,json=abstractIsm,proto3" json:"abstract_ism,omitempty"` +} + +func (m *CustomIsm) Reset() { *m = CustomIsm{} } +func (m *CustomIsm) String() string { return proto.CompactTextString(m) } +func (*CustomIsm) ProtoMessage() {} +func (*CustomIsm) Descriptor() ([]byte, []int) { + return fileDescriptor_425ee6960ca43e9a, []int{1} +} + +func (m *CustomIsm) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} + +func (m *CustomIsm) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CustomIsm.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 *CustomIsm) XXX_Merge(src proto.Message) { + xxx_messageInfo_CustomIsm.Merge(m, src) +} + +func (m *CustomIsm) XXX_Size() int { + return m.Size() +} + +func (m *CustomIsm) XXX_DiscardUnknown() { + xxx_messageInfo_CustomIsm.DiscardUnknown(m) +} + +var xxx_messageInfo_CustomIsm proto.InternalMessageInfo + +func (m *CustomIsm) GetIndex() uint32 { + if m != nil { + return m.Index + } + return 0 +} + +func (m *CustomIsm) GetAbstractIsm() *types.Any { if m != nil { return m.AbstractIsm } @@ -85,31 +143,34 @@ func (m *Ism) GetAbstractIsm() *types.Any { } func init() { - proto.RegisterType((*Ism)(nil), "hyperlane.ism.v1.Ism") + proto.RegisterType((*DefaultIsm)(nil), "hyperlane.ism.v1.DefaultIsm") + proto.RegisterType((*CustomIsm)(nil), "hyperlane.ism.v1.CustomIsm") } func init() { proto.RegisterFile("hyperlane/ism/v1/ism.proto", fileDescriptor_425ee6960ca43e9a) } var fileDescriptor_425ee6960ca43e9a = []byte{ - // 228 bytes of a gzipped FileDescriptorProto + // 262 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xca, 0xa8, 0x2c, 0x48, 0x2d, 0xca, 0x49, 0xcc, 0x4b, 0xd5, 0xcf, 0x2c, 0xce, 0xd5, 0x2f, 0x33, 0x04, 0x51, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x02, 0x70, 0x39, 0x3d, 0x90, 0x60, 0x99, 0xa1, 0x94, 0x64, 0x7a, 0x7e, 0x7e, 0x7a, 0x4e, 0xaa, 0x3e, 0x58, 0x3e, 0xa9, 0x34, 0x4d, 0x3f, 0x31, 0xaf, 0x12, 0xa2, - 0x58, 0x29, 0x8c, 0x8b, 0xd9, 0xb3, 0x38, 0x57, 0x48, 0x8c, 0x8b, 0x2d, 0xbf, 0x28, 0x33, 0x3d, - 0x33, 0x4f, 0x82, 0x51, 0x81, 0x51, 0x83, 0x37, 0x08, 0xca, 0x13, 0x32, 0xe7, 0xe2, 0x49, 0x4c, - 0x2a, 0x2e, 0x29, 0x4a, 0x4c, 0x2e, 0x89, 0xcf, 0x2c, 0xce, 0x95, 0x60, 0x52, 0x60, 0xd4, 0xe0, - 0x36, 0x12, 0xd1, 0x83, 0x18, 0xa8, 0x07, 0x33, 0x50, 0xcf, 0x31, 0xaf, 0x32, 0x88, 0x1b, 0xa6, - 0xd2, 0xb3, 0x38, 0xd7, 0x29, 0xec, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, - 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, - 0x6c, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x41, 0xea, 0xf3, 0xd2, - 0x53, 0x73, 0xf2, 0xcb, 0x52, 0x75, 0xcb, 0x52, 0xf3, 0x4a, 0x4a, 0x8b, 0x52, 0x8b, 0xf5, 0xe1, - 0xce, 0xd7, 0x4d, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0xaf, 0x00, 0xfb, 0xb1, 0xa4, 0xb2, 0x20, - 0xb5, 0x38, 0x89, 0x0d, 0x6c, 0xa5, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x5a, 0x98, 0xc2, 0x65, - 0x01, 0x01, 0x00, 0x00, -} - -func (m *Ism) Marshal() (dAtA []byte, err error) { + 0x58, 0x29, 0x96, 0x8b, 0xcb, 0x25, 0x35, 0x2d, 0xb1, 0x34, 0xa7, 0xc4, 0xb3, 0x38, 0x57, 0x48, + 0x8c, 0x8b, 0x2d, 0xbf, 0x28, 0x33, 0x3d, 0x33, 0x4f, 0x82, 0x51, 0x81, 0x51, 0x83, 0x37, 0x08, + 0xca, 0x13, 0x32, 0xe7, 0xe2, 0x49, 0x4c, 0x2a, 0x2e, 0x29, 0x4a, 0x4c, 0x2e, 0x89, 0xcf, 0x2c, + 0xce, 0x95, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x36, 0x12, 0xd1, 0x83, 0x98, 0xab, 0x07, 0x33, 0x57, + 0xcf, 0x31, 0xaf, 0x32, 0x88, 0x1b, 0xa6, 0xd2, 0xb3, 0x38, 0x57, 0x29, 0x8a, 0x8b, 0xd3, 0xb9, + 0xb4, 0xb8, 0x24, 0x3f, 0x17, 0x64, 0xba, 0x08, 0x17, 0x6b, 0x66, 0x5e, 0x4a, 0x6a, 0x05, 0xd4, + 0x70, 0x08, 0x87, 0x6c, 0xb3, 0x9d, 0xc2, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, + 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, + 0x21, 0xca, 0x26, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0xa4, 0x3e, + 0x2f, 0x3d, 0x35, 0x27, 0xbf, 0x2c, 0x55, 0xb7, 0x2c, 0x35, 0xaf, 0xa4, 0xb4, 0x28, 0xb5, 0x58, + 0x1f, 0x1e, 0x42, 0xba, 0xc9, 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xfa, 0x15, 0xe0, 0x60, 0x2c, 0xa9, + 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x5b, 0x69, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x5f, 0xa8, + 0x4c, 0xaa, 0x64, 0x01, 0x00, 0x00, +} + +func (m *DefaultIsm) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -119,12 +180,12 @@ func (m *Ism) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *Ism) MarshalTo(dAtA []byte) (int, error) { +func (m *DefaultIsm) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *Ism) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *DefaultIsm) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -149,6 +210,46 @@ func (m *Ism) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *CustomIsm) 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 *CustomIsm) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CustomIsm) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.AbstractIsm != nil { + { + size, err := m.AbstractIsm.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintIsm(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.Index != 0 { + i = encodeVarintIsm(dAtA, i, uint64(m.Index)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func encodeVarintIsm(dAtA []byte, offset int, v uint64) int { offset -= sovIsm(v) base := offset @@ -161,7 +262,7 @@ func encodeVarintIsm(dAtA []byte, offset int, v uint64) int { return base } -func (m *Ism) Size() (n int) { +func (m *DefaultIsm) Size() (n int) { if m == nil { return 0 } @@ -177,6 +278,22 @@ func (m *Ism) Size() (n int) { return n } +func (m *CustomIsm) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Index != 0 { + n += 1 + sovIsm(uint64(m.Index)) + } + if m.AbstractIsm != nil { + l = m.AbstractIsm.Size() + n += 1 + l + sovIsm(uint64(l)) + } + return n +} + func sovIsm(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -185,7 +302,7 @@ func sozIsm(x uint64) (n int) { return sovIsm(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *Ism) Unmarshal(dAtA []byte) error { +func (m *DefaultIsm) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -208,10 +325,10 @@ func (m *Ism) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: Ism: wiretype end group for non-group") + return fmt.Errorf("proto: DefaultIsm: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: Ism: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: DefaultIsm: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -291,6 +408,112 @@ func (m *Ism) Unmarshal(dAtA []byte) error { return nil } +func (m *CustomIsm) 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 ErrIntOverflowIsm + } + 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: CustomIsm: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CustomIsm: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) + } + m.Index = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIsm + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Index |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AbstractIsm", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIsm + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthIsm + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthIsm + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.AbstractIsm == nil { + m.AbstractIsm = &types.Any{} + } + if err := m.AbstractIsm.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipIsm(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthIsm + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} + func skipIsm(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/ism/types/keys.go b/x/ism/types/keys.go index c8d426e..70a9ac3 100644 --- a/x/ism/types/keys.go +++ b/x/ism/types/keys.go @@ -11,9 +11,15 @@ const ( // StoreKey is the store key string for hyperlane mailbox StoreKey = ModuleName - KeyOriginsDefaultIsm = "defaultIsm" + KeyOriginsDefaultIsm = "defaultIsm" + KeyCustomIsm = "customIsm" + KeyNextCustomIsmIndex = "nextCustomIsmIndex" ) -func OriginKey(origin uint32) []byte { +func DefaultIsmKey(origin uint32) []byte { return []byte(fmt.Sprintf("%s/%d", KeyOriginsDefaultIsm, origin)) } + +func CustomIsmKey(index uint32) []byte { + return []byte(fmt.Sprintf("%s/%d", KeyCustomIsm, index)) +} diff --git a/x/ism/types/legacy_multisig/legacy_multisig.go b/x/ism/types/legacy_multisig/legacy_multisig.go index b3afd3d..959b147 100644 --- a/x/ism/types/legacy_multisig/legacy_multisig.go +++ b/x/ism/types/legacy_multisig/legacy_multisig.go @@ -1,7 +1,6 @@ package legacy_multisig import ( - "fmt" "reflect" "strconv" @@ -16,7 +15,7 @@ import ( var _ types.AbstractIsm = (*LegacyMultiSig)(nil) -func (i *LegacyMultiSig) Event(origin uint32) sdk.Event { +func (i *LegacyMultiSig) DefaultIsmEvent(origin uint32) sdk.Event { originStr := strconv.FormatUint(uint64(origin), 10) thresholdStr := strconv.FormatUint(uint64(i.Threshold), 10) eventAttributes := []sdk.Attribute{} @@ -34,6 +33,24 @@ func (i *LegacyMultiSig) Event(origin uint32) sdk.Event { ) } +func (i *LegacyMultiSig) CustomIsmEvent(index uint32) sdk.Event { + indexStr := strconv.FormatUint(uint64(index), 10) + thresholdStr := strconv.FormatUint(uint64(i.Threshold), 10) + eventAttributes := []sdk.Attribute{} + eventAttributes = append(eventAttributes, sdk.NewAttribute(types.AttributeKeyIndex, indexStr)) + eventAttributes = append(eventAttributes, sdk.NewAttribute(types.AttributeKeyThreshold, thresholdStr)) + for index := 0; index < len(i.ValidatorPubKeys); index++ { + eventAttributes = append(eventAttributes, sdk.NewAttribute( + types.AttributeKeyValidator, + i.ValidatorPubKeys[index], + )) + } + return sdk.NewEvent( + types.EventTypeCreateCustomIsm, + eventAttributes..., + ) +} + func (i *LegacyMultiSig) Validate() error { if i.Threshold == 0 { return types.ErrInvalidThreshold @@ -79,8 +96,6 @@ func (i *LegacyMultiSig) VerifyValidatorSignatures(metadata []byte, message []by signerAddress := crypto.PubkeyToAddress(*signer) // Loop through remaining validators until we find a match for validatorIndex < validatorCount { - fmt.Println("Signer: ", hexutil.Encode(signerAddress[:])) - fmt.Println("Val: ", i.ValidatorPubKeys[validatorIndex]) valAddress, err := hexutil.Decode(i.ValidatorPubKeys[validatorIndex]) if err != nil { return false diff --git a/x/ism/types/merkle_root_multisig/merkle_root_multisig.go b/x/ism/types/merkle_root_multisig/merkle_root_multisig.go index 0726f66..e15388c 100644 --- a/x/ism/types/merkle_root_multisig/merkle_root_multisig.go +++ b/x/ism/types/merkle_root_multisig/merkle_root_multisig.go @@ -1,7 +1,6 @@ package merkle_root_multisig import ( - "fmt" "reflect" "strconv" @@ -16,7 +15,7 @@ import ( var _ types.AbstractIsm = (*MerkleRootMultiSig)(nil) -func (i *MerkleRootMultiSig) Event(origin uint32) sdk.Event { +func (i *MerkleRootMultiSig) DefaultIsmEvent(origin uint32) sdk.Event { originStr := strconv.FormatUint(uint64(origin), 10) thresholdStr := strconv.FormatUint(uint64(i.Threshold), 10) eventAttributes := []sdk.Attribute{} @@ -34,6 +33,24 @@ func (i *MerkleRootMultiSig) Event(origin uint32) sdk.Event { ) } +func (i *MerkleRootMultiSig) CustomIsmEvent(index uint32) sdk.Event { + indexStr := strconv.FormatUint(uint64(index), 10) + thresholdStr := strconv.FormatUint(uint64(i.Threshold), 10) + eventAttributes := []sdk.Attribute{} + eventAttributes = append(eventAttributes, sdk.NewAttribute(types.AttributeKeyIndex, indexStr)) + eventAttributes = append(eventAttributes, sdk.NewAttribute(types.AttributeKeyThreshold, thresholdStr)) + for index := 0; index < len(i.ValidatorPubKeys); index++ { + eventAttributes = append(eventAttributes, sdk.NewAttribute( + types.AttributeKeyValidator, + i.ValidatorPubKeys[index], + )) + } + return sdk.NewEvent( + types.EventTypeCreateCustomIsm, + eventAttributes..., + ) +} + func (i *MerkleRootMultiSig) Validate() error { if i.Threshold == 0 { return types.ErrInvalidThreshold @@ -90,8 +107,6 @@ func (i *MerkleRootMultiSig) VerifyValidatorSignatures(metadata []byte, message signerAddress := crypto.PubkeyToAddress(*signer) // Loop through remaining validators until we find a match for validatorIndex < validatorCount { - fmt.Println("Signer: ", hexutil.Encode(signerAddress[:])) - fmt.Println("Val: ", i.ValidatorPubKeys[validatorIndex]) valAddress, err := hexutil.Decode(i.ValidatorPubKeys[validatorIndex]) if err != nil { return false diff --git a/x/ism/types/message_id_multisig/message_id_mulitsig.go b/x/ism/types/message_id_multisig/message_id_mulitsig.go index be8b45c..ea03b0d 100644 --- a/x/ism/types/message_id_multisig/message_id_mulitsig.go +++ b/x/ism/types/message_id_multisig/message_id_mulitsig.go @@ -1,7 +1,6 @@ package message_id_multisig import ( - "fmt" "reflect" "strconv" @@ -15,7 +14,7 @@ import ( var _ types.AbstractIsm = (*MessageIdMultiSig)(nil) -func (i *MessageIdMultiSig) Event(origin uint32) sdk.Event { +func (i *MessageIdMultiSig) DefaultIsmEvent(origin uint32) sdk.Event { originStr := strconv.FormatUint(uint64(origin), 10) thresholdStr := strconv.FormatUint(uint64(i.Threshold), 10) eventAttributes := []sdk.Attribute{} @@ -33,6 +32,24 @@ func (i *MessageIdMultiSig) Event(origin uint32) sdk.Event { ) } +func (i *MessageIdMultiSig) CustomIsmEvent(index uint32) sdk.Event { + indexStr := strconv.FormatUint(uint64(index), 10) + thresholdStr := strconv.FormatUint(uint64(i.Threshold), 10) + eventAttributes := []sdk.Attribute{} + eventAttributes = append(eventAttributes, sdk.NewAttribute(types.AttributeKeyIndex, indexStr)) + eventAttributes = append(eventAttributes, sdk.NewAttribute(types.AttributeKeyThreshold, thresholdStr)) + for index := 0; index < len(i.ValidatorPubKeys); index++ { + eventAttributes = append(eventAttributes, sdk.NewAttribute( + types.AttributeKeyValidator, + i.ValidatorPubKeys[index], + )) + } + return sdk.NewEvent( + types.EventTypeCreateCustomIsm, + eventAttributes..., + ) +} + func (i *MessageIdMultiSig) Validate() error { if i.Threshold == 0 { return types.ErrInvalidThreshold @@ -76,8 +93,6 @@ func (i *MessageIdMultiSig) VerifyValidatorSignatures(metadata []byte, message [ signerAddress := crypto.PubkeyToAddress(*signer) // Loop through remaining validators until we find a match for validatorIndex < validatorCount { - fmt.Println("Signer: ", hexutil.Encode(signerAddress[:])) - fmt.Println("Val: ", i.ValidatorPubKeys[validatorIndex]) valAddress, err := hexutil.Decode(i.ValidatorPubKeys[validatorIndex]) if err != nil { return false diff --git a/x/ism/types/msgs.go b/x/ism/types/msgs.go index 2a40f1b..c372a93 100644 --- a/x/ism/types/msgs.go +++ b/x/ism/types/msgs.go @@ -11,7 +11,7 @@ var ( ) // NewMsgSetDefaultIsm creates a new MsgSetDefaultIsm instance -func NewMsgSetDefaultIsm(signer string, isms []*Ism) *MsgSetDefaultIsm { +func NewMsgSetDefaultIsm(signer string, isms []*DefaultIsm) *MsgSetDefaultIsm { return &MsgSetDefaultIsm{ Signer: signer, Isms: isms, @@ -57,3 +57,55 @@ func (m MsgSetDefaultIsm) UnpackInterfaces(unpacker codectypes.AnyUnpacker) erro } return nil } + + +var ( + _ sdk.Msg = (*MsgCreateIsm)(nil) + _ codectypes.UnpackInterfacesMessage = (*MsgCreateIsm)(nil) +) + +// NewMsgCreateIsm creates a new MsgCreateIsm instance +func NewMsgCreateIsm(signer string, ism *codectypes.Any) *MsgCreateIsm { + return &MsgCreateIsm{ + Signer: signer, + Ism: ism, + } +} + +// ValidateBasic implements sdk.Msg +func (m MsgCreateIsm) ValidateBasic() error { + if m.Ism == nil { + return ErrInvalidIsmSet + } + + ism, err := UnpackAbstractIsm(m.Ism) + if err != nil { + return err + } + err = ism.Validate() + if err != nil { + return err + } + + return nil +} + +// GetSigners implements sdk.Msg +func (m MsgCreateIsm) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(m.Signer) + if err != nil { + panic(err) + } + return []sdk.AccAddress{signer} +} + +func (m MsgCreateIsm) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + var ism AbstractIsm + + err := unpacker.UnpackAny(m.Ism, &ism) + if err != nil { + return err + } + return nil +} + diff --git a/x/ism/types/query.go b/x/ism/types/query.go new file mode 100644 index 0000000..31205c9 --- /dev/null +++ b/x/ism/types/query.go @@ -0,0 +1,56 @@ +package types + +import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" +) + +var ( + _ codectypes.UnpackInterfacesMessage = QueryOriginsDefaultIsmResponse{} + _ codectypes.UnpackInterfacesMessage = QueryCustomIsmResponse{} + _ codectypes.UnpackInterfacesMessage = QueryAllDefaultIsmsResponse{} + _ codectypes.UnpackInterfacesMessage = QueryAllCustomIsmsResponse{} +) + +func (r QueryOriginsDefaultIsmResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + if r.DefaultIsm != nil { + var ism AbstractIsm + return unpacker.UnpackAny(r.DefaultIsm, &ism) + } + return nil +} + +func (r QueryCustomIsmResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + if r.CustomIsm != nil { + var ism AbstractIsm + return unpacker.UnpackAny(r.CustomIsm, &ism) + } + return nil +} + +func (r QueryAllDefaultIsmsResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + for _, defaultIsm := range r.DefaultIsms { + ism := defaultIsm.AbstractIsm + if ism != nil { + var aIsm AbstractIsm + err := unpacker.UnpackAny(ism, &aIsm) + if err != nil { + return err + } + } + } + return nil +} + +func (r QueryAllCustomIsmsResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + for _, customIsm := range r.CustomIsms { + ism := customIsm.AbstractIsm + if ism != nil { + var aIsm AbstractIsm + err := unpacker.UnpackAny(ism, &aIsm) + if err != nil { + return err + } + } + } + return nil +} \ No newline at end of file diff --git a/x/ism/types/query.pb.go b/x/ism/types/query.pb.go index c8e328d..a69ea10 100644 --- a/x/ism/types/query.pb.go +++ b/x/ism/types/query.pb.go @@ -177,7 +177,7 @@ var xxx_messageInfo_QueryAllDefaultIsmsRequest proto.InternalMessageInfo // QueryAllDefaultIsmResponse is the response type for the AllDefaultIsms RPC // method. type QueryAllDefaultIsmsResponse struct { - DefaultIsms []*Ism `protobuf:"bytes,1,rep,name=default_isms,json=defaultIsms,proto3" json:"default_isms,omitempty"` + DefaultIsms []*DefaultIsm `protobuf:"bytes,1,rep,name=default_isms,json=defaultIsms,proto3" json:"default_isms,omitempty"` } func (m *QueryAllDefaultIsmsResponse) Reset() { *m = QueryAllDefaultIsmsResponse{} } @@ -218,50 +218,256 @@ func (m *QueryAllDefaultIsmsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryAllDefaultIsmsResponse proto.InternalMessageInfo -func (m *QueryAllDefaultIsmsResponse) GetDefaultIsms() []*Ism { +func (m *QueryAllDefaultIsmsResponse) GetDefaultIsms() []*DefaultIsm { if m != nil { return m.DefaultIsms } return nil } +// QueryCustomIsmRequest is the request type for the CustomIsm RPC method. +type QueryCustomIsmRequest struct { + IsmId uint32 `protobuf:"varint,1,opt,name=ism_id,json=ismId,proto3" json:"ism_id,omitempty"` +} + +func (m *QueryCustomIsmRequest) Reset() { *m = QueryCustomIsmRequest{} } +func (m *QueryCustomIsmRequest) String() string { return proto.CompactTextString(m) } +func (*QueryCustomIsmRequest) ProtoMessage() {} +func (*QueryCustomIsmRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_4dfd752fcec82ce5, []int{4} +} + +func (m *QueryCustomIsmRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} + +func (m *QueryCustomIsmRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryCustomIsmRequest.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 *QueryCustomIsmRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryCustomIsmRequest.Merge(m, src) +} + +func (m *QueryCustomIsmRequest) XXX_Size() int { + return m.Size() +} + +func (m *QueryCustomIsmRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryCustomIsmRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryCustomIsmRequest proto.InternalMessageInfo + +func (m *QueryCustomIsmRequest) GetIsmId() uint32 { + if m != nil { + return m.IsmId + } + return 0 +} + +// QueryCustomIsmResponse is the response type for the CustomIsm RPC method. +type QueryCustomIsmResponse struct { + CustomIsm *types.Any `protobuf:"bytes,1,opt,name=custom_ism,json=customIsm,proto3" json:"custom_ism,omitempty"` +} + +func (m *QueryCustomIsmResponse) Reset() { *m = QueryCustomIsmResponse{} } +func (m *QueryCustomIsmResponse) String() string { return proto.CompactTextString(m) } +func (*QueryCustomIsmResponse) ProtoMessage() {} +func (*QueryCustomIsmResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_4dfd752fcec82ce5, []int{5} +} + +func (m *QueryCustomIsmResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} + +func (m *QueryCustomIsmResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryCustomIsmResponse.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 *QueryCustomIsmResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryCustomIsmResponse.Merge(m, src) +} + +func (m *QueryCustomIsmResponse) XXX_Size() int { + return m.Size() +} + +func (m *QueryCustomIsmResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryCustomIsmResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryCustomIsmResponse proto.InternalMessageInfo + +func (m *QueryCustomIsmResponse) GetCustomIsm() *types.Any { + if m != nil { + return m.CustomIsm + } + return nil +} + +// QueryAllCustomIsmRequest is the request type for the AllCustomIsms RPC +// method. +type QueryAllCustomIsmsRequest struct{} + +func (m *QueryAllCustomIsmsRequest) Reset() { *m = QueryAllCustomIsmsRequest{} } +func (m *QueryAllCustomIsmsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAllCustomIsmsRequest) ProtoMessage() {} +func (*QueryAllCustomIsmsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_4dfd752fcec82ce5, []int{6} +} + +func (m *QueryAllCustomIsmsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} + +func (m *QueryAllCustomIsmsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllCustomIsmsRequest.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 *QueryAllCustomIsmsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllCustomIsmsRequest.Merge(m, src) +} + +func (m *QueryAllCustomIsmsRequest) XXX_Size() int { + return m.Size() +} + +func (m *QueryAllCustomIsmsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllCustomIsmsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllCustomIsmsRequest proto.InternalMessageInfo + +// QueryAllCustomIsmResponse is the response type for the AllCustomIsms RPC +// method. +type QueryAllCustomIsmsResponse struct { + CustomIsms []*CustomIsm `protobuf:"bytes,1,rep,name=custom_isms,json=customIsms,proto3" json:"custom_isms,omitempty"` +} + +func (m *QueryAllCustomIsmsResponse) Reset() { *m = QueryAllCustomIsmsResponse{} } +func (m *QueryAllCustomIsmsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAllCustomIsmsResponse) ProtoMessage() {} +func (*QueryAllCustomIsmsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_4dfd752fcec82ce5, []int{7} +} + +func (m *QueryAllCustomIsmsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} + +func (m *QueryAllCustomIsmsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAllCustomIsmsResponse.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 *QueryAllCustomIsmsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAllCustomIsmsResponse.Merge(m, src) +} + +func (m *QueryAllCustomIsmsResponse) XXX_Size() int { + return m.Size() +} + +func (m *QueryAllCustomIsmsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAllCustomIsmsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAllCustomIsmsResponse proto.InternalMessageInfo + +func (m *QueryAllCustomIsmsResponse) GetCustomIsms() []*CustomIsm { + if m != nil { + return m.CustomIsms + } + return nil +} + func init() { proto.RegisterType((*QueryOriginsDefaultIsmRequest)(nil), "hyperlane.ism.v1.QueryOriginsDefaultIsmRequest") proto.RegisterType((*QueryOriginsDefaultIsmResponse)(nil), "hyperlane.ism.v1.QueryOriginsDefaultIsmResponse") proto.RegisterType((*QueryAllDefaultIsmsRequest)(nil), "hyperlane.ism.v1.QueryAllDefaultIsmsRequest") proto.RegisterType((*QueryAllDefaultIsmsResponse)(nil), "hyperlane.ism.v1.QueryAllDefaultIsmsResponse") + proto.RegisterType((*QueryCustomIsmRequest)(nil), "hyperlane.ism.v1.QueryCustomIsmRequest") + proto.RegisterType((*QueryCustomIsmResponse)(nil), "hyperlane.ism.v1.QueryCustomIsmResponse") + proto.RegisterType((*QueryAllCustomIsmsRequest)(nil), "hyperlane.ism.v1.QueryAllCustomIsmsRequest") + proto.RegisterType((*QueryAllCustomIsmsResponse)(nil), "hyperlane.ism.v1.QueryAllCustomIsmsResponse") } func init() { proto.RegisterFile("hyperlane/ism/v1/query.proto", fileDescriptor_4dfd752fcec82ce5) } var fileDescriptor_4dfd752fcec82ce5 = []byte{ - // 413 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xc1, 0xaa, 0xd3, 0x40, - 0x18, 0x85, 0x3b, 0x57, 0xbc, 0x8b, 0x89, 0x8a, 0x0e, 0x2a, 0xd7, 0x58, 0xc3, 0x25, 0x28, 0x5e, - 0xc4, 0xcc, 0x78, 0x2b, 0xa2, 0x0b, 0x37, 0x15, 0x37, 0xae, 0xc4, 0x2e, 0x2c, 0xb8, 0x29, 0xd3, - 0x76, 0x9a, 0x0e, 0x4c, 0x66, 0xd2, 0xfc, 0x93, 0x60, 0xb6, 0x3e, 0x81, 0xe0, 0xca, 0x07, 0xf0, - 0x5d, 0x04, 0x37, 0x05, 0x37, 0x2e, 0xa5, 0xf5, 0x41, 0xa4, 0x93, 0xd8, 0x56, 0xd3, 0x4a, 0x97, - 0x93, 0x7f, 0xce, 0x39, 0xdf, 0x7f, 0x32, 0xb8, 0x3d, 0x2d, 0x53, 0x91, 0x29, 0xae, 0x05, 0x93, - 0x90, 0xb0, 0xe2, 0x9c, 0xcd, 0x72, 0x91, 0x95, 0x34, 0xcd, 0x8c, 0x35, 0xe4, 0xea, 0x7a, 0x4a, - 0x25, 0x24, 0xb4, 0x38, 0xf7, 0xdb, 0xb1, 0x31, 0xb1, 0x12, 0x8c, 0xa7, 0x92, 0x71, 0xad, 0x8d, - 0xe5, 0x56, 0x1a, 0x0d, 0xd5, 0x7d, 0xdf, 0x6f, 0xb8, 0xad, 0x64, 0xd5, 0xec, 0x56, 0xad, 0x74, - 0xa7, 0x61, 0x3e, 0x61, 0x5c, 0xd7, 0x31, 0xe1, 0x53, 0x7c, 0xe7, 0xcd, 0x2a, 0xf5, 0x75, 0x26, - 0x63, 0xa9, 0xe1, 0xa5, 0x98, 0xf0, 0x5c, 0xd9, 0x57, 0x90, 0xf4, 0xc4, 0x2c, 0x17, 0x60, 0xc9, - 0x4d, 0x7c, 0x6c, 0xdc, 0xec, 0x04, 0x9d, 0xa2, 0xb3, 0xcb, 0xbd, 0xfa, 0x14, 0xf6, 0x71, 0xb0, - 0x4f, 0x08, 0xa9, 0xd1, 0x20, 0xc8, 0x13, 0xec, 0x8d, 0xab, 0xaf, 0x03, 0x09, 0x89, 0x93, 0x7b, - 0x9d, 0xeb, 0xb4, 0x62, 0xa1, 0x7f, 0x58, 0x68, 0x57, 0x97, 0x3d, 0x3c, 0x5e, 0xcb, 0xc3, 0x36, - 0xf6, 0x9d, 0x71, 0x57, 0xa9, 0x8d, 0x29, 0xd4, 0x38, 0x61, 0x1f, 0xdf, 0xde, 0x39, 0xad, 0x33, - 0x9f, 0xe1, 0x4b, 0x5b, 0x99, 0x70, 0x82, 0x4e, 0x2f, 0x9c, 0x79, 0x9d, 0x1b, 0xf4, 0xdf, 0x32, - 0xe9, 0x0a, 0xd4, 0xdb, 0xa4, 0x42, 0xe7, 0xdb, 0x11, 0xbe, 0xe8, 0x9c, 0xc9, 0x17, 0x84, 0xaf, - 0x35, 0xb6, 0x22, 0xac, 0xe9, 0xf1, 0xdf, 0xe2, 0xfc, 0x47, 0x87, 0x0b, 0x2a, 0xf8, 0x30, 0xfa, - 0xf0, 0xfd, 0xd7, 0xa7, 0xa3, 0xfb, 0xe4, 0x1e, 0x6b, 0xfc, 0xcb, 0xaa, 0x74, 0x18, 0x6c, 0x2d, - 0x47, 0x3e, 0x23, 0x7c, 0xe5, 0xef, 0x1a, 0xc8, 0xc3, 0x3d, 0x99, 0x3b, 0xbb, 0xf4, 0xa3, 0x03, - 0x6f, 0xd7, 0x78, 0x0f, 0x1c, 0xde, 0x5d, 0x12, 0x36, 0xf1, 0xb8, 0x52, 0xdb, 0x68, 0xf0, 0xe2, - 0xed, 0xd7, 0x45, 0x80, 0xe6, 0x8b, 0x00, 0xfd, 0x5c, 0x04, 0xe8, 0xe3, 0x32, 0x68, 0xcd, 0x97, - 0x41, 0xeb, 0xc7, 0x32, 0x68, 0xbd, 0x7b, 0x1e, 0x4b, 0x3b, 0xcd, 0x87, 0x74, 0x64, 0x12, 0x06, - 0x36, 0xe3, 0x3a, 0x16, 0xca, 0x14, 0x22, 0x2a, 0x84, 0xb6, 0x79, 0x26, 0x60, 0x63, 0x1e, 0x8d, - 0x0c, 0x24, 0x06, 0xd8, 0x7b, 0x97, 0x62, 0xcb, 0x54, 0xc0, 0xf0, 0xd8, 0x3d, 0x9b, 0xc7, 0xbf, - 0x03, 0x00, 0x00, 0xff, 0xff, 0x18, 0x2b, 0x2f, 0xf2, 0x3c, 0x03, 0x00, 0x00, + // 552 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xc1, 0x6e, 0xd3, 0x40, + 0x10, 0x86, 0x63, 0xa0, 0x91, 0x3a, 0xa1, 0x08, 0x56, 0xb4, 0x6a, 0x9d, 0x60, 0x15, 0x53, 0xd4, + 0x00, 0x8d, 0x4d, 0x53, 0x21, 0x2e, 0x95, 0x50, 0x81, 0x4b, 0x0f, 0x08, 0x91, 0x03, 0x48, 0x3d, + 0x10, 0x39, 0xc9, 0x36, 0x5d, 0xc9, 0xde, 0x75, 0x3d, 0xeb, 0x88, 0x5c, 0x11, 0x0f, 0x80, 0x84, + 0x38, 0xf0, 0x00, 0xbc, 0x0b, 0xc7, 0x4a, 0x5c, 0x38, 0xa2, 0x84, 0x13, 0x4f, 0x81, 0xba, 0xde, + 0xd8, 0x6e, 0x9c, 0xd0, 0x1c, 0xed, 0x99, 0xf9, 0xff, 0x6f, 0xc6, 0xbf, 0xa1, 0x76, 0x32, 0x0c, + 0x69, 0xe4, 0x7b, 0x9c, 0xba, 0x0c, 0x03, 0x77, 0xb0, 0xeb, 0x9e, 0xc6, 0x34, 0x1a, 0x3a, 0x61, + 0x24, 0xa4, 0x20, 0x37, 0xd3, 0xaa, 0xc3, 0x30, 0x70, 0x06, 0xbb, 0x66, 0xad, 0x2f, 0x44, 0xdf, + 0xa7, 0xae, 0x17, 0x32, 0xd7, 0xe3, 0x5c, 0x48, 0x4f, 0x32, 0xc1, 0x31, 0xe9, 0x37, 0xcd, 0x82, + 0xda, 0xf9, 0x58, 0x52, 0xdb, 0xd0, 0x93, 0xea, 0xa9, 0x13, 0x1f, 0xbb, 0x1e, 0xd7, 0x36, 0xf6, + 0x53, 0xb8, 0xf3, 0xe6, 0xdc, 0xf5, 0x75, 0xc4, 0xfa, 0x8c, 0xe3, 0x4b, 0x7a, 0xec, 0xc5, 0xbe, + 0x3c, 0xc4, 0xa0, 0x45, 0x4f, 0x63, 0x8a, 0x92, 0xac, 0x41, 0x59, 0xa8, 0xda, 0xba, 0xb1, 0x69, + 0xd4, 0x57, 0x5a, 0xfa, 0xc9, 0x7e, 0x07, 0xd6, 0xbc, 0x41, 0x0c, 0x05, 0x47, 0x4a, 0x9e, 0x40, + 0xa5, 0x97, 0xbc, 0x6d, 0x33, 0x0c, 0xd4, 0x78, 0xa5, 0x79, 0xdb, 0x49, 0x58, 0x9c, 0x09, 0x8b, + 0x73, 0xc0, 0x87, 0x2d, 0xe8, 0xa5, 0xe3, 0x76, 0x0d, 0x4c, 0x25, 0x7c, 0xe0, 0xfb, 0x99, 0x28, + 0x6a, 0x1c, 0xfb, 0x3d, 0x54, 0x67, 0x56, 0xb5, 0xe7, 0x33, 0xb8, 0x9e, 0xf3, 0xc4, 0x75, 0x63, + 0xf3, 0x6a, 0xbd, 0xd2, 0xac, 0x39, 0xd3, 0xc7, 0x74, 0x72, 0xbc, 0x95, 0xcc, 0x1c, 0x6d, 0x07, + 0x56, 0x95, 0xfe, 0x8b, 0x18, 0xa5, 0x08, 0x72, 0x77, 0x58, 0x85, 0x32, 0xc3, 0xa0, 0xcd, 0x7a, + 0xfa, 0x0e, 0x4b, 0x0c, 0x83, 0xc3, 0x9e, 0xfd, 0x0a, 0xd6, 0xa6, 0xfb, 0x35, 0xca, 0x1e, 0x40, + 0x57, 0xbd, 0xbc, 0x74, 0xfb, 0xe5, 0xee, 0x64, 0xd8, 0xae, 0xc2, 0xc6, 0x64, 0xbd, 0x54, 0x31, + 0xdd, 0xfd, 0x28, 0xbb, 0x4c, 0xbe, 0xa8, 0xfd, 0xf6, 0xa1, 0x92, 0xf9, 0x4d, 0x36, 0xaf, 0x16, + 0x37, 0xcf, 0x48, 0x21, 0xf5, 0xc5, 0xe6, 0xdf, 0x6b, 0xb0, 0xa4, 0xc4, 0xc9, 0x77, 0x03, 0x6e, + 0x15, 0x3e, 0x2a, 0x71, 0x8b, 0x42, 0xff, 0xcd, 0x8d, 0xf9, 0x78, 0xf1, 0x81, 0x64, 0x01, 0xbb, + 0xf1, 0xf1, 0xe7, 0x9f, 0x2f, 0x57, 0xb6, 0xc9, 0x7d, 0xb7, 0x10, 0xe5, 0x24, 0x73, 0xd8, 0xce, + 0x7d, 0x5b, 0xf2, 0xcd, 0x80, 0x1b, 0x17, 0x53, 0x40, 0x76, 0xe6, 0x78, 0xce, 0x8c, 0x92, 0xd9, + 0x58, 0xb0, 0x5b, 0xe3, 0x3d, 0x54, 0x78, 0x5b, 0xc4, 0x2e, 0xe2, 0x79, 0xbe, 0x9f, 0x47, 0x43, + 0xf2, 0xc9, 0x80, 0xe5, 0xf4, 0xce, 0x64, 0x7b, 0x8e, 0xd1, 0x74, 0xc6, 0xcc, 0xfa, 0xe5, 0x8d, + 0x1a, 0x66, 0x4b, 0xc1, 0x58, 0xa4, 0x56, 0x84, 0xc9, 0x42, 0x40, 0xbe, 0x1a, 0xb0, 0x72, 0x21, + 0x2c, 0xe4, 0xd1, 0xfc, 0x9d, 0x0b, 0x79, 0x33, 0x77, 0x16, 0x6b, 0xd6, 0x48, 0x0f, 0x14, 0xd2, + 0x3d, 0x72, 0x77, 0xf6, 0x7d, 0x72, 0xd9, 0x7c, 0xfe, 0xf6, 0xc7, 0xc8, 0x32, 0xce, 0x46, 0x96, + 0xf1, 0x7b, 0x64, 0x19, 0x9f, 0xc7, 0x56, 0xe9, 0x6c, 0x6c, 0x95, 0x7e, 0x8d, 0xad, 0xd2, 0xd1, + 0x7e, 0x9f, 0xc9, 0x93, 0xb8, 0xe3, 0x74, 0x45, 0xe0, 0xa2, 0x8c, 0x3c, 0xde, 0xa7, 0xbe, 0x18, + 0xd0, 0xc6, 0x80, 0x72, 0x19, 0x47, 0x14, 0x33, 0xed, 0x46, 0x57, 0x60, 0x20, 0xd0, 0xfd, 0xa0, + 0x4c, 0xe4, 0x30, 0xa4, 0xd8, 0x29, 0xab, 0xdf, 0x6a, 0xef, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xde, 0xf5, 0xd4, 0x41, 0x5a, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -282,6 +488,10 @@ type QueryClient interface { OriginsDefaultIsm(ctx context.Context, in *QueryOriginsDefaultIsmRequest, opts ...grpc.CallOption) (*QueryOriginsDefaultIsmResponse, error) // Get all current default multisig ISMs AllDefaultIsms(ctx context.Context, in *QueryAllDefaultIsmsRequest, opts ...grpc.CallOption) (*QueryAllDefaultIsmsResponse, error) + // Get custom ISM + CustomIsm(ctx context.Context, in *QueryCustomIsmRequest, opts ...grpc.CallOption) (*QueryCustomIsmResponse, error) + // Get all custom ISMs + AllCustomIsms(ctx context.Context, in *QueryAllCustomIsmsRequest, opts ...grpc.CallOption) (*QueryAllCustomIsmsResponse, error) } type queryClient struct { @@ -310,12 +520,34 @@ func (c *queryClient) AllDefaultIsms(ctx context.Context, in *QueryAllDefaultIsm return out, nil } +func (c *queryClient) CustomIsm(ctx context.Context, in *QueryCustomIsmRequest, opts ...grpc.CallOption) (*QueryCustomIsmResponse, error) { + out := new(QueryCustomIsmResponse) + err := c.cc.Invoke(ctx, "/hyperlane.ism.v1.Query/CustomIsm", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) AllCustomIsms(ctx context.Context, in *QueryAllCustomIsmsRequest, opts ...grpc.CallOption) (*QueryAllCustomIsmsResponse, error) { + out := new(QueryAllCustomIsmsResponse) + err := c.cc.Invoke(ctx, "/hyperlane.ism.v1.Query/AllCustomIsms", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { // Get current default multisig ISM for an origin OriginsDefaultIsm(context.Context, *QueryOriginsDefaultIsmRequest) (*QueryOriginsDefaultIsmResponse, error) // Get all current default multisig ISMs AllDefaultIsms(context.Context, *QueryAllDefaultIsmsRequest) (*QueryAllDefaultIsmsResponse, error) + // Get custom ISM + CustomIsm(context.Context, *QueryCustomIsmRequest) (*QueryCustomIsmResponse, error) + // Get all custom ISMs + AllCustomIsms(context.Context, *QueryAllCustomIsmsRequest) (*QueryAllCustomIsmsResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -329,6 +561,14 @@ func (*UnimplementedQueryServer) AllDefaultIsms(ctx context.Context, req *QueryA return nil, status.Errorf(codes.Unimplemented, "method AllDefaultIsms not implemented") } +func (*UnimplementedQueryServer) CustomIsm(ctx context.Context, req *QueryCustomIsmRequest) (*QueryCustomIsmResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CustomIsm not implemented") +} + +func (*UnimplementedQueryServer) AllCustomIsms(ctx context.Context, req *QueryAllCustomIsmsRequest) (*QueryAllCustomIsmsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AllCustomIsms not implemented") +} + func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) } @@ -369,6 +609,42 @@ func _Query_AllDefaultIsms_Handler(srv interface{}, ctx context.Context, dec fun return interceptor(ctx, in, info, handler) } +func _Query_CustomIsm_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryCustomIsmRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).CustomIsm(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/hyperlane.ism.v1.Query/CustomIsm", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).CustomIsm(ctx, req.(*QueryCustomIsmRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_AllCustomIsms_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAllCustomIsmsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).AllCustomIsms(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/hyperlane.ism.v1.Query/AllCustomIsms", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).AllCustomIsms(ctx, req.(*QueryAllCustomIsmsRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "hyperlane.ism.v1.Query", HandlerType: (*QueryServer)(nil), @@ -381,6 +657,14 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "AllDefaultIsms", Handler: _Query_AllDefaultIsms_Handler, }, + { + MethodName: "CustomIsm", + Handler: _Query_CustomIsm_Handler, + }, + { + MethodName: "AllCustomIsms", + Handler: _Query_AllCustomIsms_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "hyperlane/ism/v1/query.proto", @@ -509,76 +793,248 @@ func (m *QueryAllDefaultIsmsResponse) MarshalToSizedBuffer(dAtA []byte) (int, er return len(dAtA) - i, nil } -func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { - offset -= sovQuery(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ +func (m *QueryCustomIsmRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err } - dAtA[offset] = uint8(v) - return base + return dAtA[:n], nil } -func (m *QueryOriginsDefaultIsmRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Origin != 0 { - n += 1 + sovQuery(uint64(m.Origin)) - } - return n +func (m *QueryCustomIsmRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryOriginsDefaultIsmResponse) Size() (n int) { - if m == nil { - return 0 - } +func (m *QueryCustomIsmRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i var l int _ = l - if m.DefaultIsm != nil { - l = m.DefaultIsm.Size() - n += 1 + l + sovQuery(uint64(l)) + if m.IsmId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.IsmId)) + i-- + dAtA[i] = 0x8 } - return n + return len(dAtA) - i, nil } -func (m *QueryAllDefaultIsmsRequest) Size() (n int) { - if m == nil { - return 0 +func (m *QueryCustomIsmResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err } - var l int - _ = l - return n + return dAtA[:n], nil } -func (m *QueryAllDefaultIsmsResponse) Size() (n int) { - if m == nil { - return 0 - } +func (m *QueryCustomIsmResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryCustomIsmResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i var l int _ = l - if len(m.DefaultIsms) > 0 { - for _, e := range m.DefaultIsms { - l = e.Size() - n += 1 + l + sovQuery(uint64(l)) + if m.CustomIsm != nil { + { + size, err := m.CustomIsm.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa } - return n + return len(dAtA) - i, nil } -func sovQuery(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 +func (m *QueryAllCustomIsmsRequest) 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 sozQuery(x uint64) (n int) { - return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +func (m *QueryAllCustomIsmsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryOriginsDefaultIsmRequest) Unmarshal(dAtA []byte) error { +func (m *QueryAllCustomIsmsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryAllCustomIsmsResponse) 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 *QueryAllCustomIsmsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAllCustomIsmsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CustomIsms) > 0 { + for iNdEx := len(m.CustomIsms) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.CustomIsms[iNdEx].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 + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} + +func (m *QueryOriginsDefaultIsmRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Origin != 0 { + n += 1 + sovQuery(uint64(m.Origin)) + } + return n +} + +func (m *QueryOriginsDefaultIsmResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.DefaultIsm != nil { + l = m.DefaultIsm.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAllDefaultIsmsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryAllDefaultIsmsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.DefaultIsms) > 0 { + for _, e := range m.DefaultIsms { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func (m *QueryCustomIsmRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.IsmId != 0 { + n += 1 + sovQuery(uint64(m.IsmId)) + } + return n +} + +func (m *QueryCustomIsmResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.CustomIsm != nil { + l = m.CustomIsm.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAllCustomIsmsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryAllCustomIsmsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.CustomIsms) > 0 { + for _, e := range m.CustomIsms { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} + +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} + +func (m *QueryOriginsDefaultIsmRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -844,7 +1300,7 @@ func (m *QueryAllDefaultIsmsResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.DefaultIsms = append(m.DefaultIsms, &Ism{}) + m.DefaultIsms = append(m.DefaultIsms, &DefaultIsm{}) if err := m.DefaultIsms[len(m.DefaultIsms)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -871,6 +1327,299 @@ func (m *QueryAllDefaultIsmsResponse) Unmarshal(dAtA []byte) error { return nil } +func (m *QueryCustomIsmRequest) 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: QueryCustomIsmRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryCustomIsmRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IsmId", wireType) + } + m.IsmId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.IsmId |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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 *QueryCustomIsmResponse) 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: QueryCustomIsmResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryCustomIsmResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CustomIsm", 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 m.CustomIsm == nil { + m.CustomIsm = &types.Any{} + } + if err := m.CustomIsm.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 (m *QueryAllCustomIsmsRequest) 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: QueryAllCustomIsmsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllCustomIsmsRequest: 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 *QueryAllCustomIsmsResponse) 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: QueryAllCustomIsmsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAllCustomIsmsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CustomIsms", 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 + } + m.CustomIsms = append(m.CustomIsms, &CustomIsm{}) + if err := m.CustomIsms[len(m.CustomIsms)-1].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/ism/types/query.pb.gw.go b/x/ism/types/query.pb.gw.go index e8de75b..99d86c2 100644 --- a/x/ism/types/query.pb.gw.go +++ b/x/ism/types/query.pb.gw.go @@ -83,6 +83,54 @@ func local_request_Query_AllDefaultIsms_0(ctx context.Context, marshaler runtime return msg, metadata, err } +var filter_Query_CustomIsm_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} + +func request_Query_CustomIsm_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryCustomIsmRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_CustomIsm_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.CustomIsm(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_Query_CustomIsm_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryCustomIsmRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_CustomIsm_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.CustomIsm(ctx, &protoReq) + return msg, metadata, err +} + +func request_Query_AllCustomIsms_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllCustomIsmsRequest + var metadata runtime.ServerMetadata + + msg, err := client.AllCustomIsms(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_Query_AllCustomIsms_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAllCustomIsmsRequest + var metadata runtime.ServerMetadata + + msg, err := server.AllCustomIsms(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. @@ -132,6 +180,50 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv forward_Query_AllDefaultIsms_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) + mux.Handle("GET", pattern_Query_CustomIsm_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_CustomIsm_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_CustomIsm_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + + mux.Handle("GET", pattern_Query_AllCustomIsms_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_AllCustomIsms_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_AllCustomIsms_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + return nil } @@ -210,6 +302,44 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie forward_Query_AllDefaultIsms_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) + mux.Handle("GET", pattern_Query_CustomIsm_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_CustomIsm_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_CustomIsm_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + + mux.Handle("GET", pattern_Query_AllCustomIsms_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_AllCustomIsms_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_AllCustomIsms_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + return nil } @@ -217,10 +347,18 @@ var ( pattern_Query_OriginsDefaultIsm_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"hyperlane", "ism", "v1", "origins_default_ism"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_AllDefaultIsms_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"hyperlane", "ism", "v1", "all_default_isms"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_CustomIsm_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"hyperlane", "ism", "v1", "custom_ism"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_AllCustomIsms_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"hyperlane", "ism", "v1", "all_custom_isms"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( forward_Query_OriginsDefaultIsm_0 = runtime.ForwardResponseMessage forward_Query_AllDefaultIsms_0 = runtime.ForwardResponseMessage + + forward_Query_CustomIsm_0 = runtime.ForwardResponseMessage + + forward_Query_AllCustomIsms_0 = runtime.ForwardResponseMessage ) diff --git a/x/ism/types/tx.pb.go b/x/ism/types/tx.pb.go index ead2f87..48aef5b 100644 --- a/x/ism/types/tx.pb.go +++ b/x/ism/types/tx.pb.go @@ -10,6 +10,11 @@ import ( math "math" math_bits "math/bits" + _ "github.com/cosmos/cosmos-proto" + types "github.com/cosmos/cosmos-sdk/codec/types" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" grpc "google.golang.org/grpc" @@ -32,8 +37,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // MsgSetDefaultIsm defines the request type for the SetDefaultIsm rpc. type MsgSetDefaultIsm struct { - Signer string `protobuf:"bytes,1,opt,name=signer,proto3" json:"signer,omitempty"` - Isms []*Ism `protobuf:"bytes,2,rep,name=isms,proto3" json:"isms,omitempty"` + Signer string `protobuf:"bytes,1,opt,name=signer,proto3" json:"signer,omitempty"` + Isms []*DefaultIsm `protobuf:"bytes,2,rep,name=isms,proto3" json:"isms,omitempty"` } func (m *MsgSetDefaultIsm) Reset() { *m = MsgSetDefaultIsm{} } @@ -74,20 +79,6 @@ func (m *MsgSetDefaultIsm) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSetDefaultIsm proto.InternalMessageInfo -func (m *MsgSetDefaultIsm) GetSigner() string { - if m != nil { - return m.Signer - } - return "" -} - -func (m *MsgSetDefaultIsm) GetIsms() []*Ism { - if m != nil { - return m.Isms - } - return nil -} - // MsgSetDefaultIsmResponse defines the Msg/SetDefaultIsm response type type MsgSetDefaultIsmResponse struct{} @@ -129,32 +120,143 @@ func (m *MsgSetDefaultIsmResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSetDefaultIsmResponse proto.InternalMessageInfo +// MsgCreateIsm defines the request type to create a hyperlane ISM +type MsgCreateIsm struct { + Signer string `protobuf:"bytes,1,opt,name=signer,proto3" json:"signer,omitempty"` + Ism *types.Any `protobuf:"bytes,2,opt,name=ism,proto3" json:"ism,omitempty"` +} + +func (m *MsgCreateIsm) Reset() { *m = MsgCreateIsm{} } +func (m *MsgCreateIsm) String() string { return proto.CompactTextString(m) } +func (*MsgCreateIsm) ProtoMessage() {} +func (*MsgCreateIsm) Descriptor() ([]byte, []int) { + return fileDescriptor_7b013040feeda308, []int{2} +} + +func (m *MsgCreateIsm) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} + +func (m *MsgCreateIsm) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateIsm.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 *MsgCreateIsm) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateIsm.Merge(m, src) +} + +func (m *MsgCreateIsm) XXX_Size() int { + return m.Size() +} + +func (m *MsgCreateIsm) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateIsm.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateIsm proto.InternalMessageInfo + +// MsgCreateIsmResponse deines the MsgCreateIsm response type +type MsgCreateIsmResponse struct { + // The unique ID assigned to the newly created ISM + IsmId uint32 `protobuf:"varint,1,opt,name=ism_id,json=ismId,proto3" json:"ism_id,omitempty"` +} + +func (m *MsgCreateIsmResponse) Reset() { *m = MsgCreateIsmResponse{} } +func (m *MsgCreateIsmResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCreateIsmResponse) ProtoMessage() {} +func (*MsgCreateIsmResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_7b013040feeda308, []int{3} +} + +func (m *MsgCreateIsmResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} + +func (m *MsgCreateIsmResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateIsmResponse.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 *MsgCreateIsmResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateIsmResponse.Merge(m, src) +} + +func (m *MsgCreateIsmResponse) XXX_Size() int { + return m.Size() +} + +func (m *MsgCreateIsmResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateIsmResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateIsmResponse proto.InternalMessageInfo + +func (m *MsgCreateIsmResponse) GetIsmId() uint32 { + if m != nil { + return m.IsmId + } + return 0 +} + func init() { proto.RegisterType((*MsgSetDefaultIsm)(nil), "hyperlane.ism.v1.MsgSetDefaultIsm") proto.RegisterType((*MsgSetDefaultIsmResponse)(nil), "hyperlane.ism.v1.MsgSetDefaultIsmResponse") + proto.RegisterType((*MsgCreateIsm)(nil), "hyperlane.ism.v1.MsgCreateIsm") + proto.RegisterType((*MsgCreateIsmResponse)(nil), "hyperlane.ism.v1.MsgCreateIsmResponse") } func init() { proto.RegisterFile("hyperlane/ism/v1/tx.proto", fileDescriptor_7b013040feeda308) } var fileDescriptor_7b013040feeda308 = []byte{ - // 260 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcc, 0xa8, 0x2c, 0x48, - 0x2d, 0xca, 0x49, 0xcc, 0x4b, 0xd5, 0xcf, 0x2c, 0xce, 0xd5, 0x2f, 0x33, 0xd4, 0x2f, 0xa9, 0xd0, - 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x80, 0x4b, 0xe9, 0x65, 0x16, 0xe7, 0xea, 0x95, 0x19, - 0x4a, 0x49, 0x61, 0x28, 0x06, 0x49, 0x80, 0x55, 0x2b, 0x85, 0x72, 0x09, 0xf8, 0x16, 0xa7, 0x07, - 0xa7, 0x96, 0xb8, 0xa4, 0xa6, 0x25, 0x96, 0xe6, 0x94, 0x78, 0x16, 0xe7, 0x0a, 0x89, 0x71, 0xb1, - 0x15, 0x67, 0xa6, 0xe7, 0xa5, 0x16, 0x49, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x41, 0x79, 0x42, - 0x9a, 0x5c, 0x2c, 0x99, 0xc5, 0xb9, 0xc5, 0x12, 0x4c, 0x0a, 0xcc, 0x1a, 0xdc, 0x46, 0xa2, 0x7a, - 0xe8, 0x16, 0xe9, 0x79, 0x16, 0xe7, 0x06, 0x81, 0x95, 0x28, 0x49, 0x71, 0x49, 0xa0, 0x1b, 0x1b, - 0x94, 0x5a, 0x5c, 0x90, 0x9f, 0x57, 0x9c, 0x6a, 0x94, 0xc6, 0xc5, 0xec, 0x5b, 0x9c, 0x2e, 0x14, - 0xcf, 0xc5, 0x8b, 0x6a, 0xad, 0x12, 0xa6, 0x81, 0xe8, 0x66, 0x48, 0x69, 0x11, 0x56, 0x03, 0xb3, - 0xc7, 0x29, 0xec, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, - 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x6c, 0xd2, 0x33, - 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x8b, 0x4b, 0x8a, 0x12, 0xf3, 0xd2, 0x53, - 0x73, 0xf2, 0xcb, 0x52, 0x75, 0xcb, 0x52, 0xf3, 0x4a, 0x4a, 0x8b, 0x52, 0x8b, 0xf5, 0xe1, 0x96, - 0xe8, 0x26, 0xe7, 0x17, 0xe7, 0xe6, 0x17, 0xeb, 0x57, 0x80, 0x43, 0xae, 0xa4, 0xb2, 0x20, 0xb5, - 0x38, 0x89, 0x0d, 0x1c, 0x72, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xef, 0xd6, 0x66, 0x48, - 0x84, 0x01, 0x00, 0x00, + // 481 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0x3f, 0x6b, 0xdb, 0x40, + 0x18, 0xc6, 0x75, 0x71, 0x63, 0xc8, 0xa5, 0x81, 0x54, 0xb8, 0x54, 0x11, 0x45, 0x31, 0x1a, 0x82, + 0x31, 0x58, 0x97, 0xb8, 0xd0, 0x21, 0x74, 0x49, 0xda, 0x25, 0x83, 0x17, 0x19, 0x3a, 0x74, 0x31, + 0x72, 0xf4, 0xe6, 0x72, 0xe0, 0xbb, 0x33, 0x7a, 0xcf, 0x26, 0xde, 0x4a, 0xa7, 0xd2, 0xa9, 0x1f, + 0xa0, 0x43, 0x3e, 0x41, 0xf1, 0xd0, 0x4f, 0xd0, 0xa9, 0x63, 0xe8, 0xd4, 0xb1, 0xd8, 0x83, 0xfb, + 0x31, 0x8a, 0xfe, 0xd8, 0x4e, 0xec, 0xfe, 0x81, 0x2c, 0x42, 0xef, 0x3d, 0xcf, 0x7b, 0xf7, 0x7b, + 0x9f, 0x93, 0xe8, 0xde, 0xe5, 0xa8, 0x0f, 0x49, 0x2f, 0x52, 0xc0, 0x04, 0x4a, 0x36, 0x3c, 0x62, + 0xe6, 0x2a, 0xe8, 0x27, 0xda, 0x68, 0x7b, 0x77, 0x21, 0x05, 0x02, 0x65, 0x30, 0x3c, 0x72, 0x1f, + 0x45, 0x52, 0x28, 0xcd, 0xb2, 0x67, 0x6e, 0x72, 0x9f, 0x9c, 0x6b, 0x94, 0x1a, 0x99, 0x44, 0x9e, + 0x36, 0x4b, 0xe4, 0x85, 0xb0, 0x97, 0x0b, 0x9d, 0xac, 0x62, 0x79, 0x51, 0x48, 0x15, 0xae, 0xb9, + 0xce, 0xd7, 0xd3, 0xb7, 0x79, 0x03, 0xd7, 0x9a, 0xf7, 0x80, 0x65, 0x55, 0x77, 0x70, 0xc1, 0x22, + 0x35, 0x2a, 0x24, 0x77, 0x0d, 0x32, 0x05, 0xca, 0x34, 0xff, 0x33, 0xa1, 0xbb, 0x2d, 0xe4, 0x6d, + 0x30, 0xaf, 0xe0, 0x22, 0x1a, 0xf4, 0xcc, 0x19, 0x4a, 0xfb, 0x90, 0x96, 0x51, 0x70, 0x05, 0x89, + 0x43, 0xaa, 0xa4, 0xb6, 0x75, 0xea, 0x7c, 0xff, 0xd2, 0xa8, 0x14, 0x0c, 0x27, 0x71, 0x9c, 0x00, + 0x62, 0xdb, 0x24, 0x42, 0xf1, 0xb0, 0xf0, 0xd9, 0x87, 0xf4, 0x81, 0x40, 0x89, 0xce, 0x46, 0xb5, + 0x54, 0xdb, 0x6e, 0x3e, 0x0d, 0x56, 0x67, 0x0f, 0x96, 0xbb, 0x87, 0x99, 0xf3, 0xf8, 0xf9, 0xfb, + 0xeb, 0x7d, 0xeb, 0xd7, 0xf5, 0xbe, 0xf5, 0x6e, 0x36, 0xae, 0x97, 0x11, 0x54, 0x0c, 0xc9, 0x87, + 0xd9, 0xb8, 0xee, 0x2d, 0x5a, 0x1b, 0x29, 0xec, 0x2a, 0x9b, 0xef, 0x52, 0x67, 0x75, 0x2d, 0x04, + 0xec, 0x6b, 0x85, 0xe0, 0x7f, 0x22, 0xf4, 0x61, 0x0b, 0xf9, 0xcb, 0x04, 0x22, 0x03, 0xf7, 0x1b, + 0xe4, 0x80, 0x96, 0x04, 0x4a, 0x67, 0xa3, 0x4a, 0x6a, 0xdb, 0xcd, 0x4a, 0x90, 0x87, 0x1a, 0xcc, + 0x43, 0x0d, 0x4e, 0xd4, 0x28, 0x4c, 0x0d, 0xc7, 0xcd, 0xbf, 0xe0, 0xbb, 0x6b, 0xf8, 0x0b, 0x1a, + 0xbf, 0x41, 0x2b, 0xb7, 0xeb, 0x39, 0xb6, 0xfd, 0x98, 0x96, 0x05, 0xca, 0x8e, 0x88, 0x33, 0xca, + 0x9d, 0x70, 0x53, 0xa0, 0x3c, 0x8b, 0x9b, 0x5f, 0x09, 0x2d, 0xb5, 0x90, 0xdb, 0x6d, 0xba, 0xb5, + 0x9c, 0xc8, 0x5b, 0x8f, 0xf6, 0xf6, 0x9e, 0xee, 0xc1, 0xbf, 0xf5, 0xc5, 0x99, 0x1d, 0xba, 0x73, + 0xf7, 0xce, 0xfd, 0x3f, 0x36, 0xde, 0xf1, 0xb8, 0xf5, 0xff, 0x7b, 0xe6, 0x07, 0xb8, 0x9b, 0x6f, + 0x67, 0xe3, 0x3a, 0x39, 0x7d, 0xfd, 0x6d, 0xe2, 0x91, 0x9b, 0x89, 0x47, 0x7e, 0x4e, 0x3c, 0xf2, + 0x71, 0xea, 0x59, 0x37, 0x53, 0xcf, 0xfa, 0x31, 0xf5, 0xac, 0x37, 0x2f, 0xb8, 0x30, 0x97, 0x83, + 0x6e, 0x70, 0xae, 0x25, 0x43, 0x93, 0x44, 0x8a, 0x43, 0x4f, 0x0f, 0xa1, 0x31, 0x04, 0x65, 0x06, + 0x09, 0x20, 0x5b, 0x26, 0x59, 0xfc, 0x24, 0x57, 0xd9, 0xe7, 0x6b, 0x46, 0x7d, 0xc0, 0x6e, 0x39, + 0xbb, 0x92, 0x67, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0xa4, 0xd2, 0x86, 0xf8, 0x81, 0x03, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -171,6 +273,8 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { + // Create a custom ISM + CreateIsm(ctx context.Context, in *MsgCreateIsm, opts ...grpc.CallOption) (*MsgCreateIsmResponse, error) // SetDefaultIsm defines a rpc handler method for MsgSetDefaultIsm. SetDefaultIsm(ctx context.Context, in *MsgSetDefaultIsm, opts ...grpc.CallOption) (*MsgSetDefaultIsmResponse, error) } @@ -183,6 +287,15 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } +func (c *msgClient) CreateIsm(ctx context.Context, in *MsgCreateIsm, opts ...grpc.CallOption) (*MsgCreateIsmResponse, error) { + out := new(MsgCreateIsmResponse) + err := c.cc.Invoke(ctx, "/hyperlane.ism.v1.Msg/CreateIsm", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *msgClient) SetDefaultIsm(ctx context.Context, in *MsgSetDefaultIsm, opts ...grpc.CallOption) (*MsgSetDefaultIsmResponse, error) { out := new(MsgSetDefaultIsmResponse) err := c.cc.Invoke(ctx, "/hyperlane.ism.v1.Msg/SetDefaultIsm", in, out, opts...) @@ -194,6 +307,8 @@ func (c *msgClient) SetDefaultIsm(ctx context.Context, in *MsgSetDefaultIsm, opt // MsgServer is the server API for Msg service. type MsgServer interface { + // Create a custom ISM + CreateIsm(context.Context, *MsgCreateIsm) (*MsgCreateIsmResponse, error) // SetDefaultIsm defines a rpc handler method for MsgSetDefaultIsm. SetDefaultIsm(context.Context, *MsgSetDefaultIsm) (*MsgSetDefaultIsmResponse, error) } @@ -201,6 +316,10 @@ type MsgServer interface { // UnimplementedMsgServer can be embedded to have forward compatible implementations. type UnimplementedMsgServer struct{} +func (*UnimplementedMsgServer) CreateIsm(ctx context.Context, req *MsgCreateIsm) (*MsgCreateIsmResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateIsm not implemented") +} + func (*UnimplementedMsgServer) SetDefaultIsm(ctx context.Context, req *MsgSetDefaultIsm) (*MsgSetDefaultIsmResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SetDefaultIsm not implemented") } @@ -209,6 +328,24 @@ func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } +func _Msg_CreateIsm_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCreateIsm) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).CreateIsm(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/hyperlane.ism.v1.Msg/CreateIsm", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).CreateIsm(ctx, req.(*MsgCreateIsm)) + } + return interceptor(ctx, in, info, handler) +} + func _Msg_SetDefaultIsm_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(MsgSetDefaultIsm) if err := dec(in); err != nil { @@ -231,6 +368,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "hyperlane.ism.v1.Msg", HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ + { + MethodName: "CreateIsm", + Handler: _Msg_CreateIsm_Handler, + }, { MethodName: "SetDefaultIsm", Handler: _Msg_SetDefaultIsm_Handler, @@ -307,6 +448,76 @@ func (m *MsgSetDefaultIsmResponse) MarshalToSizedBuffer(dAtA []byte) (int, error return len(dAtA) - i, nil } +func (m *MsgCreateIsm) 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 *MsgCreateIsm) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateIsm) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Ism != nil { + { + size, err := m.Ism.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgCreateIsmResponse) 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 *MsgCreateIsmResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateIsmResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.IsmId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.IsmId)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -347,6 +558,35 @@ func (m *MsgSetDefaultIsmResponse) Size() (n int) { return n } +func (m *MsgCreateIsm) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Ism != nil { + l = m.Ism.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgCreateIsmResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.IsmId != 0 { + n += 1 + sovTx(uint64(m.IsmId)) + } + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -445,7 +685,7 @@ func (m *MsgSetDefaultIsm) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Isms = append(m.Isms, &Ism{}) + m.Isms = append(m.Isms, &DefaultIsm{}) if err := m.Isms[len(m.Isms)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -523,6 +763,195 @@ func (m *MsgSetDefaultIsmResponse) Unmarshal(dAtA []byte) error { return nil } +func (m *MsgCreateIsm) 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 ErrIntOverflowTx + } + 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: MsgCreateIsm: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateIsm: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Ism", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Ism == nil { + m.Ism = &types.Any{} + } + if err := m.Ism.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} + +func (m *MsgCreateIsmResponse) 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 ErrIntOverflowTx + } + 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: MsgCreateIsmResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateIsmResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IsmId", wireType) + } + m.IsmId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.IsmId |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} + func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/mailbox/keeper/msg_server.go b/x/mailbox/keeper/msg_server.go index 9d799ca..6d39b05 100644 --- a/x/mailbox/keeper/msg_server.go +++ b/x/mailbox/keeper/msg_server.go @@ -35,6 +35,8 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer { return keeper } +// func (k Keeper) CreateIsm(goCtx context.Context, msg *types.) + // Dispatch defines a rpc handler method for MsgDispatch func (k Keeper) Dispatch(goCtx context.Context, msg *types.MsgDispatch) (*types.MsgDispatchResponse, error) { tree := k.GetImtTree(goCtx) @@ -148,7 +150,7 @@ func (k Keeper) Process(goCtx context.Context, msg *types.MsgProcess) (*types.Ms metadataBytes := hexutil.MustDecode(msg.Metadata) // Verify message signatures - verified, err := k.ismKeeper.Verify(metadataBytes, messageBytes) + verified, err := k.ismKeeper.Verify(goCtx, metadataBytes, messageBytes) if err != nil { return nil, err } From 83692a3588f2746fda118b0d68eb8b8631b531ae Mon Sep 17 00:00:00 2001 From: Steve Miskovetz Date: Fri, 27 Oct 2023 16:58:10 -0600 Subject: [PATCH 2/2] Small interchaintest fix --- interchaintest/helpers/ism.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interchaintest/helpers/ism.go b/interchaintest/helpers/ism.go index 7a195ba..bdfb12c 100644 --- a/interchaintest/helpers/ism.go +++ b/interchaintest/helpers/ism.go @@ -21,7 +21,7 @@ import ( "github.com/strangelove-ventures/hyperlane-cosmos/x/ism/types/message_id_multisig" ) -func GetDefaultIsms(counterChains ...*counterchain.CounterChain) (isms []*ismtypes.Ism) { +func GetDefaultIsms(counterChains ...*counterchain.CounterChain) (isms []*ismtypes.DefaultIsm) { for _, counterChain := range counterChains { var valSet []string for _, val := range counterChain.ValSet.Vals { @@ -51,7 +51,7 @@ func GetDefaultIsms(counterChains ...*counterchain.CounterChain) (isms []*ismtyp }, ) } - isms = append(isms, &ismtypes.Ism{ + isms = append(isms, &ismtypes.DefaultIsm{ Origin: counterChain.Domain, AbstractIsm: ism, })