Skip to content

Commit 9a67034

Browse files
committed
linting fixes
1 parent 5f4968b commit 9a67034

File tree

11 files changed

+52
-87
lines changed

11 files changed

+52
-87
lines changed

statediff/indexer/database/dump/indexer.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,7 @@ func (sdi *StateDiffIndexer) processReceiptsAndTxs(tx *BatchTx, args processArgs
315315
Data: trx.Data(),
316316
CID: txNode.Cid().String(),
317317
MhKey: shared.MultihashKeyFromCID(txNode.Cid()),
318-
}
319-
txType := trx.Type()
320-
if txType != types.LegacyTxType {
321-
txModel.Type = &txType
318+
Type: trx.Type(),
322319
}
323320
if _, err := fmt.Fprintf(sdi.dump, "%+v\r\n", txModel); err != nil {
324321
return err

statediff/indexer/database/sql/indexer.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,7 @@ func (sdi *StateDiffIndexer) processReceiptsAndTxs(tx *BatchTx, args processArgs
366366
Data: trx.Data(),
367367
CID: txNode.Cid().String(),
368368
MhKey: shared.MultihashKeyFromCID(txNode.Cid()),
369-
}
370-
txType := trx.Type()
371-
if txType != types.LegacyTxType {
372-
txModel.Type = &txType
369+
Type: trx.Type(),
373370
}
374371
txID, err := sdi.dbWriter.upsertTransactionCID(tx.dbtx, txModel, args.headerID)
375372
if err != nil {

statediff/indexer/database/sql/interfaces.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ type Tx interface {
6767
// ScannableRow interface to accommodate different concrete row types
6868
type ScannableRow interface {
6969
Scan(dest ...interface{}) error
70-
StructScan(dest interface{}) error
7170
}
7271

7372
// Result interface to accommodate different concrete result types

statediff/indexer/database/sql/pgx_indexer_legacy_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"testing"
2222

23+
"github.com/jmoiron/sqlx"
2324
"github.com/multiformats/go-multihash"
2425
"github.com/stretchr/testify/require"
2526

@@ -76,7 +77,7 @@ func TestPGXIndexerLegacy(t *testing.T) {
7677
}
7778
header := new(res)
7879

79-
err = db.QueryRow(context.Background(), pgStr, legacyData.BlockNumber.Uint64()).StructScan(header)
80+
err = db.QueryRow(context.Background(), pgStr, legacyData.BlockNumber.Uint64()).(*sqlx.Row).StructScan(header)
8081
require.NoError(t, err)
8182

8283
test_helpers.ExpectEqual(t, header.CID, legacyHeaderCID.String())

statediff/indexer/database/sql/pgx_indexer_test.go

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/ipfs/go-cid"
2727
blockstore "github.com/ipfs/go-ipfs-blockstore"
2828
dshelp "github.com/ipfs/go-ipfs-ds-help"
29+
"github.com/jmoiron/sqlx"
2930
"github.com/multiformats/go-multihash"
3031
"github.com/stretchr/testify/require"
3132

@@ -164,7 +165,7 @@ func TestPGXIndexer(t *testing.T) {
164165
BaseFee *int64 `db:"base_fee"`
165166
}
166167
header := new(res)
167-
err = db.QueryRow(context.Background(), pgStr, mocks.BlockNumber.Uint64()).StructScan(header)
168+
err = db.QueryRow(context.Background(), pgStr, mocks.BlockNumber.Uint64()).(*sqlx.Row).StructScan(header)
168169
if err != nil {
169170
t.Fatal(err)
170171
}
@@ -216,12 +217,12 @@ func TestPGXIndexer(t *testing.T) {
216217
if err != nil {
217218
t.Fatal(err)
218219
}
220+
txTypePgStr := `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
219221
switch c {
220222
case trx1CID.String():
221223
test_helpers.ExpectEqual(t, data, tx1)
222224
var txType *uint8
223-
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
224-
err = db.Get(context.Background(), &txType, pgStr, c)
225+
err = db.Get(context.Background(), &txType, txTypePgStr, c)
225226
if err != nil {
226227
t.Fatal(err)
227228
}
@@ -231,8 +232,7 @@ func TestPGXIndexer(t *testing.T) {
231232
case trx2CID.String():
232233
test_helpers.ExpectEqual(t, data, tx2)
233234
var txType *uint8
234-
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
235-
err = db.Get(context.Background(), &txType, pgStr, c)
235+
err = db.Get(context.Background(), &txType, txTypePgStr, c)
236236
if err != nil {
237237
t.Fatal(err)
238238
}
@@ -242,8 +242,7 @@ func TestPGXIndexer(t *testing.T) {
242242
case trx3CID.String():
243243
test_helpers.ExpectEqual(t, data, tx3)
244244
var txType *uint8
245-
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
246-
err = db.Get(context.Background(), &txType, pgStr, c)
245+
err = db.Get(context.Background(), &txType, txTypePgStr, c)
247246
if err != nil {
248247
t.Fatal(err)
249248
}
@@ -253,8 +252,7 @@ func TestPGXIndexer(t *testing.T) {
253252
case trx4CID.String():
254253
test_helpers.ExpectEqual(t, data, tx4)
255254
var txType *uint8
256-
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
257-
err = db.Get(context.Background(), &txType, pgStr, c)
255+
err = db.Get(context.Background(), &txType, txTypePgStr, c)
258256
if err != nil {
259257
t.Fatal(err)
260258
}
@@ -284,8 +282,7 @@ func TestPGXIndexer(t *testing.T) {
284282
case trx5CID.String():
285283
test_helpers.ExpectEqual(t, data, tx5)
286284
var txType *uint8
287-
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
288-
err = db.Get(context.Background(), &txType, pgStr, c)
285+
err = db.Get(context.Background(), &txType, txTypePgStr, c)
289286
if err != nil {
290287
t.Fatal(err)
291288
}
@@ -398,6 +395,7 @@ func TestPGXIndexer(t *testing.T) {
398395
t.Fatal(err)
399396
}
400397

398+
postStatePgStr := `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
401399
switch c {
402400
case rct1CID.String():
403401
test_helpers.ExpectEqual(t, data, rct1)
@@ -411,35 +409,31 @@ func TestPGXIndexer(t *testing.T) {
411409
case rct2CID.String():
412410
test_helpers.ExpectEqual(t, data, rct2)
413411
var postState string
414-
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
415-
err = db.Get(context.Background(), &postState, pgStr, c)
412+
err = db.Get(context.Background(), &postState, postStatePgStr, c)
416413
if err != nil {
417414
t.Fatal(err)
418415
}
419416
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState1)
420417
case rct3CID.String():
421418
test_helpers.ExpectEqual(t, data, rct3)
422419
var postState string
423-
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
424-
err = db.Get(context.Background(), &postState, pgStr, c)
420+
err = db.Get(context.Background(), &postState, postStatePgStr, c)
425421
if err != nil {
426422
t.Fatal(err)
427423
}
428424
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState2)
429425
case rct4CID.String():
430426
test_helpers.ExpectEqual(t, data, rct4)
431427
var postState string
432-
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
433-
err = db.Get(context.Background(), &postState, pgStr, c)
428+
err = db.Get(context.Background(), &postState, postStatePgStr, c)
434429
if err != nil {
435430
t.Fatal(err)
436431
}
437432
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState3)
438433
case rct5CID.String():
439434
test_helpers.ExpectEqual(t, data, rct5)
440435
var postState string
441-
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
442-
err = db.Get(context.Background(), &postState, pgStr, c)
436+
err = db.Get(context.Background(), &postState, postStatePgStr, c)
443437
if err != nil {
444438
t.Fatal(err)
445439
}

statediff/indexer/database/sql/postgres/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"github.com/ethereum/go-ethereum/statediff/indexer/shared"
2525
)
2626

27-
// DriverType to explicity type the kind of sql driver we are using
27+
// DriverType to explicitly type the kind of sql driver we are using
2828
type DriverType string
2929

3030
const (

statediff/indexer/database/sql/postgres/pgx.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ func (pgx *PGXDriver) createNode() error {
105105

106106
// QueryRow satisfies sql.Database
107107
func (pgx *PGXDriver) QueryRow(ctx context.Context, sql string, args ...interface{}) sql.ScannableRow {
108-
rows, _ := pgx.pool.Query(ctx, sql, args...)
109-
return rowsWrapper{rows: rows}
108+
return pgx.pool.QueryRow(ctx, sql, args...)
110109
}
111110

112111
// Exec satisfies sql.Database
@@ -160,20 +159,6 @@ func (pgx *PGXDriver) Context() context.Context {
160159
return pgx.ctx
161160
}
162161

163-
type rowsWrapper struct {
164-
rows pgx.Rows
165-
}
166-
167-
// Scan satisfies sql.ScannableRow
168-
func (r rowsWrapper) Scan(dest ...interface{}) error {
169-
return (pgx.Row)(r.rows).Scan(dest...)
170-
}
171-
172-
// StructScan satisfies sql.ScannableRow
173-
func (r rowsWrapper) StructScan(dest interface{}) error {
174-
return pgxscan.ScanRow(dest, r.rows)
175-
}
176-
177162
type resultWrapper struct {
178163
ct pgconn.CommandTag
179164
}
@@ -234,8 +219,7 @@ type pgxTxWrapper struct {
234219

235220
// QueryRow satisfies sql.Tx
236221
func (t pgxTxWrapper) QueryRow(ctx context.Context, sql string, args ...interface{}) sql.ScannableRow {
237-
rows, _ := t.tx.Query(ctx, sql, args...)
238-
return rowsWrapper{rows: rows}
222+
return t.tx.QueryRow(ctx, sql, args...)
239223
}
240224

241225
// Exec satisfies sql.Tx

statediff/indexer/database/sql/sqlx_indexer_legacy_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ import (
2020
"context"
2121
"testing"
2222

23-
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
24-
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
25-
2623
"github.com/ipfs/go-cid"
24+
"github.com/jmoiron/sqlx"
2725
"github.com/multiformats/go-multihash"
2826
"github.com/stretchr/testify/require"
2927

3028
"github.com/ethereum/go-ethereum/core/types"
3129
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql"
30+
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
31+
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
3232
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
3333
"github.com/ethereum/go-ethereum/statediff/indexer/mocks"
3434
"github.com/ethereum/go-ethereum/statediff/indexer/test_helpers"
@@ -85,7 +85,7 @@ func TestSQLXIndexerLegacy(t *testing.T) {
8585
BaseFee *int64 `db:"base_fee"`
8686
}
8787
header := new(res)
88-
err = db.QueryRow(context.Background(), pgStr, legacyData.BlockNumber.Uint64()).StructScan(header)
88+
err = db.QueryRow(context.Background(), pgStr, legacyData.BlockNumber.Uint64()).(*sqlx.Row).StructScan(header)
8989
require.NoError(t, err)
9090

9191
test_helpers.ExpectEqual(t, header.CID, legacyHeaderCID.String())

statediff/indexer/database/sql/sqlx_indexer_test.go

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/ipfs/go-cid"
2727
blockstore "github.com/ipfs/go-ipfs-blockstore"
2828
dshelp "github.com/ipfs/go-ipfs-ds-help"
29+
"github.com/jmoiron/sqlx"
2930
"github.com/multiformats/go-multihash"
3031
"github.com/stretchr/testify/require"
3132

@@ -190,7 +191,7 @@ func TestSQLXIndexer(t *testing.T) {
190191
BaseFee *int64 `db:"base_fee"`
191192
}
192193
header := new(res)
193-
err = db.QueryRow(context.Background(), pgStr, mocks.BlockNumber.Uint64()).StructScan(header)
194+
err = db.QueryRow(context.Background(), pgStr, mocks.BlockNumber.Uint64()).(*sqlx.Row).StructScan(header)
194195
if err != nil {
195196
t.Fatal(err)
196197
}
@@ -242,50 +243,47 @@ func TestSQLXIndexer(t *testing.T) {
242243
if err != nil {
243244
t.Fatal(err)
244245
}
246+
txTypePgStr := `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
245247
switch c {
246248
case trx1CID.String():
247249
test_helpers.ExpectEqual(t, data, tx1)
248-
var txType *uint8
249-
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
250-
err = db.Get(context.Background(), &txType, pgStr, c)
250+
var txType uint8
251+
err = db.Get(context.Background(), &txType, txTypePgStr, c)
251252
if err != nil {
252253
t.Fatal(err)
253254
}
254-
if txType != nil {
255-
t.Fatalf("expected nil tx_type, got %d", *txType)
255+
if txType != 0 {
256+
t.Fatalf("expected LegacyTxType (0), got %d", txType)
256257
}
257258
case trx2CID.String():
258259
test_helpers.ExpectEqual(t, data, tx2)
259-
var txType *uint8
260-
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
261-
err = db.Get(context.Background(), &txType, pgStr, c)
260+
var txType uint8
261+
err = db.Get(context.Background(), &txType, txTypePgStr, c)
262262
if err != nil {
263263
t.Fatal(err)
264264
}
265-
if txType != nil {
266-
t.Fatalf("expected nil tx_type, got %d", *txType)
265+
if txType != 0 {
266+
t.Fatalf("expected LegacyTxType (0), got %d", txType)
267267
}
268268
case trx3CID.String():
269269
test_helpers.ExpectEqual(t, data, tx3)
270-
var txType *uint8
271-
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
272-
err = db.Get(context.Background(), &txType, pgStr, c)
270+
var txType uint8
271+
err = db.Get(context.Background(), &txType, txTypePgStr, c)
273272
if err != nil {
274273
t.Fatal(err)
275274
}
276-
if txType != nil {
277-
t.Fatalf("expected nil tx_type, got %d", *txType)
275+
if txType != 0 {
276+
t.Fatalf("expected LegacyTxType (0), got %d", txType)
278277
}
279278
case trx4CID.String():
280279
test_helpers.ExpectEqual(t, data, tx4)
281-
var txType *uint8
282-
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
283-
err = db.Get(context.Background(), &txType, pgStr, c)
280+
var txType uint8
281+
err = db.Get(context.Background(), &txType, txTypePgStr, c)
284282
if err != nil {
285283
t.Fatal(err)
286284
}
287-
if *txType != types.AccessListTxType {
288-
t.Fatalf("expected AccessListTxType (1), got %d", *txType)
285+
if txType != types.AccessListTxType {
286+
t.Fatalf("expected AccessListTxType (1), got %d", txType)
289287
}
290288
accessListElementModels := make([]models.AccessListElementModel, 0)
291289
pgStr = `SELECT access_list_element.* FROM eth.access_list_element INNER JOIN eth.transaction_cids ON (tx_id = transaction_cids.id) WHERE cid = $1 ORDER BY access_list_element.index ASC`
@@ -310,8 +308,7 @@ func TestSQLXIndexer(t *testing.T) {
310308
case trx5CID.String():
311309
test_helpers.ExpectEqual(t, data, tx5)
312310
var txType *uint8
313-
pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1`
314-
err = db.Get(context.Background(), &txType, pgStr, c)
311+
err = db.Get(context.Background(), &txType, txTypePgStr, c)
315312
if err != nil {
316313
t.Fatal(err)
317314
}
@@ -423,7 +420,7 @@ func TestSQLXIndexer(t *testing.T) {
423420
if err != nil {
424421
t.Fatal(err)
425422
}
426-
423+
postStatePgStr := `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
427424
switch c {
428425
case rct1CID.String():
429426
test_helpers.ExpectEqual(t, data, rct1)
@@ -437,35 +434,31 @@ func TestSQLXIndexer(t *testing.T) {
437434
case rct2CID.String():
438435
test_helpers.ExpectEqual(t, data, rct2)
439436
var postState string
440-
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
441-
err = db.Get(context.Background(), &postState, pgStr, c)
437+
err = db.Get(context.Background(), &postState, postStatePgStr, c)
442438
if err != nil {
443439
t.Fatal(err)
444440
}
445441
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState1)
446442
case rct3CID.String():
447443
test_helpers.ExpectEqual(t, data, rct3)
448444
var postState string
449-
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
450-
err = db.Get(context.Background(), &postState, pgStr, c)
445+
err = db.Get(context.Background(), &postState, postStatePgStr, c)
451446
if err != nil {
452447
t.Fatal(err)
453448
}
454449
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState2)
455450
case rct4CID.String():
456451
test_helpers.ExpectEqual(t, data, rct4)
457452
var postState string
458-
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
459-
err = db.Get(context.Background(), &postState, pgStr, c)
453+
err = db.Get(context.Background(), &postState, postStatePgStr, c)
460454
if err != nil {
461455
t.Fatal(err)
462456
}
463457
test_helpers.ExpectEqual(t, postState, mocks.ExpectedPostState3)
464458
case rct5CID.String():
465459
test_helpers.ExpectEqual(t, data, rct5)
466460
var postState string
467-
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
468-
err = db.Get(context.Background(), &postState, pgStr, c)
461+
err = db.Get(context.Background(), &postState, postStatePgStr, c)
469462
if err != nil {
470463
t.Fatal(err)
471464
}

statediff/indexer/models/models.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type TxModel struct {
6767
Dst string `db:"dst"`
6868
Src string `db:"src"`
6969
Data []byte `db:"tx_data"`
70-
Type *uint8 `db:"tx_type"`
70+
Type uint8 `db:"tx_type"`
7171
}
7272

7373
// AccessListElementModel is the db model for eth.access_list_entry

0 commit comments

Comments
 (0)