-
Notifications
You must be signed in to change notification settings - Fork 687
/
Copy pathibc_module.go
65 lines (55 loc) · 1.9 KB
/
ibc_module.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package mock
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
channeltypesv2 "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"
"github.com/cosmos/ibc-go/v9/modules/core/api"
mockv1 "github.com/cosmos/ibc-go/v9/testing/mock"
)
var _ api.IBCModule = (*IBCModule)(nil)
const (
// ModuleNameA is a name that can be used for the first mock application.
ModuleNameA = ModuleName + "A"
// ModuleNameB is a name that can be used for the second mock application.
ModuleNameB = ModuleName + "B"
)
// IBCModule is a mock implementation of the IBCModule interface.
// which delegates calls to the underlying IBCApp.
type IBCModule struct {
IBCApp *IBCApp
}
// NewIBCModule creates a new IBCModule with an underlying mock IBC application.
func NewIBCModule() IBCModule {
return IBCModule{
IBCApp: &IBCApp{},
}
}
func (im IBCModule) OnSendPacket(ctx context.Context, sourceID string, destinationID string, sequence uint64, data channeltypesv2.PacketData, signer sdk.AccAddress) error {
if im.IBCApp.OnSendPacket != nil {
return im.IBCApp.OnSendPacket(ctx, sourceID, destinationID, sequence, data, signer)
}
return nil
}
func (im IBCModule) OnRecvPacket(ctx context.Context, sourceID string, destinationID string, data channeltypesv2.PacketData, relayer sdk.AccAddress) channeltypesv2.RecvPacketResult {
if im.IBCApp.OnRecvPacket != nil {
return im.IBCApp.OnRecvPacket(ctx, sourceID, destinationID, data, relayer)
}
return channeltypesv2.RecvPacketResult{
Status: channeltypesv2.PacketStatus_Success,
Acknowledgement: mockv1.MockPacketData,
}
}
//
// func (im IBCModule) OnAcknowledgementPacket() error {
// if im.IBCApp.OnAcknowledgementPacket != nil {
// return im.IBCApp.OnAcknowledgementPacket(...)
// }
// return nil
// }
//
// func (im IBCModule) OnTimeoutPacket() error {
// if im.IBCApp.OnTimeoutPacket != nil {
// return im.IBCApp.OnTimeoutPacket(...)
// }
// return nil
// }