Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add new EurekaMsg #617

Merged
merged 5 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions types/eureka.go
Original file line number Diff line number Diff line change
@@ -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"`
}
15 changes: 15 additions & 0 deletions types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
chipshort marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down
17 changes: 17 additions & 0 deletions types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Loading