From 767e5c0aaa9efb72b01234568478d9d36ac68d1d Mon Sep 17 00:00:00 2001 From: Ken Erwin Date: Sat, 28 Sep 2024 19:35:16 -0400 Subject: [PATCH] lots of fixes for new backend --- new-backend/go.mod | 15 ++++ new-backend/go.sum | 30 +++++++ .../db/migrations/001_initial_schema.sql | 6 +- new-backend/internal/db/queries.sql.go | 10 ++- new-backend/internal/db/queries/queries.sql | 2 +- new-backend/internal/ingestor/ingestor.go | 84 ++++++++++++++++--- 6 files changed, 130 insertions(+), 17 deletions(-) diff --git a/new-backend/go.mod b/new-backend/go.mod index 47b64d8..658211c 100644 --- a/new-backend/go.mod +++ b/new-backend/go.mod @@ -51,19 +51,34 @@ require ( github.com/google/uuid v1.6.0 // indirect github.com/gorilla/websocket v1.5.3 // indirect github.com/holiman/uint256 v1.3.1 // indirect + github.com/ipfs/go-cid v0.4.1 // indirect + github.com/klauspost/cpuid/v2 v2.0.9 // indirect + github.com/minio/sha256-simd v1.0.0 // indirect github.com/mmcloughlin/addchain v0.4.0 // indirect + github.com/mr-tron/base58 v1.2.0 // indirect + github.com/multiformats/go-base32 v0.0.3 // indirect + github.com/multiformats/go-base36 v0.1.0 // indirect + github.com/multiformats/go-multibase v0.2.0 // indirect + github.com/multiformats/go-multihash v0.2.3 // indirect + github.com/multiformats/go-varint v0.0.6 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/shirou/gopsutil v3.21.11+incompatible // indirect + github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/supranational/blst v0.3.13 // indirect github.com/tklauser/go-sysconf v0.3.14 // indirect github.com/tklauser/numcpus v0.8.0 // indirect + github.com/wealdtech/go-ens/v3 v3.6.0 // indirect + github.com/wealdtech/go-multicodec v1.4.0 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.27.0 // indirect golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect + golang.org/x/net v0.24.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.25.0 // indirect + golang.org/x/text v0.18.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + lukechampine.com/blake3 v1.1.6 // indirect rsc.io/tmplfunc v0.0.3 // indirect ) diff --git a/new-backend/go.sum b/new-backend/go.sum index 2193426..86308b5 100644 --- a/new-backend/go.sum +++ b/new-backend/go.sum @@ -136,12 +136,17 @@ github.com/holiman/uint256 v1.3.1 h1:JfTzmih28bittyHM8z360dCjIA9dbPIBlcTI6lmctQs github.com/holiman/uint256 v1.3.1/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc= github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8= +github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= +github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/klauspost/compress v1.16.0 h1:iULayQNOReoYUe+1qtKOqw9CwJv3aNQu8ivo7lw1HU4= github.com/klauspost/compress v1.16.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -160,6 +165,8 @@ github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4 github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI= github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= +github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g= +github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= @@ -167,6 +174,18 @@ github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8oh github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= +github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= +github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= +github.com/multiformats/go-base32 v0.0.3 h1:tw5+NhuwaOjJCC5Pp82QuXbrmLzWg7uxlMFp8Nq/kkI= +github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= +github.com/multiformats/go-base36 v0.1.0 h1:JR6TyF7JjGd3m6FbLU2cOxhC0Li8z8dLNGQ89tUg4F4= +github.com/multiformats/go-base36 v0.1.0/go.mod h1:kFGE83c6s80PklsHO9sRn2NCoffoRdUUOENyW/Vv6sM= +github.com/multiformats/go-multibase v0.2.0 h1:isdYCVLvksgWlMW9OZRYJEa9pZETFivncJHmHnnd87g= +github.com/multiformats/go-multibase v0.2.0/go.mod h1:bFBZX4lKCA/2lyOFSAoKH5SS6oPyjtnzK/XTFDPkNuk= +github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U= +github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM= +github.com/multiformats/go-varint v0.0.6 h1:gk85QWKxh3TazbLxED/NlDVv8+q+ReFJk7Y2W/KhfNY= +github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -191,9 +210,12 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= +github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= @@ -211,6 +233,10 @@ github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2n github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= +github.com/wealdtech/go-ens/v3 v3.6.0 h1:EAByZlHRQ3vxqzzwNi0GvEq1AjVozfWO4DMldHcoVg8= +github.com/wealdtech/go-ens/v3 v3.6.0/go.mod h1:hcmMr9qPoEgVSEXU2Bwzrn/9NczTWZ1rE53jIlqUpzw= +github.com/wealdtech/go-multicodec v1.4.0 h1:iq5PgxwssxnXGGPTIK1srvt6U5bJwIp7k6kBrudIWxg= +github.com/wealdtech/go-multicodec v1.4.0/go.mod h1:aedGMaTeYkIqi/KCPre1ho5rTb3hGpu/snBOS3GQLw4= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= @@ -236,6 +262,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= +golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= +golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= @@ -277,5 +305,7 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +lukechampine.com/blake3 v1.1.6 h1:H3cROdztr7RCfoaTpGZFQsrqvweFLrqS73j7L7cmR5c= +lukechampine.com/blake3 v1.1.6/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA= rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA= diff --git a/new-backend/internal/db/migrations/001_initial_schema.sql b/new-backend/internal/db/migrations/001_initial_schema.sql index 90d8aa9..72c8226 100644 --- a/new-backend/internal/db/migrations/001_initial_schema.sql +++ b/new-backend/internal/db/migrations/001_initial_schema.sql @@ -15,10 +15,10 @@ CREATE TABLE current_state ( CREATE TABLE tiles ( id INTEGER PRIMARY KEY, image VARCHAR(800) NOT NULL, - price VARCHAR(255) NOT NULL DEFAULT '2.00', + price VARCHAR(255) NOT NULL, url VARCHAR(255) NOT NULL DEFAULT '', - owner VARCHAR(255) NOT NULL DEFAULT '0x4f4b7e7edf5ec41235624ce207a6ef352aca7050', - wrapped BOOLEAN NOT NULL DEFAULT FALSE, + owner VARCHAR(255) NOT NULL DEFAULT '0x4f4b7e7edf5ec41235624ce207a6ef352aca7050' CHECK (owner != ''), + wrapped BOOLEAN NOT NULL, ens VARCHAR(255) NOT NULL DEFAULT '', opensea_price VARCHAR(255) NOT NULL DEFAULT '0.0' ); diff --git a/new-backend/internal/db/queries.sql.go b/new-backend/internal/db/queries.sql.go index 74aa6cf..206237b 100644 --- a/new-backend/internal/db/queries.sql.go +++ b/new-backend/internal/db/queries.sql.go @@ -829,17 +829,23 @@ func (q *Queries) UpdateTileOpenSeaPrice(ctx context.Context, arg UpdateTileOpen const updateTileOwner = `-- name: UpdateTileOwner :exec UPDATE tiles -SET owner = $2, wrapped = $3 +SET owner = $2, ens = $3, wrapped = $4 WHERE id = $1 ` type UpdateTileOwnerParams struct { ID int32 `json:"id"` Owner string `json:"owner"` + Ens string `json:"ens"` Wrapped bool `json:"wrapped"` } func (q *Queries) UpdateTileOwner(ctx context.Context, arg UpdateTileOwnerParams) error { - _, err := q.db.ExecContext(ctx, updateTileOwner, arg.ID, arg.Owner, arg.Wrapped) + _, err := q.db.ExecContext(ctx, updateTileOwner, + arg.ID, + arg.Owner, + arg.Ens, + arg.Wrapped, + ) return err } diff --git a/new-backend/internal/db/queries/queries.sql b/new-backend/internal/db/queries/queries.sql index c268fde..e507d0f 100644 --- a/new-backend/internal/db/queries/queries.sql +++ b/new-backend/internal/db/queries/queries.sql @@ -106,7 +106,7 @@ ORDER BY id; -- name: UpdateTileOwner :exec UPDATE tiles -SET owner = $2, wrapped = $3 +SET owner = $2, ens = $3, wrapped = $4 WHERE id = $1; -- name: UpdateTileENS :exec diff --git a/new-backend/internal/ingestor/ingestor.go b/new-backend/internal/ingestor/ingestor.go index 5b774b5..745af10 100644 --- a/new-backend/internal/ingestor/ingestor.go +++ b/new-backend/internal/ingestor/ingestor.go @@ -16,7 +16,9 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" "github.com/lib/pq" + ens "github.com/wealdtech/go-ens/v3" "go.uber.org/zap" pixelmap "pixelmap.io/backend/internal/contracts/pixelmap" pixelmapWrapper "pixelmap.io/backend/internal/contracts/pixelmapWrapper" @@ -40,6 +42,19 @@ func NewPubSub() *PubSub { } } +func lookupENS(client *ethclient.Client, address string) (string, error) { + + name, err := ens.ReverseResolve(client, common.HexToAddress(address)) + if err != nil { + if err.Error() == "ErrNoName" { + return "", nil // No ENS name found, but not an error + } + return "", fmt.Errorf("failed to resolve ENS name: %w", err) + } + + return name, nil +} + func (ps *PubSub) Subscribe(eventType string) <-chan Event { ps.mu.Lock() defer ps.mu.Unlock() @@ -70,6 +85,7 @@ type Ingestor struct { maxRetries int baseDelay time.Duration s3Syncer *S3Syncer + ethClient *ethclient.Client } func NewIngestor(logger *zap.Logger, sqlDB *sql.DB, apiKey string) *Ingestor { @@ -85,6 +101,15 @@ func NewIngestor(logger *zap.Logger, sqlDB *sql.DB, apiKey string) *Ingestor { } } + ethClient, err := ethclient.Dial(os.Getenv("WEB3_URL")) + if err != nil { + logger.Error("Failed to connect to Ethereum client", zap.Error(err)) + } + + if err != nil { + logger.Error("Failed to create ENS resolver", zap.Error(err)) + } + ingestor := &Ingestor{ logger: logger, queries: db.New(sqlDB), @@ -94,6 +119,7 @@ func NewIngestor(logger *zap.Logger, sqlDB *sql.DB, apiKey string) *Ingestor { maxRetries: 5, baseDelay: time.Second, s3Syncer: s3Syncer, + ethClient: ethClient, } // Start the continuous rendering process @@ -338,12 +364,15 @@ func (i *Ingestor) processTransaction(ctx context.Context, tx *EtherscanTransact TileID: int32(location.Int64()), SoldBy: tile.Owner, PurchasedBy: tx.From, - Price: tile.Price, + Price: "0", Tx: tx.Hash, TimeStamp: time.Unix(timeStamp.Int64(), 0), BlockNumber: blockNumber.Int64(), LogIndex: int32(transactionIndex), } + if tile.Price != "" { + purchaseHistory.Price = tile.Price + } _, err = i.queries.InsertPurchaseHistory(ctx, purchaseHistory) if err != nil { @@ -361,6 +390,11 @@ func (i *Ingestor) processTransaction(ctx context.Context, tx *EtherscanTransact } // Update tile owner + if tx.From == "" { + i.logger.Warn("Transaction has no Owner address?", + zap.String("tx", tx.Hash)) + os.Exit(1) + } err = i.queries.UpdateTileOwner(ctx, db.UpdateTileOwnerParams{ ID: int32(location.Int64()), Owner: tx.From, @@ -382,8 +416,9 @@ func (i *Ingestor) processTransaction(ctx context.Context, tx *EtherscanTransact image, _ := args[1].(string) url, _ := args[2].(string) priceWei, _ := args[3].(*big.Int) + wrapped := false - if err := i.processTileUpdate(ctx, location, image, url, priceWei, tx, timeStamp.Int64(), blockNumber.Int64(), int32(transactionIndex)); err != nil { + if err := i.processTileUpdate(ctx, location, image, url, priceWei, tx, timeStamp.Int64(), blockNumber.Int64(), int32(transactionIndex), wrapped); err != nil { return err } } @@ -393,9 +428,10 @@ func (i *Ingestor) processTransaction(ctx context.Context, tx *EtherscanTransact location, _ := args[0].(*big.Int) image, _ := args[1].(string) url, _ := args[2].(string) + wrapped := true // For setTileData, we don't change the price, so we pass nil for priceWei - if err := i.processTileUpdate(ctx, location, image, url, nil, tx, timeStamp.Int64(), blockNumber.Int64(), int32(transactionIndex)); err != nil { + if err := i.processTileUpdate(ctx, location, image, url, nil, tx, timeStamp.Int64(), blockNumber.Int64(), int32(transactionIndex), wrapped); err != nil { return err } } @@ -445,10 +481,15 @@ func (i *Ingestor) processTransaction(ctx context.Context, tx *EtherscanTransact if err != nil { return fmt.Errorf("failed to insert wrapping history: %w", err) } + if tx.From == "" { + i.logger.Warn("Transaction has no Owner address?", + zap.String("tx", tx.Hash)) + os.Exit(1) + } err = i.queries.UpdateTile(ctx, db.UpdateTileParams{ ID: int32(location.Int64()), Owner: tx.From, - Wrapped: wrapped == "true", + Wrapped: true, }) if err != nil { return fmt.Errorf("failed to update tile owner: %w", err) @@ -479,10 +520,15 @@ func (i *Ingestor) processTransaction(ctx context.Context, tx *EtherscanTransact if err != nil { return fmt.Errorf("failed to insert wrapping history: %w", err) } + if tx.From == "" { + i.logger.Warn("Transaction has no Owner address?", + zap.String("tx", tx.Hash)) + os.Exit(1) + } err = i.queries.UpdateTile(ctx, db.UpdateTileParams{ ID: int32(location.Int64()), Owner: tx.From, - Wrapped: wrapped == "false", + Wrapped: false, }) if err != nil { return fmt.Errorf("failed to update tile owner: %w", err) @@ -725,7 +771,7 @@ func (i *Ingestor) renderAndSaveImage(location *big.Int, imageData string, block // Verify that the files were created if _, err := os.Stat(blockFilePath); os.IsNotExist(err) { - i.logger.Error("Block image file not created", + i.logger.Debug("Block image file not created", zap.String("path", blockFilePath)) return nil } @@ -742,7 +788,7 @@ func (i *Ingestor) renderAndSaveImage(location *big.Int, imageData string, block return nil } -func (i *Ingestor) processTileUpdate(ctx context.Context, location *big.Int, image, url string, priceWei *big.Int, tx *EtherscanTransaction, timestamp, blockNumber int64, transactionIndex int32) error { +func (i *Ingestor) processTileUpdate(ctx context.Context, location *big.Int, image, url string, priceWei *big.Int, tx *EtherscanTransaction, timestamp, blockNumber int64, transactionIndex int32, wrapped bool) error { var priceEthStr string if priceWei == nil { // Fetch the current price from the database @@ -799,10 +845,12 @@ func (i *Ingestor) processTileUpdate(ctx context.Context, location *big.Int, ima // Update the tile in the database err := i.queries.UpdateTile(ctx, db.UpdateTileParams{ - ID: int32(location.Int64()), - Price: priceEthStr, - Url: url, - Image: image, + ID: int32(location.Int64()), + Price: priceEthStr, + Url: url, + Image: image, + Owner: tx.From, + Wrapped: wrapped, }) if err != nil { i.logger.Error("Failed to update tile", zap.Error(err), zap.String("location", location.String())) @@ -866,9 +914,23 @@ func (i *Ingestor) processTransfer(ctx context.Context, args []interface{}, tx * } // Update tile owner + if to.Hex() == "" { + i.logger.Warn("Transaction has no Owner address?", + zap.String("tx", tx.Hash)) + os.Exit(1) + } + + // Lookup ENS + ensName, err := lookupENS(i.ethClient, to.Hex()) + if err != nil { + i.logger.Error("Failed to lookup ENS", zap.Error(err), zap.String("address", to.Hex())) + } + i.logger.Debug("ENS", zap.String("ens", ensName), zap.String("address", to.Hex())) + err = i.queries.UpdateTileOwner(ctx, db.UpdateTileOwnerParams{ ID: int32(location.Int64()), Owner: to.Hex(), + Ens: ensName, }) if err != nil { return fmt.Errorf("failed to update tile owner: %w", err)