Skip to content

Commit

Permalink
should check chainId before deciamals
Browse files Browse the repository at this point in the history
  • Loading branch information
asilenced committed Aug 25, 2022
1 parent d5166e9 commit c165c66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion chains/substrate/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

var (
ValueNotStringError = errors.New("value not string")
SkipError = errors.New("should skip")
)

type eventName string
Expand Down Expand Up @@ -52,7 +53,7 @@ func fungibleTransferHandler(evtI interface{}, log log15.Logger) (msg.Message, e
}

// FungibleTransfer(AccountId, ChainId, DepositNonce, ResourceId, U256, Vec<u8>)
func FungibleTransferEventData(evt *substrate.ChainEvent, decimals map[string]decimal.Decimal) (*EventFungibleTransfer, error) {
func (l *listener) FungibleTransferEventData(evt *substrate.ChainEvent, decimals map[string]decimal.Decimal) (*EventFungibleTransfer, error) {
if len(evt.Params) != 6 {
return nil, fmt.Errorf("EventFungibleTransfer params number not right: %d, expected: 6", len(evt.Params))
}
Expand All @@ -62,6 +63,10 @@ func FungibleTransferEventData(evt *substrate.ChainEvent, decimals map[string]de
return nil, fmt.Errorf("EventFungibleTransfer params[1] -> chainId error: %s", err)
}

if !l.router.SupportChainId(msg.ChainId(chainId)) {
return nil, SkipError
}

nonce, err := parseDepositNonce(evt.Params[2])
if err != nil {
return nil, fmt.Errorf("EventFungibleTransfer params[1] -> chainId error: %s", err)
Expand Down
8 changes: 6 additions & 2 deletions chains/substrate/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,16 @@ func (l *listener) processEvents(blockNum uint64) error {
continue
}

data, err := FungibleTransferEventData(evt, l.decimals)
data, err := l.FungibleTransferEventData(evt, l.decimals)
if err != nil {
if strings.Contains(err.Error(), "recipient error") {
switch {
case strings.Contains(err.Error(), "recipient error"):
l.log.Error("skip recipient err", "blockNumber", blockNum, "eventId", evt.EventId)
continue
case err == SkipError:
continue
}

return err
}
//skip event if not support chainId
Expand Down

0 comments on commit c165c66

Please sign in to comment.