Skip to content

Commit 7b1b5be

Browse files
authored
Merge pull request #617 from CosmWasm/eureka/send-packet
Add new EurekaMsg
2 parents 566c8a1 + b6d0a44 commit 7b1b5be

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

types/eureka.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package types
2+
3+
// EurekaPayload defines a single packet sent in the EurekaSendPacketMsg.
4+
//
5+
// Payload value should be encoded using the method specified in the Encoding field,
6+
// and the module on the other side should know how to parse this.
7+
type EurekaPayload struct {
8+
// The port id on the chain where the packet is sent to (external chain).
9+
DestinationPort string `json:"destination_port"`
10+
// Version of the receiving contract.
11+
Version string `json:"version"`
12+
// Encoding used to serialize the Value.
13+
Encoding string `json:"encoding"`
14+
// Encoded payload data
15+
Value []byte `json:"value"`
16+
}

types/msg.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type CosmosMsg struct {
6060
Staking *StakingMsg `json:"staking,omitempty"`
6161
Any *AnyMsg `json:"any,omitempty"`
6262
Wasm *WasmMsg `json:"wasm,omitempty"`
63+
Eureka *EurekaMsg `json:"eureka,omitempty"`
6364
}
6465

6566
func (m *CosmosMsg) UnmarshalJSON(data []byte) error {
@@ -74,6 +75,7 @@ func (m *CosmosMsg) UnmarshalJSON(data []byte) error {
7475
Any *AnyMsg `json:"any,omitempty"`
7576
Wasm *WasmMsg `json:"wasm,omitempty"`
7677
Stargate *AnyMsg `json:"stargate,omitempty"`
78+
Eureka *EurekaMsg `json:"eureka,omitempty"`
7779
}
7880
var tmp InternalCosmosMsg
7981
err := json.Unmarshal(data, &tmp)
@@ -97,6 +99,7 @@ func (m *CosmosMsg) UnmarshalJSON(data []byte) error {
9799
Staking: tmp.Staking,
98100
Any: tmp.Any,
99101
Wasm: tmp.Wasm,
102+
Eureka: tmp.Eureka,
100103
}
101104
return nil
102105
}
@@ -350,6 +353,18 @@ type WasmMsg struct {
350353
ClearAdmin *ClearAdminMsg `json:"clear_admin,omitempty"`
351354
}
352355

356+
// These are messages in the IBC lifecycle using the new Eureka approach. Only usable by IBC-enabled contracts
357+
type EurekaMsg struct {
358+
SendPacket *EurekaSendPacketMsg `json:"send_packet,omitempty"`
359+
}
360+
361+
// Sends an IBC packet with given payloads over the existing channel.
362+
type EurekaSendPacketMsg struct {
363+
ChannelID string `json:"channel_id"`
364+
Payloads []EurekaPayload `json:"payloads"`
365+
Timeout uint64 `json:"timeout,string,omitempty"`
366+
}
367+
353368
// ExecuteMsg is used to call another defined contract on this chain.
354369
// The calling contract requires the callee to be defined beforehand,
355370
// and the address should have been defined in initialization.

types/msg_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,20 @@ func TestMsgFundCommunityPoolSerialization(t *testing.T) {
161161

162162
require.Equal(t, Array[Coin]{{"adenom", "300"}, {"bdenom", "400"}}, msg.FundCommunityPool.Amount)
163163
}
164+
165+
func TestMsgEurekaSendPacketSerialization(t *testing.T) {
166+
document := []byte(`{"send_packet":{"channel_id":"channel-432", "payloads": [{"destination_port": "wasm.123", "version": "random_version", "encoding": "json", "value": ""}], "timeout": "0"}}`)
167+
168+
var msg EurekaMsg
169+
err := json.Unmarshal(document, &msg)
170+
require.NoError(t, err)
171+
172+
require.Equal(t, "channel-432", msg.SendPacket.ChannelID)
173+
require.Equal(t, []EurekaPayload{{
174+
DestinationPort: "wasm.123",
175+
Version: "random_version",
176+
Encoding: "json",
177+
Value: []byte(""),
178+
}}, msg.SendPacket.Payloads)
179+
require.Equal(t, uint64(0), msg.SendPacket.Timeout)
180+
}

0 commit comments

Comments
 (0)