Skip to content

Commit

Permalink
lots of fixes for new backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Erwin committed Sep 28, 2024
1 parent e87272f commit 767e5c0
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 17 deletions.
15 changes: 15 additions & 0 deletions new-backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
30 changes: 30 additions & 0 deletions new-backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -160,13 +165,27 @@ 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=
github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4=
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=
Expand All @@ -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=
Expand All @@ -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=
Expand All @@ -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=
Expand Down Expand Up @@ -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=
6 changes: 3 additions & 3 deletions new-backend/internal/db/migrations/001_initial_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
Expand Down
10 changes: 8 additions & 2 deletions new-backend/internal/db/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion new-backend/internal/db/queries/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
84 changes: 73 additions & 11 deletions new-backend/internal/ingestor/ingestor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand Down Expand Up @@ -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 {
Expand All @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -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
}
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 767e5c0

Please sign in to comment.