From 0a3b0632142cea01a2a32c5fc8c6f3b0cc1618fc Mon Sep 17 00:00:00 2001 From: forcodedancing Date: Wed, 1 Nov 2023 18:05:08 +0800 Subject: [PATCH] fix: wrong extra format (#5) --- monitor/bsc_block_processor.go | 14 ++++++++++++++ monitor/gnfd_event.go | 8 +++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/monitor/bsc_block_processor.go b/monitor/bsc_block_processor.go index 33a4f99..d987872 100644 --- a/monitor/bsc_block_processor.go +++ b/monitor/bsc_block_processor.go @@ -187,6 +187,13 @@ func (p *BscBlockProcessor) handleEventList(blockHeight uint64, l types.Log) (st return "", nil } + // item should be existed + _, err = p.itemDao.GetByGroupId(context.Background(), event.GroupId.Int64(), true) + if err != nil { + util.Logger.Errorf("processor: %s, fail to find item %d err: %s", p.Name(), event.GroupId.Int64(), err) + return "", err + } + rawSql := fmt.Sprintf("update items set status = %d, price = %s, updated_bsc_height = %d where group_id = %d ", database.ItemListed, event.Price, blockHeight, event.GroupId) @@ -203,6 +210,13 @@ func (p *BscBlockProcessor) handleEventDelist(blockHeight uint64, l types.Log) ( return "", nil } + // item should be existed + _, err = p.itemDao.GetByGroupId(context.Background(), event.GroupId.Int64(), true) + if err != nil { + util.Logger.Errorf("processor: %s, fail to find item %d err: %s", p.Name(), event.GroupId.Int64(), err) + return "", err + } + rawSql := fmt.Sprintf("update items set status = %d, updated_bsc_height = %d where group_id = %d ", database.ItemDelisted, blockHeight, event.GroupId) diff --git a/monitor/gnfd_event.go b/monitor/gnfd_event.go index 6d9de77..2f934a9 100644 --- a/monitor/gnfd_event.go +++ b/monitor/gnfd_event.go @@ -11,11 +11,17 @@ type Extra struct { Price decimal.Decimal `json:"price"` } +// If there is wrong format extra, we just ignore the error and use default values. +// https://gnfd-testnet-fullnode-tendermint-us.bnbchain.org/block_results?height=1658808 func parseExtra(str string) (*Extra, error) { var extra Extra err := json.Unmarshal([]byte(str), &extra) if err != nil { - return nil, err + return &Extra{ + Desc: "", + Url: "", + Price: decimal.Zero, + }, nil } return &extra, nil