From 418966e5a8b5012b581911e65bebca5bc1365d92 Mon Sep 17 00:00:00 2001 From: Ryan Smith Date: Tue, 10 Oct 2023 14:33:02 -0700 Subject: [PATCH] integrations/txinputs: revert Now that we have declaritive based indexing, this compiled integration no longer makes sense. Here is the equivalent config: { "pg_url": "postgres:///e2pg", "eth_sources": [{"name": "main", "chain_id": 1, "url": ""}], "integrations": [{ "name": "txinputs", "enabled": true, "sources": [{"name": "main"}], "table": { "name": "txi", "columns": [ {"name": "chain_id", "type": "numeric"}, {"name": "block_hash", "type": "bytea"}, {"name": "block_num", "type": "numeric"}, {"name": "tx_hash", "type": "bytea"}, {"name": "tx_idx", "type": "numeric"}, {"name": "tx_signer", "type": "bytea"}, {"name": "tx_to", "type": "bytea"}, {"name": "tx_input", "type": "bytea"} ] }, "block": [ {"name": "chain_id", "column": "chain_id"}, {"name": "block_hash", "column": "block_hash"}, {"name": "block_num", "column": "block_num"}, {"name": "tx_hash", "column": "tx_hash"}, {"name": "tx_idx", "column": "tx_idx"}, {"name": "tx_signer", "column": "tx_signer"}, {"name": "tx_to", "column": "tx_to"}, {"name": "tx_input", "column": "tx_input"} ] }] } --- e2pg/config/config.go | 10 ++- e2pg/migrations.go | 17 +---- e2pg/schema.sql | 14 ---- integrations/txinputs/inputs.go | 98 ---------------------------- integrations/txinputs/inputs_test.go | 48 -------------- 5 files changed, 5 insertions(+), 182 deletions(-) delete mode 100644 integrations/txinputs/inputs.go delete mode 100644 integrations/txinputs/inputs_test.go diff --git a/e2pg/config/config.go b/e2pg/config/config.go index e9c2ac8f..04d23d32 100644 --- a/e2pg/config/config.go +++ b/e2pg/config/config.go @@ -13,18 +13,16 @@ import ( "github.com/indexsupply/x/integrations/erc20" "github.com/indexsupply/x/integrations/erc4337" "github.com/indexsupply/x/integrations/erc721" - "github.com/indexsupply/x/integrations/txinputs" "github.com/indexsupply/x/jrpc2" "github.com/indexsupply/x/rlps" "github.com/jackc/pgx/v5/pgxpool" ) var compiled = map[string]e2pg.Integration{ - "erc20": erc20.Integration, - "erc721": erc721.Integration, - "erc1155": erc1155.Integration, - "erc4337": erc4337.Integration, - "txinputs": txinputs.Integration, + "erc20": erc20.Integration, + "erc721": erc721.Integration, + "erc1155": erc1155.Integration, + "erc4337": erc4337.Integration, } type EthSource struct { diff --git a/e2pg/migrations.go b/e2pg/migrations.go index e557fad5..50fa75b9 100644 --- a/e2pg/migrations.go +++ b/e2pg/migrations.go @@ -99,28 +99,13 @@ var Migrations = map[int]pgmig.Migration{ 6: pgmig.Migration{ SQL: `alter table task set schema e2pg`, }, - 7: pgmig.Migration{ - SQL: ` - create table tx_inputs ( - task_id numeric, - chain_id numeric, - block_hash bytea, - block_number numeric, - tx_hash bytea, - tx_index numeric, - tx_signer bytea, - tx_to bytea, - tx_input bytea - ) - `, - }, + 7: pgmig.Migration{SQL: ``}, //reverted tx_inputs 8: pgmig.Migration{ SQL: ` alter table e2pg.task alter column id type text; alter table nft_transfers alter column task_id type text; alter table erc20_transfers alter column task_id type text; alter table erc4337_userops alter column task_id type text; - alter table tx_inputs alter column task_id type text; `, }, } diff --git a/e2pg/schema.sql b/e2pg/schema.sql index e548000a..2ae9542b 100644 --- a/e2pg/schema.sql +++ b/e2pg/schema.sql @@ -96,20 +96,6 @@ CREATE TABLE public.nft_transfers ( -CREATE TABLE public.tx_inputs ( - task_id text, - chain_id numeric, - block_hash bytea, - block_number numeric, - tx_hash bytea, - tx_index numeric, - tx_signer bytea, - tx_to bytea, - tx_input bytea -); - - - ALTER TABLE ONLY e2pg.migrations ADD CONSTRAINT migrations_pkey PRIMARY KEY (idx, hash); diff --git a/integrations/txinputs/inputs.go b/integrations/txinputs/inputs.go deleted file mode 100644 index a0f8c258..00000000 --- a/integrations/txinputs/inputs.go +++ /dev/null @@ -1,98 +0,0 @@ -package txinputs - -import ( - "bytes" - "context" - "encoding/hex" - "fmt" - "log/slog" - "os" - - "github.com/indexsupply/x/e2pg" - "github.com/indexsupply/x/eth" - - "github.com/jackc/pgx/v5" -) - -var filterFrom, filterTo []byte - -func init() { - if f := os.Getenv("TX_FROM"); len(f) > 0 { - b, err := hex.DecodeString(f) - if err != nil { - fmt.Println("Unable to hex decode $TX_FROM") - os.Exit(1) - } - filterFrom = b - } - if t := os.Getenv("TX_TO"); len(t) > 0 { - b, err := hex.DecodeString(t) - if err != nil { - fmt.Println("Unable to hex decode $TX_TO") - os.Exit(1) - } - filterTo = b - } -} - -type integration struct { - name string -} - -var Integration = integration{ - name: "Tx Inputs", -} - -func (i integration) Events(ctx context.Context) [][]byte { return [][]byte{} } - -func (i integration) Delete(ctx context.Context, pg e2pg.PG, n uint64) error { - const q = ` - delete from tx_inputs - where task_id = $1 - and chain_id = $2 - and block_number >= $3 - ` - _, err := pg.Exec(ctx, q, e2pg.TaskID(ctx), e2pg.ChainID(ctx), n) - return err -} - -func (i integration) Insert(ctx context.Context, pg e2pg.PG, blocks []eth.Block) (int64, error) { - var rows = make([][]any, 0, 1<<8) - for bidx := range blocks { - for tidx := range blocks[bidx].Txs { - signer, err := blocks[bidx].Txs[tidx].Signer() - if err != nil { - slog.ErrorContext(ctx, "unable to deriver signer", err) - continue - } - if len(filterFrom) > 0 && !bytes.Equal(filterFrom, signer) { - continue - } - if len(filterTo) > 0 && !bytes.Equal(filterTo, blocks[bidx].Txs[tidx].To) { - continue - } - rows = append(rows, []any{ - e2pg.TaskID(ctx), - e2pg.ChainID(ctx), - blocks[bidx].Num(), - blocks[bidx].Hash(), - blocks[bidx].Txs[tidx].Hash(), - tidx, - signer, - blocks[bidx].Txs[tidx].To.Bytes(), - blocks[bidx].Txs[tidx].Data.Bytes(), - }) - } - } - return pg.CopyFrom(ctx, pgx.Identifier{"tx_inputs"}, []string{ - "task_id", - "chain_id", - "block_number", - "block_hash", - "tx_hash", - "tx_index", - "tx_signer", - "tx_to", - "tx_input", - }, pgx.CopyFromRows(rows)) -} diff --git a/integrations/txinputs/inputs_test.go b/integrations/txinputs/inputs_test.go deleted file mode 100644 index 9988b1e2..00000000 --- a/integrations/txinputs/inputs_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package txinputs - -import ( - "database/sql" - "encoding/hex" - "testing" - - "github.com/indexsupply/x/integrations/testhelper" - - "blake.io/pqx/pqxtest" - "github.com/jackc/pgx/v5/stdlib" - "kr.dev/diff" -) - -func TestMain(m *testing.M) { - sql.Register("postgres", stdlib.GetDefaultDriver()) - pqxtest.TestMain(m) -} - -func TestTransfer(t *testing.T) { - th := testhelper.New(t) - defer th.Done() - - cases := []struct { - blockNum uint64 - query string - }{ - { - 6307510, //first usdc transfer - ` - select true from tx_inputs - where block_hash = '\x755ad481c67c136fdb6daafab432257ebc2aec940019e95b72a020ec1b4041a7' - and tx_hash = '\xdc6bb2a1aff2dbb2613113984b5fbd560e582c0a4369149402d7ea83b0f5983e' - and tx_signer = '\x5B6122C109B78C6755486966148C1D70a50A47D7' - and tx_to = '\xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' - and tx_input = '\x40c10f1900000000000000000000000055fe002aeff02f77364de339a1292923a15844b80000000000000000000000000000000000000000000000000000000001312d00' - `, - }, - } - for _, tc := range cases { - th.Reset() - filterFrom, _ = hex.DecodeString("5B6122C109B78C6755486966148C1D70a50A47D7") - filterTo, _ = hex.DecodeString("A0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48") - th.Process(Integration, tc.blockNum) - var found bool - diff.Test(t, t.Errorf, nil, th.PG.QueryRow(th.Context(), tc.query).Scan(&found)) - } -}