Skip to content

Commit

Permalink
Return error on nil tokenID
Browse files Browse the repository at this point in the history
  • Loading branch information
lukanus committed Feb 19, 2024
1 parent 0376980 commit 44f9915
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions eth/tracers/blocknative/decoder/evm_caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func evmCallMethodDecimals(evmCall evmCallFn, addr common.Address) (uint8, error

// evmCallMethodTokenURI decodes the tokenURI of an asset from the EVM.
func evmCallMethodTokenURI(evmCall evmCallFn, addr common.Address, tokenID *big.Int) (string, error) {
if tokenID == nil {
return "", fmt.Errorf("tokenID is nil")
}

tokenIDBytes := tokenID.Bytes()
if len(tokenIDBytes) > 32 {
return "", fmt.Errorf("tokenID is too large")
Expand All @@ -99,6 +103,10 @@ func evmCallMethodTokenURI(evmCall evmCallFn, addr common.Address, tokenID *big.

// evmCallMethodURI decodes the URI of an asset from the EVM.
func evmCallMethodURI(evmCall evmCallFn, addr common.Address, tokenID *big.Int) (string, error) {
if tokenID == nil {
return "", fmt.Errorf("tokenID is nil")
}

tokenIDBytes := common.LeftPadBytes(tokenID.Bytes(), 32)
input := append(methodIDURI, tokenIDBytes...)
return callAndDecodeString(evmCall, addr, input)
Expand Down
4 changes: 2 additions & 2 deletions eth/tracers/blocknative/decoder/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"

"github.com/ethereum/go-ethereum/common"
)

Expand Down Expand Up @@ -82,7 +83,7 @@ var methodSignatures = map[string]string{
type MethodID []byte

func (m MethodID) Is(other MethodID) bool {
return bytes.Compare(m, other) == 0
return bytes.Equal(m, other)
}

func (m MethodID) String() string {
Expand Down Expand Up @@ -113,7 +114,6 @@ func (m *MethodID) UnmarshalJSON(b []byte) error {
}

if len(b) > methodIDEncodedLen {
fmt.Println("sdfasdfasdf:", len(b), string(b), b)
return ErrMethodIDTooLong
}

Expand Down

0 comments on commit 44f9915

Please sign in to comment.