feat: index ownership changes, bump min go version
This commit is contained in:
parent
afd8e3f30b
commit
defde73bd4
@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.23.0-bookworm as build
|
FROM golang:1.23.3-bookworm as build
|
||||||
|
|
||||||
ENV CGO_ENABLED=1
|
ENV CGO_ENABLED=1
|
||||||
|
|
||||||
|
@ -38,6 +38,10 @@ func bootstrapRouter(handlerContainer *handler.Handler) *router.Router {
|
|||||||
handlerContainer.IndexFaucetGive,
|
handlerContainer.IndexFaucetGive,
|
||||||
handlerContainer.FaucetHealthCheck,
|
handlerContainer.FaucetHealthCheck,
|
||||||
)
|
)
|
||||||
|
router.RegisterRoute(
|
||||||
|
"TRACKER.OWNERSHIP_TRANSFERRED",
|
||||||
|
handlerContainer.IndexOwnershipChange,
|
||||||
|
)
|
||||||
|
|
||||||
return router
|
return router
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
|||||||
module github.com/grassrootseconomics/eth-indexer
|
module github.com/grassrootseconomics/eth-indexer
|
||||||
|
|
||||||
go 1.23.0
|
go 1.23.3
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/VictoriaMetrics/metrics v1.35.1
|
github.com/VictoriaMetrics/metrics v1.35.1
|
||||||
|
11
internal/handler/ownership.go
Normal file
11
internal/handler/ownership.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/grassrootseconomics/eth-tracker/pkg/event"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *Handler) IndexOwnershipChange(ctx context.Context, event event.Event) error {
|
||||||
|
return h.store.InsertOwnershipChange(ctx, event)
|
||||||
|
}
|
@ -36,6 +36,7 @@ type (
|
|||||||
InsertFaucetGive string `query:"insert-faucet-give"`
|
InsertFaucetGive string `query:"insert-faucet-give"`
|
||||||
InsertPoolSwap string `query:"insert-pool-swap"`
|
InsertPoolSwap string `query:"insert-pool-swap"`
|
||||||
InsertPoolDeposit string `query:"insert-pool-deposit"`
|
InsertPoolDeposit string `query:"insert-pool-deposit"`
|
||||||
|
InsertOwnershipChange string `query:"insert-ownership-change"`
|
||||||
InsertToken string `query:"insert-token"`
|
InsertToken string `query:"insert-token"`
|
||||||
InsertPool string `query:"insert-pool"`
|
InsertPool string `query:"insert-pool"`
|
||||||
}
|
}
|
||||||
@ -199,6 +200,25 @@ func (pg *Pg) InsertPoolDeposit(ctx context.Context, eventPayload event.Event) e
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pg *Pg) InsertOwnershipChange(ctx context.Context, eventPayload event.Event) error {
|
||||||
|
return pg.executeTransaction(ctx, func(tx pgx.Tx) error {
|
||||||
|
txID, err := pg.insertTx(ctx, tx, eventPayload)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = tx.Exec(
|
||||||
|
ctx,
|
||||||
|
pg.queries.InsertOwnershipChange,
|
||||||
|
txID,
|
||||||
|
eventPayload.Payload["previousOwner"].(string),
|
||||||
|
eventPayload.Payload["newOwner"].(string),
|
||||||
|
eventPayload.ContractAddress,
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (pg *Pg) InsertToken(ctx context.Context, contractAddress string, name string, symbol string, decimals uint8, sinkAddress string) error {
|
func (pg *Pg) InsertToken(ctx context.Context, contractAddress string, name string, symbol string, decimals uint8, sinkAddress string) error {
|
||||||
return pg.executeTransaction(ctx, func(tx pgx.Tx) error {
|
return pg.executeTransaction(ctx, func(tx pgx.Tx) error {
|
||||||
_, err := tx.Exec(
|
_, err := tx.Exec(
|
||||||
|
@ -15,6 +15,7 @@ type (
|
|||||||
InsertFaucetGive(context.Context, event.Event) error
|
InsertFaucetGive(context.Context, event.Event) error
|
||||||
InsertPoolSwap(context.Context, event.Event) error
|
InsertPoolSwap(context.Context, event.Event) error
|
||||||
InsertPoolDeposit(context.Context, event.Event) error
|
InsertPoolDeposit(context.Context, event.Event) error
|
||||||
|
InsertOwnershipChange(context.Context, event.Event) error
|
||||||
InsertToken(context.Context, string, string, string, uint8, string) error
|
InsertToken(context.Context, string, string, string, uint8, string) error
|
||||||
InsertPool(context.Context, string, string, string) error
|
InsertPool(context.Context, string, string, string) error
|
||||||
Pool() *pgxpool.Pool
|
Pool() *pgxpool.Pool
|
||||||
|
7
migrations/002_track_ownership_change.sql
Normal file
7
migrations/002_track_ownership_change.sql
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS ownership_change (
|
||||||
|
id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||||
|
tx_id INT REFERENCES tx(id),
|
||||||
|
previous_owner VARCHAR(42) NOT NULL DEFAULT '0x0000000000000000000000000000000000000000',
|
||||||
|
new_owner VARCHAR(42) NOT NULL DEFAULT '0x0000000000000000000000000000000000000000'.
|
||||||
|
contract_address VARCHAR(42) NOT NULL DEFAULT '0x0000000000000000000000000000000000000000'
|
||||||
|
);
|
12
queries.sql
12
queries.sql
@ -104,6 +104,18 @@ INSERT INTO pool_deposit(
|
|||||||
contract_address
|
contract_address
|
||||||
) VALUES($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING
|
) VALUES($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING
|
||||||
|
|
||||||
|
--name: insert-ownership-change
|
||||||
|
-- $1: tx_id
|
||||||
|
-- $2: previous_owner
|
||||||
|
-- $3: new_owner
|
||||||
|
-- $4: contract_address
|
||||||
|
INSERT INTO ownership_change(
|
||||||
|
tx_id,
|
||||||
|
previous_owner,
|
||||||
|
new_owner,
|
||||||
|
contract_address
|
||||||
|
) VALUES($1, $2, $3, $4) ON CONFLICT DO NOTHING
|
||||||
|
|
||||||
--name: insert-token
|
--name: insert-token
|
||||||
-- $1: contract_address
|
-- $1: contract_address
|
||||||
-- $2: token_name
|
-- $2: token_name
|
||||||
|
Loading…
Reference in New Issue
Block a user