Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: handle NULL NFT owner #570

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1579,8 +1579,9 @@ func (c *StorageClient) RuntimeEVMNFTs(ctx context.Context, limit *uint64, offse
var contractAddrContextVersion int
var contractAddrData []byte
var tokenType sql.NullInt32
var ownerAddrContextIdentifier string
var ownerAddrContextVersion int
// Owner might not be known, so these preimage fields are also nilable.
var ownerAddrContextIdentifier *string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a short inline comment here explaining why this is nullable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya

oo come to think of it we should use if nft.Owner != nil instead

var ownerAddrContextVersion *int
var ownerAddrData []byte
var metadataAccessedN sql.NullTime
if err = res.rows.Scan(
Expand Down Expand Up @@ -1617,9 +1618,11 @@ func (c *StorageClient) RuntimeEVMNFTs(ctx context.Context, limit *uint64, offse
if tokenType.Valid {
nft.Token.Type = translateTokenType(common.TokenType(tokenType.Int32))
}
if ownerEthAddr, err1 := EVMEthAddrFromPreimage(ownerAddrContextIdentifier, ownerAddrContextVersion, ownerAddrData); err1 == nil {
ownerECAddr := ethCommon.BytesToAddress(ownerEthAddr)
nft.OwnerEth = common.Ptr(ownerECAddr.String())
if nft.Owner != nil {
if ownerEthAddr, err1 := EVMEthAddrFromPreimage(*ownerAddrContextIdentifier, *ownerAddrContextVersion, ownerAddrData); err1 == nil {
ownerECAddr := ethCommon.BytesToAddress(ownerEthAddr)
nft.OwnerEth = common.Ptr(ownerECAddr.String())
}
}
if metadataAccessedN.Valid {
nft.MetadataAccessed = common.Ptr(metadataAccessedN.Time.String())
Expand Down