Skip to content

Commit

Permalink
feat(eventindexer): Index nfts (#14418)
Browse files Browse the repository at this point in the history
Co-authored-by: David <david@taiko.xyz>
Co-authored-by: Roger <50648015+RogerLamTd@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 9, 2023
1 parent 2d9ab0f commit 364b09b
Show file tree
Hide file tree
Showing 55 changed files with 1,448 additions and 318 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/eventindexer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Eventindexer

on:
push:
branches: [main, alpha-2]
branches: [main]
paths:
- "packages/eventindexer/**"
pull_request:
Expand All @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.20.5
go-version: 1.21.0
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand All @@ -40,7 +40,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ">=1.20.5"
go-version: ">=1.21.0"

- name: eventindexer - Unit Tests
working-directory: ./packages/eventindexer
Expand Down Expand Up @@ -96,4 +96,4 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
PACKAGE=eventindexer

This comment has been minimized.

Copy link
@edtjguillamon

edtjguillamon Apr 18, 2024

I don't think this is well wrote

PACKAGE=eventindexer
8 changes: 4 additions & 4 deletions .github/workflows/relayer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Relayer

on:
push:
branches: [main, alpha-2]
branches: [main]
paths:
- "packages/relayer/**"
pull_request:
Expand All @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.20.5
go-version: 1.21.0
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand All @@ -26,7 +26,7 @@ jobs:

# Optional: working directory, useful for monorepos
working-directory: ./packages/relayer
args: --config=.golangci.yml
args: --config=.golangci.yml --timeout=4m

test:
runs-on: ubuntu-latest
Expand All @@ -40,7 +40,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "1.20.5"
go-version: "1.21.0"

- name: relayer - Unit Tests
working-directory: ./packages/relayer
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19.3 as builder
FROM golang:1.21.0 as builder

ARG PACKAGE=eventindexer

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/taikoxyz/taiko-mono

go 1.19
go 1.21

require (
github.com/buildkite/terminal-to-html/v3 v3.8.0
Expand Down
64 changes: 64 additions & 0 deletions go.sum

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion packages/eventindexer/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ linters:
- gocognit
- gocritic
- gofmt
- golint
# - revive
- gosec
- gosimple
- lll
Expand All @@ -44,3 +44,6 @@ issues:
- path: contracts\.go
linters:
- lll
- path: /
linters:
- typecheck
22 changes: 19 additions & 3 deletions packages/eventindexer/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"context"
"fmt"
"log"
"os"
"strconv"
"strings"
Expand All @@ -15,7 +16,6 @@ import (
"github.com/ethereum/go-ethereum/rpc"
"github.com/joho/godotenv"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/taikoxyz/taiko-mono/packages/eventindexer"
"github.com/taikoxyz/taiko-mono/packages/eventindexer/db"
"github.com/taikoxyz/taiko-mono/packages/eventindexer/http"
Expand Down Expand Up @@ -45,13 +45,12 @@ func Run(
mode eventindexer.Mode,
watchMode eventindexer.WatchMode,
httpOnly eventindexer.HTTPOnly,
indexNfts eventindexer.IndexNFTS,
) {
if err := loadAndValidateEnv(); err != nil {
log.Fatal(err)
}

log.SetFormatter(&log.JSONFormatter{})

db, err := openDBConnection(eventindexer.DBConnectionOpts{
Name: os.Getenv("MYSQL_USER"),
Password: os.Getenv("MYSQL_PASSWORD"),
Expand Down Expand Up @@ -126,10 +125,20 @@ func Run(
log.Fatal(err)
}

var nftBalanceRepo eventindexer.NFTBalanceRepository

if indexNfts {
nftBalanceRepo, err = repo.NewNFTBalanceRepository(db)
if err != nil {
log.Fatal(err)
}
}

i, err := indexer.NewService(indexer.NewServiceOpts{
EventRepo: eventRepository,
BlockRepo: blockRepository,
StatRepo: statRepository,
NFTBalanceRepo: nftBalanceRepo,
EthClient: ethClient,
RPCClient: rpcClient,
SrcTaikoAddress: common.HexToAddress(os.Getenv("L1_TAIKO_ADDRESS")),
Expand All @@ -138,6 +147,7 @@ func Run(
SrcSwapAddresses: stringsToAddresses(strings.Split(os.Getenv("SWAP_ADDRESSES"), ",")),
BlockBatchSize: uint64(blockBatchSize),
SubscriptionBackoff: subscriptionBackoff,
IndexNFTs: bool(indexNfts),
})
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -267,9 +277,15 @@ func newHTTPServer(db eventindexer.DB, l1EthClient *ethclient.Client) (*http.Ser
return nil, err
}

nftBalanceRepo, err := repo.NewNFTBalanceRepository(db)
if err != nil {
return nil, err
}

srv, err := http.NewServer(http.NewServerOpts{
EventRepo: eventRepo,
StatRepo: statRepo,
NFTBalanceRepo: nftBalanceRepo,
Echo: echo.New(),
CorsOrigins: strings.Split(os.Getenv("CORS_ORIGINS"), ","),
EthClient: l1EthClient,
Expand Down
7 changes: 7 additions & 0 deletions packages/eventindexer/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@ func main() {
false: run an http server and index blocks
`)

indexNfts := flag.Bool("index-nfts", false, `index nft transfer events.
options:
true: index
false: dont index
`)

flag.Parse()

cli.Run(
eventindexer.Mode(*modePtr),
eventindexer.WatchMode(*watchModePtr),
eventindexer.HTTPOnly(*httpOnlyPtr),
eventindexer.IndexNFTS(*indexNfts),
)
}
Loading

1 comment on commit 364b09b

@quangbui6789
Copy link

Choose a reason for hiding this comment

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

good project

Please sign in to comment.