-
Notifications
You must be signed in to change notification settings - Fork 330
/
hooks.go
77 lines (65 loc) · 2.62 KB
/
hooks.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
66
67
68
69
70
71
72
73
74
75
76
77
package keeper
import (
"github.com/dymensionxyz/dymension/v3/x/delayedack/types"
sdk "github.com/cosmos/cosmos-sdk/types"
commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"
eibctypes "github.com/dymensionxyz/dymension/v3/x/eibc/types"
osmoutils "github.com/osmosis-labs/osmosis/v15/osmoutils"
epochstypes "github.com/osmosis-labs/osmosis/v15/x/epochs/types"
)
/* -------------------------------------------------------------------------- */
/* eIBC Hooks */
/* -------------------------------------------------------------------------- */
var _ eibctypes.EIBCHooks = eibcHooks{}
type eibcHooks struct {
eibctypes.BaseEIBCHook
Keeper
}
func (k Keeper) GetEIBCHooks() eibctypes.EIBCHooks {
return eibcHooks{
BaseEIBCHook: eibctypes.BaseEIBCHook{},
Keeper: k,
}
}
// AfterDemandOrderFulfilled is called every time a demand order is fulfilled.
// Once it is fulfilled the underlying packet recipient should be updated to the fullfiller.
func (k eibcHooks) AfterDemandOrderFulfilled(ctx sdk.Context, demandOrder *eibctypes.DemandOrder, fulfillerAddress string) error {
err := k.UpdateRollappPacketTransferAddress(ctx, demandOrder.TrackingPacketKey, fulfillerAddress)
if err != nil {
return err
}
return nil
}
/* -------------------------------------------------------------------------- */
/* epoch hooks */
/* -------------------------------------------------------------------------- */
var _ epochstypes.EpochHooks = epochHooks{}
type epochHooks struct {
Keeper
}
func (k Keeper) GetEpochHooks() epochstypes.EpochHooks {
return epochHooks{
Keeper: k,
}
}
// BeforeEpochStart is the epoch start hook.
func (e epochHooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) error {
return nil
}
// AfterEpochEnd is the epoch end hook.
// We want to clean up the demand orders that are with underlying packet status which are finalized.
func (e epochHooks) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) error {
if epochIdentifier != e.GetParams(ctx).EpochIdentifier {
return nil
}
// Get all rollapp packets with status != PENDING and delete them
// tech debt: this slice can potentially take up a lot of memory
toDeletePackets := e.ListRollappPackets(ctx, types.ByStatus(commontypes.Status_FINALIZED, commontypes.Status_REVERTED))
for _, packet := range toDeletePackets {
packetCopy := packet
_ = osmoutils.ApplyFuncIfNoError(ctx, func(ctx sdk.Context) error {
return e.deleteRollappPacket(ctx, &packetCopy)
})
}
return nil
}