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

NFT original metadata #552

Merged
merged 6 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions analyzer/evmnfts/evm_nfts.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (p *processor) ProcessItem(ctx context.Context, batch *storage.QueryBatch,
staleNFT.DownloadRound,
nftData.MetadataURI,
nftData.MetadataAccessed,
nftData.Metadata,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

apparently this makes it so that the string is the JSON serialized value. I have no idea how, hypothetically, to tell the db that "the JSON value was a string, here's that string."

nftData.Name,
nftData.Description,
nftData.Image,
Expand Down
7 changes: 4 additions & 3 deletions analyzer/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,10 @@ var (
last_download_round = $4,
metadata_uri = $5,
metadata_accessed = $6,
name = $7,
description = $8,
image = $9
metadata = $7,
name = $8,
description = $9,
image = $10
WHERE
runtime = $1 AND
token_address = $2 AND
Expand Down
7 changes: 4 additions & 3 deletions analyzer/runtime/evm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ type EVMTokenMutableData struct {
type EVMNFTData struct {
MetadataURI string
MetadataAccessed time.Time
Name string
Description string
Image string
Metadata *string
Name *string
Description *string
Image *string
}

type EVMTokenBalanceData struct {
Expand Down
12 changes: 8 additions & 4 deletions analyzer/runtime/evm/erc721.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"math/big"
"strings"
"time"

ethCommon "github.com/ethereum/go-ethereum/common"
Expand All @@ -26,13 +27,13 @@ const MaxMetadataBytes = 10 * 1024 * 1024
// https://eips.ethereum.org/EIPS/eip-721
type ERC721AssetMetadata struct {
// Name identifies the asset which this NFT represents
Name string `json:"name"`
Name *string `json:"name"`
// Description describes the asset which this NFT represents
Description string `json:"description"`
Description *string `json:"description"`
// Image is A URI pointing to a resource with mime type image/*
// representing the asset which this NFT represents. (Additional
// non-descriptive text from ERC-721 omitted.)
Image string `json:"image"`
Image *string `json:"image"`
}

func evmDownloadTokenERC721Mutable(ctx context.Context, logger *log.Logger, source nodeapi.RuntimeApiLite, round uint64, tokenEthAddr []byte) (*EVMTokenMutableData, error) {
Expand Down Expand Up @@ -108,8 +109,10 @@ func evmDownloadNFTERC721Metadata(ctx context.Context, logger *log.Logger, sourc
return nil
}
limitedReader := io.LimitReader(rc, MaxMetadataBytes)
var metadataBuilder strings.Builder
teeReader := io.TeeReader(limitedReader, &metadataBuilder)
var metadata ERC721AssetMetadata
if err = json.NewDecoder(limitedReader).Decode(&metadata); err != nil {
if err = json.NewDecoder(teeReader).Decode(&metadata); err != nil {
logger.Info("error decoding token metadata",
"uri", nftData.MetadataURI,
"err", err,
Expand All @@ -118,6 +121,7 @@ func evmDownloadNFTERC721Metadata(ctx context.Context, logger *log.Logger, sourc
if err = rc.Close(); err != nil {
return fmt.Errorf("closing metadata reader: %w", err)
}
nftData.Metadata = common.Ptr(metadataBuilder.String())
nftData.Name = metadata.Name
nftData.Description = metadata.Description
nftData.Image = metadata.Image
Expand Down
4 changes: 4 additions & 0 deletions api/spec/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2689,6 +2689,10 @@ components:
type: string
metadata_accessed:
type: string
metadata:
description: |
A metadata document for this NFT instance.
Currently only ERC-721 is supported, where the document is an Asset Metadata from the ERC721 Metadata JSON Schema.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

https://eips.ethereum.org/EIPS/eip-721 their schema is here. if higher effort, we could import that and say it could be that schema

name:
type: string
description: Identifies the asset which this NFT represents
Expand Down
1 change: 1 addition & 0 deletions storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,7 @@ func (c *StorageClient) RuntimeEVMNFTs(ctx context.Context, limit *uint64, offse
&ownerAddrData,
&nft.MetadataUri,
&metadataAccessedN,
&nft.Metadata,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

and then this does unmarshal the JSON from the db into Metadata interface{} as like maps and stuff 🤷 and our API layer later re-marshals it 🔁

&nft.Name,
&nft.Description,
&nft.Image,
Expand Down
1 change: 1 addition & 0 deletions storage/client/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ const (
owner_preimage.address_data,
chain.evm_nfts.metadata_uri,
chain.evm_nfts.metadata_accessed,
chain.evm_nfts.metadata,
chain.evm_nfts.name,
chain.evm_nfts.description,
chain.evm_nfts.image
Expand Down
6 changes: 6 additions & 0 deletions storage/migrations/23_evm_nfts.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN;

ALTER TABLE chain.evm_nfts
ADD COLUMN metadata JSONB;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

using a json type to be nice to people who want to do things in the db. but beware there are no indices. downside is that both go and postgresql will parse the JSON code. if they ever have any difference in opinion on what's valid JSON, then someone could break our indexer.


COMMIT;
Loading
Loading