-
Notifications
You must be signed in to change notification settings - Fork 1
/
end_block_cancel_orders.go
46 lines (41 loc) · 1.78 KB
/
end_block_cancel_orders.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
package abci
import (
"context"
"fmt"
"github.com/Timwood0x10/sei-chain/x/dex/keeper/utils"
"github.com/Timwood0x10/sei-chain/x/dex/types"
dexutils "github.com/Timwood0x10/sei-chain/x/dex/utils"
sdk "github.com/cosmos/cosmos-sdk/types"
"go.opentelemetry.io/otel/attribute"
otrace "go.opentelemetry.io/otel/trace"
)
func (w KeeperWrapper) HandleEBCancelOrders(ctx context.Context, sdkCtx sdk.Context, tracer *otrace.Tracer, contractAddr string, registeredPairs []types.Pair) error {
_, span := (*tracer).Start(ctx, "SudoCancelOrders")
span.SetAttributes(attribute.String("contractAddr", contractAddr))
typedContractAddr := types.ContractAddress(contractAddr)
msg := w.getCancelSudoMsg(sdkCtx, typedContractAddr, registeredPairs)
if len(msg.OrderCancellations.IdsToCancel) == 0 {
return nil
}
userProvidedGas := w.GetParams(sdkCtx).DefaultGasPerCancel * uint64(len(msg.OrderCancellations.IdsToCancel))
if _, err := utils.CallContractSudo(sdkCtx, w.Keeper, contractAddr, msg, userProvidedGas); err != nil {
sdkCtx.Logger().Error(fmt.Sprintf("Error during cancellation: %s", err.Error()))
return err
}
span.End()
return nil
}
func (w KeeperWrapper) getCancelSudoMsg(sdkCtx sdk.Context, typedContractAddr types.ContractAddress, registeredPairs []types.Pair) types.SudoOrderCancellationMsg {
idsToCancel := []uint64{}
for _, pair := range registeredPairs {
typedPairStr := types.GetPairString(&pair) //nolint:gosec // THIS MAY BE CAUSE FOR CONCERN AND WE MIGHT WANT TO REFACTOR.
for _, cancel := range dexutils.GetMemState(sdkCtx.Context()).GetBlockCancels(sdkCtx, typedContractAddr, typedPairStr).Get() {
idsToCancel = append(idsToCancel, cancel.Id)
}
}
return types.SudoOrderCancellationMsg{
OrderCancellations: types.OrderCancellationMsgDetails{
IdsToCancel: idsToCancel,
},
}
}