Change IBCContractKeeper interface, code builds

This commit is contained in:
Ethan Frey
2021-07-28 22:11:27 +02:00
parent 0dbcef0d55
commit cf854947e9
3 changed files with 63 additions and 79 deletions

View File

@@ -43,13 +43,18 @@ func (i IBCHandler) OnChanOpenInit(
return sdkerrors.Wrapf(err, "contract port id")
}
err = i.keeper.OnOpenChannel(ctx, contractAddr, wasmvmtypes.IBCChannel{
Endpoint: wasmvmtypes.IBCEndpoint{PortID: portID, ChannelID: channelID},
CounterpartyEndpoint: wasmvmtypes.IBCEndpoint{PortID: counterParty.PortId, ChannelID: counterParty.ChannelId},
Order: order.String(),
Version: version,
ConnectionID: connectionHops[0], // At the moment this list must be of length 1. In the future multi-hop channels may be supported.
}, "")
msg := wasmvmtypes.IBCChannelOpenMsg{
OpenInit: &wasmvmtypes.IBCOpenInit{
Channel: wasmvmtypes.IBCChannel{
Endpoint: wasmvmtypes.IBCEndpoint{PortID: portID, ChannelID: channelID},
CounterpartyEndpoint: wasmvmtypes.IBCEndpoint{PortID: counterParty.PortId, ChannelID: counterParty.ChannelId},
Order: order.String(),
Version: version,
ConnectionID: connectionHops[0], // At the moment this list must be of length 1. In the future multi-hop channels may be supported.
},
},
}
err = i.keeper.OnOpenChannel(ctx, contractAddr, msg)
if err != nil {
return err
}
@@ -80,13 +85,20 @@ func (i IBCHandler) OnChanOpenTry(
return sdkerrors.Wrapf(err, "contract port id")
}
err = i.keeper.OnOpenChannel(ctx, contractAddr, wasmvmtypes.IBCChannel{
Endpoint: wasmvmtypes.IBCEndpoint{PortID: portID, ChannelID: channelID},
CounterpartyEndpoint: wasmvmtypes.IBCEndpoint{PortID: counterParty.PortId, ChannelID: counterParty.ChannelId},
Order: order.String(),
Version: version,
ConnectionID: connectionHops[0], // At the moment this list must be of length 1. In the future multi-hop channels may be supported.
}, counterpartyVersion)
msg := wasmvmtypes.IBCChannelOpenMsg{
OpenTry: &wasmvmtypes.IBCOpenTry{
Channel: wasmvmtypes.IBCChannel{
Endpoint: wasmvmtypes.IBCEndpoint{PortID: portID, ChannelID: channelID},
CounterpartyEndpoint: wasmvmtypes.IBCEndpoint{PortID: counterParty.PortId, ChannelID: counterParty.ChannelId},
Order: order.String(),
Version: version,
ConnectionID: connectionHops[0], // At the moment this list must be of length 1. In the future multi-hop channels may be supported.
},
CounterpartyVersion: counterpartyVersion,
},
}
err = i.keeper.OnOpenChannel(ctx, contractAddr, msg)
if err != nil {
return err
}
@@ -117,7 +129,13 @@ func (i IBCHandler) OnChanOpenAck(
if !ok {
return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}
return i.keeper.OnConnectChannel(ctx, contractAddr, toWasmVMChannel(portID, channelID, channelInfo), counterpartyVersion)
msg := wasmvmtypes.IBCChannelConnectMsg{
OpenAck: &wasmvmtypes.IBCOpenAck{
Channel: toWasmVMChannel(portID, channelID, channelInfo),
CounterpartyVersion: counterpartyVersion,
},
}
return i.keeper.OnConnectChannel(ctx, contractAddr, msg)
}
// OnChanOpenConfirm implements the IBCModule interface
@@ -130,7 +148,12 @@ func (i IBCHandler) OnChanOpenConfirm(ctx sdk.Context, portID, channelID string)
if !ok {
return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}
return i.keeper.OnConnectChannel(ctx, contractAddr, toWasmVMChannel(portID, channelID, channelInfo), "")
msg := wasmvmtypes.IBCChannelConnectMsg{
OpenConfirm: &wasmvmtypes.IBCOpenConfirm{
Channel: toWasmVMChannel(portID, channelID, channelInfo),
},
}
return i.keeper.OnConnectChannel(ctx, contractAddr, msg)
}
// OnChanCloseInit implements the IBCModule interface
@@ -144,7 +167,10 @@ func (i IBCHandler) OnChanCloseInit(ctx sdk.Context, portID, channelID string) e
return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}
err = i.keeper.OnCloseChannel(ctx, contractAddr, toWasmVMChannel(portID, channelID, channelInfo), false)
msg := wasmvmtypes.IBCChannelCloseMsg{
CloseInit: &wasmvmtypes.IBCCloseInit{Channel: toWasmVMChannel(portID, channelID, channelInfo)},
}
err = i.keeper.OnCloseChannel(ctx, contractAddr, msg)
if err != nil {
return err
}
@@ -165,7 +191,10 @@ func (i IBCHandler) OnChanCloseConfirm(ctx sdk.Context, portID, channelID string
return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}
err = i.keeper.OnCloseChannel(ctx, contractAddr, toWasmVMChannel(portID, channelID, channelInfo), true)
msg := wasmvmtypes.IBCChannelCloseMsg{
CloseConfirm: &wasmvmtypes.IBCCloseConfirm{Channel: toWasmVMChannel(portID, channelID, channelInfo)},
}
err = i.keeper.OnCloseChannel(ctx, contractAddr, msg)
if err != nil {
return err
}
@@ -193,7 +222,8 @@ func (i IBCHandler) OnRecvPacket(
if err != nil {
return nil, nil, sdkerrors.Wrapf(err, "contract port id")
}
ack, err := i.keeper.OnRecvPacket(ctx, contractAddr, newIBCPacket(packet))
msg := wasmvmtypes.IBCPacketReceiveMsg{Packet: newIBCPacket(packet)}
ack, err := i.keeper.OnRecvPacket(ctx, contractAddr, msg)
if err != nil {
return nil, nil, err
}
@@ -230,7 +260,8 @@ func (i IBCHandler) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet)
if err != nil {
return nil, sdkerrors.Wrapf(err, "contract port id")
}
err = i.keeper.OnTimeoutPacket(ctx, contractAddr, newIBCPacket(packet))
msg := wasmvmtypes.IBCPacketTimeoutMsg{Packet: newIBCPacket(packet)}
err = i.keeper.OnTimeoutPacket(ctx, contractAddr, msg)
if err != nil {
return nil, err
}