-
Notifications
You must be signed in to change notification settings - Fork 204
/
abci.go
49 lines (42 loc) · 1.51 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
42
43
44
45
46
47
48
49
package keeper
import (
"encoding/hex"
"fmt"
"time"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/Stride-Labs/stride/v6/x/interchainquery/types"
)
// EndBlocker of interchainquery module
func (k Keeper) EndBlocker(ctx sdk.Context) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)
_ = k.Logger(ctx)
events := sdk.Events{}
// emit events for periodic queries
k.IterateQueries(ctx, func(_ int64, query types.Query) (stop bool) {
if !query.RequestSent {
k.Logger(ctx).Info(fmt.Sprintf("Interchainquery event emitted %s", query.Id))
// QUESTION: Do we need to emit this event twice?
event := sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeyAction, types.AttributeValueQuery),
sdk.NewAttribute(types.AttributeKeyQueryId, query.Id),
sdk.NewAttribute(types.AttributeKeyChainId, query.ChainId),
sdk.NewAttribute(types.AttributeKeyConnectionId, query.ConnectionId),
sdk.NewAttribute(types.AttributeKeyType, query.QueryType),
sdk.NewAttribute(types.AttributeKeyHeight, "0"),
sdk.NewAttribute(types.AttributeKeyRequest, hex.EncodeToString(query.Request)),
)
events = append(events, event)
event.Type = "query_request"
events = append(events, event)
query.RequestSent = true
k.SetQuery(ctx, query)
}
return false
})
if len(events) > 0 {
ctx.EventManager().EmitEvents(events)
}
}