diff --git a/types/eureka.go b/types/eureka.go new file mode 100644 index 000000000..a3d919e42 --- /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 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). + 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..d7f616844 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:"send_packet,omitempty"` +} + +// Sends an IBC packet with given payloads over the existing channel. +type EurekaSendPacketMsg struct { + ChannelID string `json:"channel_id"` + Payloads []EurekaPayload `json:"payloads"` + Timeout uint64 `json:"timeout,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. diff --git a/types/msg_test.go b/types/msg_test.go index f56915928..4a1b409e0 100644 --- a/types/msg_test.go +++ b/types/msg_test.go @@ -161,3 +161,20 @@ 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":{"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, "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) +}