/
abci.go
41 lines (31 loc) · 1.04 KB
/
abci.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
package htlc
import (
"fmt"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/furynet/furymod/modules/htlc/keeper"
"github.com/furynet/furymod/modules/htlc/types"
)
// BeginBlocker handles block beginning logic for HTLC
func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
ctx = ctx.WithLogger(ctx.Logger().With("handler", "beginBlock").With("module", "furymod/htlc"))
currentBlockHeight := uint64(ctx.BlockHeight())
k.IterateHTLCExpiredQueueByHeight(
ctx, currentBlockHeight,
func(id tmbytes.HexBytes, h types.HTLC) (stop bool) {
// refund HTLC
_ = k.RefundHTLC(ctx, h, id)
// delete from the expiration queue
k.DeleteHTLCFromExpiredQueue(ctx, currentBlockHeight, id)
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeRefundHTLC,
sdk.NewAttribute(types.AttributeKeyID, id.String()),
),
})
ctx.Logger().Info(fmt.Sprintf("HTLC [%s] is refunded", id.String()))
return false
},
)
k.UpdateTimeBasedSupplyLimits(ctx)
}