From 800c506e6d58cc7ec4b7a1030309fd305f97e63e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wo=C5=BAniak?= Date: Wed, 22 Jan 2025 18:11:08 +0100 Subject: [PATCH 1/5] Add new EurekaMsg --- types/eureka.go | 16 ++++++++++++++++ types/msg.go | 15 +++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 types/eureka.go diff --git a/types/eureka.go b/types/eureka.go new file mode 100644 index 000000000..befbeee99 --- /dev/null +++ b/types/eureka.go @@ -0,0 +1,16 @@ +package types + +// EurekaPayload defines a single packet sent in the EurekaSendPacketMsg +// +// Payload value should be encoded in a format defined by the channel version, +// and the module on the other side should know how to parse this. +type EurekaPayload struct { + // The port id on the chain where the packet is sent to (external chain). + DestinationPort string `json:"destination_port"` + // Version of the receiving contract. + Version string `json:"version"` + // Encoding used to serialize the Value. + Encoding string `json:"encoding"` + // Encoded payload data + Value []byte `json:"value"` +} diff --git a/types/msg.go b/types/msg.go index 60a6e8751..d26d92062 100644 --- a/types/msg.go +++ b/types/msg.go @@ -60,6 +60,7 @@ type CosmosMsg struct { Staking *StakingMsg `json:"staking,omitempty"` Any *AnyMsg `json:"any,omitempty"` Wasm *WasmMsg `json:"wasm,omitempty"` + Eureka *EurekaMsg `json:"eureka,omitempty"` } func (m *CosmosMsg) UnmarshalJSON(data []byte) error { @@ -74,6 +75,7 @@ func (m *CosmosMsg) UnmarshalJSON(data []byte) error { Any *AnyMsg `json:"any,omitempty"` Wasm *WasmMsg `json:"wasm,omitempty"` Stargate *AnyMsg `json:"stargate,omitempty"` + Eureka *EurekaMsg `json:"eureka,omitempty"` } var tmp InternalCosmosMsg err := json.Unmarshal(data, &tmp) @@ -97,6 +99,7 @@ func (m *CosmosMsg) UnmarshalJSON(data []byte) error { Staking: tmp.Staking, Any: tmp.Any, Wasm: tmp.Wasm, + Eureka: tmp.Eureka, } return nil } @@ -350,6 +353,18 @@ type WasmMsg struct { ClearAdmin *ClearAdminMsg `json:"clear_admin,omitempty"` } +// These are messages in the IBC lifecycle using the new Eureka approach. Only usable by IBC-enabled contracts +type EurekaMsg struct { + SendPacket *EurekaSendPacketMsg `json:"execute,omitempty"` +} + +// Sends an IBC packet with given payloads over the existing channel. +type EurekaSendPacketMsg struct { + ChannelID string `json:"channel_id"` + Data []EurekaPayload `json:"data"` + Timestamp uint64 `json:"timestamp,string,omitempty"` +} + // ExecuteMsg is used to call another defined contract on this chain. // The calling contract requires the callee to be defined beforehand, // and the address should have been defined in initialization. From 55a4044f2278438ca62b812993e958036342fa9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wo=C5=BAniak?= Date: Thu, 23 Jan 2025 16:54:25 +0100 Subject: [PATCH 2/5] Update types/msg.go Co-authored-by: Christoph Otter --- types/msg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/msg.go b/types/msg.go index d26d92062..61e45013f 100644 --- a/types/msg.go +++ b/types/msg.go @@ -362,7 +362,7 @@ type EurekaMsg struct { type EurekaSendPacketMsg struct { ChannelID string `json:"channel_id"` Data []EurekaPayload `json:"data"` - Timestamp uint64 `json:"timestamp,string,omitempty"` + Timeout uint64 `json:"timeout,string,omitempty"` } // ExecuteMsg is used to call another defined contract on this chain. From d1ee0325d3940b1a6c970fa7188afcbd49744804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wo=C5=BAniak?= Date: Thu, 23 Jan 2025 16:54:43 +0100 Subject: [PATCH 3/5] Update types/msg.go Co-authored-by: Christoph Otter --- types/msg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/msg.go b/types/msg.go index 61e45013f..6c55faf9a 100644 --- a/types/msg.go +++ b/types/msg.go @@ -361,7 +361,7 @@ type EurekaMsg struct { // Sends an IBC packet with given payloads over the existing channel. type EurekaSendPacketMsg struct { ChannelID string `json:"channel_id"` - Data []EurekaPayload `json:"data"` + Payloads []EurekaPayload `json:"payloads"` Timeout uint64 `json:"timeout,string,omitempty"` } From 6cda85eca6a5008c133f1817c279630e55570125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wo=C5=BAniak?= Date: Fri, 24 Jan 2025 15:28:14 +0100 Subject: [PATCH 4/5] Review changes --- types/eureka.go | 4 ++-- types/msg_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/types/eureka.go b/types/eureka.go index befbeee99..a3d919e42 100644 --- a/types/eureka.go +++ b/types/eureka.go @@ -1,8 +1,8 @@ package types -// EurekaPayload defines a single packet sent in the EurekaSendPacketMsg +// EurekaPayload defines a single packet sent in the EurekaSendPacketMsg. // -// Payload value should be encoded in a format defined by the channel version, +// Payload value should be encoded using the method specified in the Encoding field, // and the module on the other side should know how to parse this. type EurekaPayload struct { // The port id on the chain where the packet is sent to (external chain). diff --git a/types/msg_test.go b/types/msg_test.go index f56915928..e4a3d723a 100644 --- a/types/msg_test.go +++ b/types/msg_test.go @@ -161,3 +161,13 @@ func TestMsgFundCommunityPoolSerialization(t *testing.T) { require.Equal(t, Array[Coin]{{"adenom", "300"}, {"bdenom", "400"}}, msg.FundCommunityPool.Amount) } + +func TestMsgEurekaSendPacketSerialization(t *testing.T) { + document := []byte(`{"send_packet":{"amount":[{"amount":"300","denom":"adenom"},{"amount":"400","denom":"bdenom"}]}}`) + + var msg EurekaMsg + err := json.Unmarshal(document, &msg) + require.NoError(t, err) + + require.Equal(t, Array[Coin]{{"adenom", "300"}, {"bdenom", "400"}}, msg.FundCommunityPool.Amount) +} From b6d0a44386d70efdf29cda59f6ae7fc2e5101f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wo=C5=BAniak?= Date: Fri, 24 Jan 2025 16:30:11 +0100 Subject: [PATCH 5/5] Check EurekaMsg serialization --- types/msg.go | 2 +- types/msg_test.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/types/msg.go b/types/msg.go index 6c55faf9a..d7f616844 100644 --- a/types/msg.go +++ b/types/msg.go @@ -355,7 +355,7 @@ type WasmMsg struct { // These are messages in the IBC lifecycle using the new Eureka approach. Only usable by IBC-enabled contracts type EurekaMsg struct { - SendPacket *EurekaSendPacketMsg `json:"execute,omitempty"` + SendPacket *EurekaSendPacketMsg `json:"send_packet,omitempty"` } // Sends an IBC packet with given payloads over the existing channel. diff --git a/types/msg_test.go b/types/msg_test.go index e4a3d723a..4a1b409e0 100644 --- a/types/msg_test.go +++ b/types/msg_test.go @@ -163,11 +163,18 @@ func TestMsgFundCommunityPoolSerialization(t *testing.T) { } func TestMsgEurekaSendPacketSerialization(t *testing.T) { - document := []byte(`{"send_packet":{"amount":[{"amount":"300","denom":"adenom"},{"amount":"400","denom":"bdenom"}]}}`) + document := []byte(`{"send_packet":{"channel_id":"channel-432", "payloads": [{"destination_port": "wasm.123", "version": "random_version", "encoding": "json", "value": ""}], "timeout": "0"}}`) var msg EurekaMsg err := json.Unmarshal(document, &msg) require.NoError(t, err) - require.Equal(t, Array[Coin]{{"adenom", "300"}, {"bdenom", "400"}}, msg.FundCommunityPool.Amount) + require.Equal(t, "channel-432", msg.SendPacket.ChannelID) + require.Equal(t, []EurekaPayload{{ + DestinationPort: "wasm.123", + Version: "random_version", + Encoding: "json", + Value: []byte(""), + }}, msg.SendPacket.Payloads) + require.Equal(t, uint64(0), msg.SendPacket.Timeout) }