diff --git a/internal/worker/worker.go b/internal/worker/worker.go index c26a6ea..6fb153f 100644 --- a/internal/worker/worker.go +++ b/internal/worker/worker.go @@ -119,7 +119,8 @@ func (w *Worker) processMessages(m []evmlistenerclient.Message) error { if err := w.s.Delete(deleteBlocks); err != nil { return err } - if err := w.s.Insert(w.priceFiller.FullFillTradeLogs(insertOrders)); err != nil { + w.priceFiller.FullFillTradeLogs(insertOrders) + if err := w.s.Insert(insertOrders); err != nil { return err } for _, log := range insertOrders { @@ -168,7 +169,8 @@ func (w *Worker) retryParseLog() error { insertOrders = append(insertOrders, order) } - if err := w.s.Insert(w.priceFiller.FullFillTradeLogs(insertOrders)); err != nil { + w.priceFiller.FullFillTradeLogs(insertOrders) + if err := w.s.Insert(insertOrders); err != nil { return err } for _, log := range insertOrders { diff --git a/pkg/pricefiller/price_fillter.go b/pkg/pricefiller/price_fillter.go index e897d72..cae0db4 100644 --- a/pkg/pricefiller/price_fillter.go +++ b/pkg/pricefiller/price_fillter.go @@ -130,13 +130,13 @@ func (p *PriceFiller) runBackFillTradelogPriceRoutine() { continue } - filledTrades := p.FullFillTradeLogs(tradeLogs) - if err := p.s.Insert(filledTrades); err != nil { + p.FullFillTradeLogs(tradeLogs) + if err := p.s.Insert(tradeLogs); err != nil { p.l.Errorw("Failed to insert tradeLogs", "err", err) continue } - p.l.Infow("backfill tradelog price successfully", "trades", filledTrades) + p.l.Infow("backfill tradelog price successfully", "trades", tradeLogs) } } @@ -193,20 +193,17 @@ func (p *PriceFiller) getPriceAndAmountUsd(address, rawAmt string, at int64) (fl return 0, 0, nil } -func (p *PriceFiller) FullFillTradeLogs(tradeLogs []storage.TradeLog) []storage.TradeLog { - resp := make([]storage.TradeLog, len(tradeLogs)) +func (p *PriceFiller) FullFillTradeLogs(tradeLogs []storage.TradeLog) { for idx, tradeLog := range tradeLogs { // for the safety, sleep a bit to avoid Binance rate limit time.Sleep(10 * time.Millisecond) filledTradeLog, err := p.fullFillTradeLog(tradeLog) if err != nil { p.l.Errorw("Failed to fullFillTradeLog", "err", err, "tradeLog", tradeLog) - resp[idx] = tradeLog continue } - resp[idx] = filledTradeLog + tradeLogs[idx] = filledTradeLog } - return resp } func (p *PriceFiller) getDecimals(address string) (int64, error) { diff --git a/pkg/pricefiller/price_fillter_test.go b/pkg/pricefiller/price_fillter_test.go index 9f782c2..59016a2 100644 --- a/pkg/pricefiller/price_fillter_test.go +++ b/pkg/pricefiller/price_fillter_test.go @@ -17,7 +17,7 @@ func TestFillPrice(t *testing.T) { require.NoError(t, err) } - newLogs := filler.FullFillTradeLogs([]storage.TradeLog{ + tradeLogs := []storage.TradeLog{ { Taker: "0x807cf9a772d5a3f9cefbc1192e939d62f0d9bd38", MakerToken: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", @@ -57,7 +57,8 @@ func TestFillPrice(t *testing.T) { Timestamp: 1720061615000, EventHash: "0xd6d4f5681c246c9f42c203e287975af1601f8df8035a9251f79aab5c8f09e2f8", }, - }) + } + filler.FullFillTradeLogs(tradeLogs) - t.Log(newLogs) + t.Log(tradeLogs) }