-
Notifications
You must be signed in to change notification settings - Fork 54
/
hooks.go
81 lines (68 loc) · 2.15 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
78
79
80
81
package keeper
import (
"time"
"github.com/bandprotocol/bandchain-packet/obi"
"github.com/bandprotocol/bandchain-packet/packet"
sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
epochstypes "github.com/elys-network/elys/x/epochs/types"
"github.com/elys-network/elys/x/oracle/types"
)
func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) {
params := k.GetParams(ctx)
if epochIdentifier == params.BandEpoch {
if params.BandChannelSource == "" {
return
}
sourcePort := types.PortID
channelCap, ok := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(sourcePort, params.BandChannelSource))
if !ok {
return
}
assetInfos := k.GetAllAssetInfo(ctx)
symbols := []string{}
for _, assetInfo := range assetInfos {
if assetInfo.BandTicker != "" {
symbols = append(symbols, assetInfo.BandTicker)
}
}
if len(symbols) == 0 {
return
}
encodedCalldata := obi.MustEncode(types.BandPriceCallData{
Symbols: symbols,
Multiplier: params.Multiplier,
})
packetData := packet.NewOracleRequestPacketData(
params.ClientID,
params.OracleScriptID,
encodedCalldata,
params.AskCount,
params.MinCount,
params.FeeLimit,
params.PrepareGas,
params.ExecuteGas,
)
_, err := k.channelKeeper.SendPacket(ctx, channelCap, sourcePort, params.BandChannelSource, clienttypes.NewHeight(0, 0), uint64(ctx.BlockTime().UnixNano()+int64(10*time.Minute)), packetData.GetBytes())
if err != nil {
return
}
}
}
func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) {}
// Hooks wrapper struct
type Hooks struct {
k Keeper
}
var _ epochstypes.EpochHooks = Hooks{}
func (k Keeper) Hooks() Hooks {
return Hooks{k}
}
// epochs hooks
func (h Hooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) {
h.k.BeforeEpochStart(ctx, epochIdentifier, epochNumber)
}
func (h Hooks) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) {
h.k.AfterEpochEnd(ctx, epochIdentifier, epochNumber)
}