Skip to content

Commit

Permalink
feat: pass blockHeight and blockTime from all IBC events
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed May 26, 2020
1 parent 2297a08 commit 79bd316
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/mailbox-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function setup(syscall, state, helpers, endowments) {

function inboundCallback(hPeer, hMessages, hAck) {
const peer = `${hPeer}`;
if (!inboundCallback) {
if (!deliverInboundMessages) {
throw new Error(
`mailbox.inboundCallback(${peer}) called before handler was registered`,
);
Expand Down
108 changes: 72 additions & 36 deletions packages/cosmic-swingset/x/swingset/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ type channelOpenInitEvent struct {
ChannelID string `json:"channelID"`
Counterparty channeltypes.Counterparty `json:"counterparty"`
Version string `json:"version"`
BlockHeight int64 `json:"blockHeight"`
BlockTime int64 `json:"blockTime"`
}

// Implement IBCModule callbacks
Expand All @@ -203,6 +205,8 @@ func (am AppModule) OnChanOpenInit(
ChannelID: channelID,
Counterparty: counterparty,
Version: version,
BlockHeight: ctx.BlockHeight(),
BlockTime: ctx.BlockTime().Unix(),
}

bytes, err := json.Marshal(&event)
Expand Down Expand Up @@ -233,6 +237,8 @@ type channelOpenTryEvent struct {
Counterparty channeltypes.Counterparty `json:"counterparty"`
Version string `json:"version"`
CounterpartyVersion string `json:"counterpartyVersion"`
BlockHeight int64 `json:"blockHeight"`
BlockTime int64 `json:"blockTime"`
}

func (am AppModule) OnChanOpenTry(
Expand All @@ -257,6 +263,8 @@ func (am AppModule) OnChanOpenTry(
Counterparty: counterparty,
Version: version,
CounterpartyVersion: counterpartyVersion,
BlockHeight: ctx.BlockHeight(),
BlockTime: ctx.BlockTime().Unix(),
}

bytes, err := json.Marshal(&event)
Expand All @@ -283,6 +291,8 @@ type channelOpenAckEvent struct {
PortID string `json:"portID"`
ChannelID string `json:"channelID"`
CounterpartyVersion string `json:"counterpartyVersion"`
BlockHeight int64 `json:"blockHeight"`
BlockTime int64 `json:"blockTime"`
}

func (am AppModule) OnChanOpenAck(
Expand All @@ -298,6 +308,8 @@ func (am AppModule) OnChanOpenAck(
PortID: portID,
ChannelID: channelID,
CounterpartyVersion: counterpartyVersion,
BlockHeight: ctx.BlockHeight(),
BlockTime: ctx.BlockTime().Unix(),
}

bytes, err := json.Marshal(&event)
Expand All @@ -310,10 +322,12 @@ func (am AppModule) OnChanOpenAck(
}

type channelOpenConfirmEvent struct {
Type string `json:"type"` // IBC
Event string `json:"event"` // channelOpenConfirm
PortID string `json:"portID"`
ChannelID string `json:"channelID"`
Type string `json:"type"` // IBC
Event string `json:"event"` // channelOpenConfirm
PortID string `json:"portID"`
ChannelID string `json:"channelID"`
BlockHeight int64 `json:"blockHeight"`
BlockTime int64 `json:"blockTime"`
}

func (am AppModule) OnChanOpenConfirm(
Expand All @@ -322,10 +336,12 @@ func (am AppModule) OnChanOpenConfirm(
channelID string,
) error {
event := channelOpenConfirmEvent{
Type: "IBC_EVENT",
Event: "channelOpenConfirm",
PortID: portID,
ChannelID: channelID,
Type: "IBC_EVENT",
Event: "channelOpenConfirm",
PortID: portID,
ChannelID: channelID,
BlockHeight: ctx.BlockHeight(),
BlockTime: ctx.BlockTime().Unix(),
}

bytes, err := json.Marshal(&event)
Expand All @@ -339,10 +355,12 @@ func (am AppModule) OnChanOpenConfirm(
}

type channelCloseInitEvent struct {
Type string `json:"type"` // IBC
Event string `json:"event"` // channelCloseInit
PortID string `json:"portID"`
ChannelID string `json:"channelID"`
Type string `json:"type"` // IBC
Event string `json:"event"` // channelCloseInit
PortID string `json:"portID"`
ChannelID string `json:"channelID"`
BlockHeight int64 `json:"blockHeight"`
BlockTime int64 `json:"blockTime"`
}

func (am AppModule) OnChanCloseInit(
Expand All @@ -351,10 +369,12 @@ func (am AppModule) OnChanCloseInit(
channelID string,
) error {
event := channelCloseInitEvent{
Type: "IBC_EVENT",
Event: "channelCloseInit",
PortID: portID,
ChannelID: channelID,
Type: "IBC_EVENT",
Event: "channelCloseInit",
PortID: portID,
ChannelID: channelID,
BlockHeight: ctx.BlockHeight(),
BlockTime: ctx.BlockTime().Unix(),
}

bytes, err := json.Marshal(&event)
Expand All @@ -367,10 +387,12 @@ func (am AppModule) OnChanCloseInit(
}

type channelCloseConfirmEvent struct {
Type string `json:"type"` // IBC
Event string `json:"event"` // channelCloseConfirm
PortID string `json:"portID"`
ChannelID string `json:"channelID"`
Type string `json:"type"` // IBC
Event string `json:"event"` // channelCloseConfirm
PortID string `json:"portID"`
ChannelID string `json:"channelID"`
BlockHeight int64 `json:"blockHeight"`
BlockTime int64 `json:"blockTime"`
}

func (am AppModule) OnChanCloseConfirm(
Expand All @@ -379,10 +401,12 @@ func (am AppModule) OnChanCloseConfirm(
channelID string,
) error {
event := channelCloseConfirmEvent{
Type: "IBC_EVENT",
Event: "channelCloseConfirm",
PortID: portID,
ChannelID: channelID,
Type: "IBC_EVENT",
Event: "channelCloseConfirm",
PortID: portID,
ChannelID: channelID,
BlockHeight: ctx.BlockHeight(),
BlockTime: ctx.BlockTime().Unix(),
}

bytes, err := json.Marshal(&event)
Expand All @@ -395,9 +419,11 @@ func (am AppModule) OnChanCloseConfirm(
}

type receivePacketEvent struct {
Type string `json:"type"` // IBC
Event string `json:"event"` // receivePacket
Packet channeltypes.Packet `json:"packet"`
Type string `json:"type"` // IBC
Event string `json:"event"` // receivePacket
Packet channeltypes.Packet `json:"packet"`
BlockHeight int64 `json:"blockHeight"`
BlockTime int64 `json:"blockTime"`
}

func (am AppModule) OnRecvPacket(
Expand All @@ -406,9 +432,11 @@ func (am AppModule) OnRecvPacket(
) (*sdk.Result, error) {

event := receivePacketEvent{
Type: "IBC_EVENT",
Event: "receivePacket",
Packet: packet,
Type: "IBC_EVENT",
Event: "receivePacket",
Packet: packet,
BlockHeight: ctx.BlockHeight(),
BlockTime: ctx.BlockTime().Unix(),
}

bytes, err := json.Marshal(&event)
Expand All @@ -431,6 +459,8 @@ type acknowledgementPacketEvent struct {
Event string `json:"event"` // acknowledgementPacket
Packet channeltypes.Packet `json:"packet"`
Acknowledgement []byte `json:"acknowledgement"`
BlockHeight int64 `json:"blockHeight"`
BlockTime int64 `json:"blockTime"`
}

func (am AppModule) OnAcknowledgementPacket(
Expand All @@ -444,6 +474,8 @@ func (am AppModule) OnAcknowledgementPacket(
Event: "acknowledgementPacket",
Packet: packet,
Acknowledgement: acknowledgement,
BlockHeight: ctx.BlockHeight(),
BlockTime: ctx.BlockTime().Unix(),
}

bytes, err := json.Marshal(&event)
Expand All @@ -462,9 +494,11 @@ func (am AppModule) OnAcknowledgementPacket(
}

type timeoutPacketEvent struct {
Type string `json:"type"` // IBC
Event string `json:"event"` // timeoutPacket
Packet channeltypes.Packet `json:"packet"`
Type string `json:"type"` // IBC
Event string `json:"event"` // timeoutPacket
Packet channeltypes.Packet `json:"packet"`
BlockHeight int64 `json:"blockHeight"`
BlockTime int64 `json:"blockTime"`
}

func (am AppModule) OnTimeoutPacket(
Expand All @@ -473,9 +507,11 @@ func (am AppModule) OnTimeoutPacket(
) (*sdk.Result, error) {

event := timeoutPacketEvent{
Type: "IBC_EVENT",
Event: "timeoutPacket",
Packet: packet,
Type: "IBC_EVENT",
Event: "timeoutPacket",
Packet: packet,
BlockHeight: ctx.BlockHeight(),
BlockTime: ctx.BlockTime().Unix(),
}

bytes, err := json.Marshal(&event)
Expand Down

0 comments on commit 79bd316

Please sign in to comment.