Skip to content

Commit fc6fbf4

Browse files
committed
Try to resolve concerns
1 parent a580b62 commit fc6fbf4

File tree

6 files changed

+29
-16
lines changed

6 files changed

+29
-16
lines changed

arbitrum/apibackend.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,18 @@ func createRegisterAPIBackend(backend *Backend, filterConfig filters.Config, fal
150150
archiveClientsManager: archiveClientsManager,
151151
}
152152
filterSystem := filters.NewFilterSystem(backend.apiBackend, filterConfig)
153-
apis, receiptFetcher := backend.apiBackend.GetAPIs(filterSystem)
153+
apis := backend.apiBackend.GetAPIs(filterSystem)
154+
var receiptFetcher ReceiptFetcher
155+
for _, api := range apis {
156+
var ok bool
157+
receiptFetcher, ok = api.Service.(ReceiptFetcher)
158+
if ok {
159+
break
160+
}
161+
}
162+
if receiptFetcher == nil {
163+
return nil, nil, errors.New("no receipt fetcher found in APIs")
164+
}
154165
backend.stack.RegisterAPIs(apis)
155166
return filterSystem, receiptFetcher, nil
156167
}
@@ -163,8 +174,8 @@ func (a *APIBackend) SetSyncBackend(sync SyncProgressBackend) error {
163174
return nil
164175
}
165176

166-
func (a *APIBackend) GetAPIs(filterSystem *filters.FilterSystem) ([]rpc.API, ReceiptFetcher) {
167-
apis, transactionAPI := ethapi.GetAPIs(a)
177+
func (a *APIBackend) GetAPIs(filterSystem *filters.FilterSystem) []rpc.API {
178+
apis := ethapi.GetAPIs(a)
168179

169180
apis = append(apis, rpc.API{
170181
Namespace: "eth",
@@ -196,7 +207,7 @@ func (a *APIBackend) GetAPIs(filterSystem *filters.FilterSystem) ([]rpc.API, Rec
196207

197208
apis = append(apis, tracers.APIs(a)...)
198209

199-
return apis, transactionAPI
210+
return apis
200211
}
201212

202213
func (a *APIBackend) BlockChain() *core.BlockChain {

common/types.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,14 @@ type BlockMetadata []byte
495495
// starting from the second byte, (N)th bit would represent if (N)th tx is timeboosted or not, 1 means yes and 0 means no
496496
// blockMetadata[index / 8 + 1] & (1 << (index % 8)) != 0; where index = (N - 1), implies whether (N)th tx in a block is timeboosted
497497
// note that number of txs in a block will always lag behind (len(blockMetadata) - 1) * 8 but it wont lag more than a value of 7
498-
func (b BlockMetadata) IsTxTimeboosted(txIndex uint64) (bool, error) {
498+
func (b BlockMetadata) IsTxTimeboosted(txIndex int) (bool, error) {
499499
if len(b) == 0 {
500500
return false, errors.New("blockMetadata is not set")
501501
}
502-
maxTxCount := (uint64(len(b)) - 1) * 8
502+
if txIndex < 0 {
503+
return false, fmt.Errorf("invalid transaction index- %d, should be positive", txIndex)
504+
}
505+
maxTxCount := (len(b) - 1) * 8
503506
if txIndex >= maxTxCount {
504507
return false, nil
505508
}

eth/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ func makeExtraData(extra []byte) []byte {
394394
// APIs return the collection of RPC services the ethereum package offers.
395395
// NOTE, some of these services probably need to be moved to somewhere else.
396396
func (s *Ethereum) APIs() []rpc.API {
397-
apis, _ := ethapi.GetAPIs(s.APIBackend)
397+
apis := ethapi.GetAPIs(s.APIBackend)
398398

399399
// Append all the local APIs and return
400400
return append(apis, []rpc.API{

eth/filters/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ func (api *FilterAPI) TransactionReceipts(ctx context.Context, filter *Transacti
370370
receiptWithTx.Receipt.BlockNumber.Uint64(),
371371
signer,
372372
receiptWithTx.Transaction,
373-
uint64(receiptWithTx.Receipt.TransactionIndex),
373+
int(receiptWithTx.Receipt.TransactionIndex),
374374
api.events.backend.ChainConfig(),
375375
header,
376376
blockMetadata,

internal/ethapi/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ func (api *BlockChainAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rp
657657
if err != nil {
658658
return nil, err
659659
}
660-
result[i] = MarshalReceipt(receipt, block.Hash(), block.NumberU64(), signer, txs[i], uint64(i), api.b.ChainConfig(), header, blockMetadata)
660+
result[i] = MarshalReceipt(receipt, block.Hash(), block.NumberU64(), signer, txs[i], i, api.b.ChainConfig(), header, blockMetadata)
661661
}
662662
return result, nil
663663
}
@@ -1758,11 +1758,11 @@ func (api *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash commo
17581758
if err != nil {
17591759
return nil, err
17601760
}
1761-
return MarshalReceipt(receipt, blockHash, blockNumber, signer, tx, index, api.b.ChainConfig(), header, blockMetadata), nil
1761+
return MarshalReceipt(receipt, blockHash, blockNumber, signer, tx, int(index), api.b.ChainConfig(), header, blockMetadata), nil
17621762
}
17631763

17641764
// MarshalReceipt marshals a transaction receipt into a JSON object.
1765-
func MarshalReceipt(receipt *types.Receipt, blockHash common.Hash, blockNumber uint64, signer types.Signer, tx *types.Transaction, txIndex uint64, chainConfig *params.ChainConfig, header *types.Header, blockMetadata common.BlockMetadata) map[string]interface{} {
1765+
func MarshalReceipt(receipt *types.Receipt, blockHash common.Hash, blockNumber uint64, signer types.Signer, tx *types.Transaction, txIndex int, chainConfig *params.ChainConfig, header *types.Header, blockMetadata common.BlockMetadata) map[string]interface{} {
17661766
from, _ := types.Sender(signer, tx)
17671767

17681768
fields := map[string]interface{}{
@@ -2062,7 +2062,7 @@ func (api *TransactionAPI) SendRawTransactionSync(ctx context.Context, input hex
20622062
rs[i].BlockNumber.Uint64(),
20632063
signer,
20642064
txs[i],
2065-
uint64(rs[i].TransactionIndex),
2065+
int(rs[i].TransactionIndex),
20662066
api.b.ChainConfig(),
20672067
header,
20682068
blockMetadata,

internal/ethapi/backend.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ type Backend interface {
108108
NewMatcherBackend() filtermaps.MatcherBackend
109109
}
110110

111-
func GetAPIs(apiBackend Backend) ([]rpc.API, *TransactionAPI) {
111+
func GetAPIs(apiBackend Backend) []rpc.API {
112112
nonceLock := new(AddrLocker)
113-
transactionAPI := NewTransactionAPI(apiBackend, nonceLock)
114113
return []rpc.API{
115114
{
116115
Namespace: "eth",
@@ -120,7 +119,7 @@ func GetAPIs(apiBackend Backend) ([]rpc.API, *TransactionAPI) {
120119
Service: NewBlockChainAPI(apiBackend),
121120
}, {
122121
Namespace: "eth",
123-
Service: transactionAPI,
122+
Service: NewTransactionAPI(apiBackend, nonceLock),
124123
}, {
125124
Namespace: "txpool",
126125
Service: NewTxPoolAPI(apiBackend),
@@ -131,5 +130,5 @@ func GetAPIs(apiBackend Backend) ([]rpc.API, *TransactionAPI) {
131130
Namespace: "eth",
132131
Service: NewEthereumAccountAPI(apiBackend.AccountManager()),
133132
},
134-
}, transactionAPI
133+
}
135134
}

0 commit comments

Comments
 (0)