Skip to content

Commit 92eed1c

Browse files
authored
Merge pull request #808 from weifangc/main
other: replace interface{} with any for clarity and modernization
2 parents 3c0ee79 + 909e37b commit 92eed1c

File tree

19 files changed

+81
-81
lines changed

19 files changed

+81
-81
lines changed

db/migrations/20220109122505_logs.up.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (s *Storage) InsertLogs(ctx context.Context, values []*Log) error {
128128
}
129129

130130
// Upsert upserts a value.
131-
func (s *Storage) Upsert(ctx context.Context, value interface{}) error {
131+
func (s *Storage) Upsert(ctx context.Context, value any) error {
132132
typ := reflect.TypeOf(value)
133133
table := s.DB.Dialect().Tables().Get(typ)
134134
pks := make([]string, len(table.PKs))

db/migrations/migrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func DropTables(ctx context.Context, db *bun.DB) error {
3434
return err
3535
}
3636

37-
var results []map[string]interface{}
37+
var results []map[string]any
3838
if err = db.ScanRows(ctx, rows, &results); err != nil {
3939
return err
4040
}

indexer/backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type GetEthInfoBackend interface {
6363
GetBlockTransactionCountByRound(ctx context.Context, round uint64) (int, error)
6464
GetBlockTransactionCountByHash(ctx context.Context, blockHash ethcommon.Hash) (int, error)
6565
GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash ethcommon.Hash, txIndex int) (*model.Transaction, error)
66-
GetTransactionReceipt(ctx context.Context, txHash ethcommon.Hash) (map[string]interface{}, error)
66+
GetTransactionReceipt(ctx context.Context, txHash ethcommon.Hash) (map[string]any, error)
6767
BlockNumber(ctx context.Context) (uint64, error)
6868
GetLogs(ctx context.Context, startRound, endRound uint64) ([]*model.Log, error)
6969
}
@@ -320,7 +320,7 @@ func (ib *indexBackend) GetTransactionByBlockHashAndIndex(ctx context.Context, b
320320
}
321321

322322
// GetTransactionReceipt returns the receipt for the given tx.
323-
func (ib *indexBackend) GetTransactionReceipt(ctx context.Context, txHash ethcommon.Hash) (map[string]interface{}, error) {
323+
func (ib *indexBackend) GetTransactionReceipt(ctx context.Context, txHash ethcommon.Hash) (map[string]any, error) {
324324
dbReceipt, err := ib.storage.GetTransactionReceipt(ctx, txHash.String())
325325
if err != nil {
326326
return nil, err

indexer/backend_cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (cb *CachingBackend) OnBlockIndexed(
143143
// need to be all that large to service the vast majority of
144144
// requests.
145145
rounds := make([]uint64, 0, cb.cacheSize)
146-
cb.blockDataByNumber.Range(func(key, _ interface{}) bool {
146+
cb.blockDataByNumber.Range(func(key, _ any) bool {
147147
rounds = append(rounds, key.(uint64))
148148
return true
149149
})
@@ -346,7 +346,7 @@ func (cb *CachingBackend) GetTransactionByBlockHashAndIndex(
346346
func (cb *CachingBackend) GetTransactionReceipt(
347347
ctx context.Context,
348348
txHash ethcommon.Hash,
349-
) (map[string]interface{}, error) {
349+
) (map[string]any, error) {
350350
if receipt, ok := cb.cachedReceiptByTxHash(txHash); ok {
351351
return db2EthReceipt(receipt), nil
352352
}

indexer/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ func (ib *indexBackend) StoreBlockData(ctx context.Context, oasisBlock *block.Bl
547547
}
548548

549549
// db2EthReceipt converts model.Receipt to the GetTransactionReceipt format.
550-
func db2EthReceipt(dbReceipt *model.Receipt) map[string]interface{} {
550+
func db2EthReceipt(dbReceipt *model.Receipt) map[string]any {
551551
ethLogs := make([]*ethtypes.Log, 0, len(dbReceipt.Logs))
552552
for _, dbLog := range dbReceipt.Logs {
553553
topics := make([]common.Hash, 0, len(dbLog.Topics))
@@ -573,7 +573,7 @@ func db2EthReceipt(dbReceipt *model.Receipt) map[string]interface{} {
573573
}
574574

575575
effectiveGasPrice, _ := new(big.Int).SetString(dbReceipt.EffectiveGasPrice, 10)
576-
receipt := map[string]interface{}{
576+
receipt := map[string]any{
577577
"status": hexutil.Uint(dbReceipt.Status),
578578
"cumulativeGasUsed": hexutil.Uint64(dbReceipt.CumulativeGasUsed),
579579
"logsBloom": ethtypes.BytesToBloom(logsBloom(ethLogs)),

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ var (
7272
)
7373

7474
func initVersions() {
75-
cobra.AddTemplateFunc("toolchain", func() interface{} { return version.Toolchain })
76-
cobra.AddTemplateFunc("sdk", func() interface{} { return version.GetOasisSDKVersion() })
75+
cobra.AddTemplateFunc("toolchain", func() any { return version.Toolchain })
76+
cobra.AddTemplateFunc("sdk", func() any { return version.GetOasisSDKVersion() })
7777

7878
rootCmd.SetVersionTemplate(`Software version: {{.Version}}
7979
Oasis SDK version: {{ sdk }}

rpc/eth/api.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var (
5454
// API is the eth_ prefixed set of APIs in the Web3 JSON-RPC spec.
5555
type API interface {
5656
// GetBlockByNumber returns the block identified by number.
57-
GetBlockByNumber(ctx context.Context, blockNum ethrpc.BlockNumber, fullTx bool) (map[string]interface{}, error)
57+
GetBlockByNumber(ctx context.Context, blockNum ethrpc.BlockNumber, fullTx bool) (map[string]any, error)
5858
// GetBlockTransactionCountByNumber returns the number of transactions in the block.
5959
GetBlockTransactionCountByNumber(ctx context.Context, blockNum ethrpc.BlockNumber) (hexutil.Uint, error)
6060
// GetStorageAt returns the storage value at the provided position.
@@ -82,15 +82,15 @@ type API interface {
8282
// EstimateGas returns an estimate of gas usage for the given transaction.
8383
EstimateGas(ctx context.Context, args utils.TransactionArgs, blockNum *ethrpc.BlockNumber) (hexutil.Uint64, error)
8484
// GetBlockByHash returns the block identified by hash.
85-
GetBlockByHash(ctx context.Context, blockHash common.Hash, fullTx bool) (map[string]interface{}, error)
85+
GetBlockByHash(ctx context.Context, blockHash common.Hash, fullTx bool) (map[string]any, error)
8686
// GetTransactionByHash returns the transaction identified by hash.
8787
GetTransactionByHash(ctx context.Context, hash common.Hash) (*utils.RPCTransaction, error)
8888
// GetTransactionByBlockHashAndIndex returns the transaction for the given block hash and index.
8989
GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index hexutil.Uint) (*utils.RPCTransaction, error)
9090
// GetTransactionByBlockNumberAndIndex returns the transaction identified by number and index.
9191
GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNum ethrpc.BlockNumber, index hexutil.Uint) (*utils.RPCTransaction, error)
9292
// GetTransactionReceipt returns the transaction receipt by hash.
93-
GetTransactionReceipt(ctx context.Context, txHash common.Hash) (map[string]interface{}, error)
93+
GetTransactionReceipt(ctx context.Context, txHash common.Hash) (map[string]any, error)
9494
// GetLogs returns the ethereum logs.
9595
GetLogs(ctx context.Context, filter filters.FilterCriteria) ([]*ethtypes.Log, error)
9696
// GetBlockHash returns the block hash by the given number.
@@ -105,7 +105,7 @@ type API interface {
105105
Hashrate() hexutil.Uint64
106106
// Syncing returns false in case the node is currently not syncing with the network, otherwise
107107
// returns syncing information.
108-
Syncing(ctx context.Context) (interface{}, error)
108+
Syncing(ctx context.Context) (any, error)
109109
}
110110

111111
type publicAPI struct {
@@ -195,7 +195,7 @@ func (api *publicAPI) roundParamFromBlockNum(ctx context.Context, logger *loggin
195195
}
196196
}
197197

198-
func (api *publicAPI) GetBlockByNumber(ctx context.Context, blockNum ethrpc.BlockNumber, fullTx bool) (map[string]interface{}, error) {
198+
func (api *publicAPI) GetBlockByNumber(ctx context.Context, blockNum ethrpc.BlockNumber, fullTx bool) (map[string]any, error) {
199199
logger := api.Logger.With("method", "eth_getBlockByNumber", "block_number", blockNum, "full_tx", fullTx)
200200
logger.Debug("request")
201201

@@ -542,7 +542,7 @@ func (api *publicAPI) EstimateGas(ctx context.Context, args utils.TransactionArg
542542
return hexutil.Uint64(gas), nil
543543
}
544544

545-
func (api *publicAPI) GetBlockByHash(ctx context.Context, blockHash common.Hash, fullTx bool) (map[string]interface{}, error) {
545+
func (api *publicAPI) GetBlockByHash(ctx context.Context, blockHash common.Hash, fullTx bool) (map[string]any, error) {
546546
logger := api.Logger.With("method", "eth_getBlockByHash", "block_hash", blockHash, "full_tx", fullTx)
547547
logger.Debug("request")
548548

@@ -598,7 +598,7 @@ func (api *publicAPI) GetTransactionByBlockNumberAndIndex(ctx context.Context, b
598598
return api.GetTransactionByBlockHashAndIndex(ctx, blockHash, index)
599599
}
600600

601-
func (api *publicAPI) GetTransactionReceipt(ctx context.Context, txHash common.Hash) (map[string]interface{}, error) {
601+
func (api *publicAPI) GetTransactionReceipt(ctx context.Context, txHash common.Hash) (map[string]any, error) {
602602
logger := api.Logger.With("method", "eth_getTransactionReceipt", "hash", txHash)
603603
logger.Debug("request")
604604

@@ -769,7 +769,7 @@ func (api *publicAPI) Hashrate() hexutil.Uint64 {
769769
return 0
770770
}
771771

772-
func (api *publicAPI) Syncing(_ context.Context) (interface{}, error) {
772+
func (api *publicAPI) Syncing(_ context.Context) (any, error) {
773773
logger := api.Logger.With("method", "eth_syncing")
774774
logger.Debug("request")
775775

rpc/eth/metrics/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (m *metricsWrapper) GetBalance(ctx context.Context, address common.Address,
211211
}
212212

213213
// GetBlockByHash implements eth.API.
214-
func (m *metricsWrapper) GetBlockByHash(ctx context.Context, blockHash common.Hash, fullTx bool) (res map[string]interface{}, err error) {
214+
func (m *metricsWrapper) GetBlockByHash(ctx context.Context, blockHash common.Hash, fullTx bool) (res map[string]any, err error) {
215215
r, s, f, i, d := metrics.GetAPIMethodMetrics("eth_getBlockByHash")
216216
defer metrics.InstrumentCaller(r, s, f, i, d, &err)()
217217

@@ -220,7 +220,7 @@ func (m *metricsWrapper) GetBlockByHash(ctx context.Context, blockHash common.Ha
220220
}
221221

222222
// GetBlockByNumber implements eth.API.
223-
func (m *metricsWrapper) GetBlockByNumber(ctx context.Context, blockNum ethrpc.BlockNumber, fullTx bool) (res map[string]interface{}, err error) {
223+
func (m *metricsWrapper) GetBlockByNumber(ctx context.Context, blockNum ethrpc.BlockNumber, fullTx bool) (res map[string]any, err error) {
224224
r, s, f, i, d := metrics.GetAPIMethodMetrics("eth_getBlockByNumber")
225225
defer metrics.InstrumentCaller(r, s, f, i, d, &err)()
226226

@@ -335,7 +335,7 @@ func (m *metricsWrapper) GetTransactionCount(ctx context.Context, ethAddr common
335335
}
336336

337337
// GetTransactionReceipt implements eth.API.
338-
func (m *metricsWrapper) GetTransactionReceipt(ctx context.Context, txHash common.Hash) (res map[string]interface{}, err error) {
338+
func (m *metricsWrapper) GetTransactionReceipt(ctx context.Context, txHash common.Hash) (res map[string]any, err error) {
339339
r, s, f, i, d := metrics.GetAPIMethodMetrics("eth_getTransactionReceipt")
340340
defer metrics.InstrumentCaller(r, s, f, i, d, &err)()
341341

@@ -369,7 +369,7 @@ func (m *metricsWrapper) SendRawTransaction(ctx context.Context, data hexutil.By
369369
}
370370

371371
// Syncing implements eth.API.
372-
func (m *metricsWrapper) Syncing(ctx context.Context) (res interface{}, err error) {
372+
func (m *metricsWrapper) Syncing(ctx context.Context) (res any, err error) {
373373
r, s, f, i, d := metrics.GetAPIMethodMetrics("eth_syncing")
374374
defer metrics.InstrumentCaller(r, s, f, i, d, &err)()
375375

rpc/eth/revert_errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type revertError struct {
2525
}
2626

2727
// ErrorData returns the hex encoded error reason.
28-
func (e *revertError) ErrorData() interface{} {
28+
func (e *revertError) ErrorData() any {
2929
return e.reason
3030
}
3131

rpc/txpool/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package txpool
44
// API is the txpool_ prefixed set of APIs in the Web3 JSON-RPC spec.
55
type API interface {
66
// Content returns the (always empty) contents of the txpool.
7-
Content() (map[string][]interface{}, error)
7+
Content() (map[string][]any, error)
88
}
99

1010
type publicAPI struct{}
@@ -14,8 +14,8 @@ func NewPublicAPI() API {
1414
return &publicAPI{}
1515
}
1616

17-
func (api *publicAPI) Content() (map[string][]interface{}, error) {
18-
m := make(map[string][]interface{})
19-
m["pending"] = []interface{}{}
17+
func (api *publicAPI) Content() (map[string][]any, error) {
18+
m := make(map[string][]any)
19+
m["pending"] = []any{}
2020
return m, nil
2121
}

0 commit comments

Comments
 (0)