Skip to content

Commit

Permalink
chore: reuse abi.ABI
Browse files Browse the repository at this point in the history
  • Loading branch information
tiennampham23 committed Dec 13, 2023
1 parent fe3b01c commit ebc7980
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
13 changes: 4 additions & 9 deletions pkg/decoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@ package decoder

import (
"encoding/hex"
"fmt"
"github.com/KyberNetwork/tradelogs/internal/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"strings"
)

func Decode(abiStr string, input string) (*types.ContractCall, error) {
ABI, err := abi.JSON(strings.NewReader(abiStr))
if err != nil {
return nil, err
}
if err != nil {
return nil, err
func Decode(ABI *abi.ABI, input string) (*types.ContractCall, error) {
if ABI == nil {
return nil, fmt.Errorf("missing abi")
}

inputBytes := common.FromHex(input)
method, err := ABI.MethodById(inputBytes)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/parser/oneinch/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (p *Parser) recursiveDetectOneInchRFQTrades(tradeLog storage.TradeLog, log
isOneInchRFQTrade := p.isOneInchRFQTrades(log, traceCall.Logs)

if isOneInchRFQTrade {
contractCall, err := decoder.Decode(OneinchMetaData.ABI, traceCall.Input)
contractCall, err := decoder.Decode(p.abi, traceCall.Input)
if err != nil {
return tradeLog, err
}
Expand Down

0 comments on commit ebc7980

Please sign in to comment.