Skip to content

Commit

Permalink
fix: wrong extra format (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing authored Nov 1, 2023
1 parent 5c35195 commit 0a3b063
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
14 changes: 14 additions & 0 deletions monitor/bsc_block_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
8 changes: 7 additions & 1 deletion monitor/gnfd_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0a3b063

Please sign in to comment.