Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix format block to handle fullTx false case #53

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions indexer/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@
Extra: []byte{},
}

// fill parent hash
if blockHeight > 1 {
parentHeader, err := e.BlockHeaderMap.Get(sdkCtx, uint64(blockHeight-1))
if err == nil {
blockHeader.ParentHash = parentHeader.Hash()
}

Check warning on line 145 in indexer/abci.go

View check run for this annotation

Codecov / codecov/patch

indexer/abci.go#L140-L145

Added lines #L140 - L145 were not covered by tests
beer-1 marked this conversation as resolved.
Show resolved Hide resolved
}

blockHash := blockHeader.Hash()
for txIndex, ethTx := range ethTxs {
txHash := ethTx.Hash()
Expand Down
47 changes: 26 additions & 21 deletions jsonrpc/backend/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,15 @@
}

txs := []*rpctypes.RPCTransaction{}
if fullTx {
err = b.app.EVMIndexer().IterateBlockTxs(queryCtx, blockNumber, func(tx *rpctypes.RPCTransaction) (bool, error) {
txs = append(txs, tx)
return false, nil
})
if err != nil {
return nil, err
}
err = b.app.EVMIndexer().IterateBlockTxs(queryCtx, blockNumber, func(tx *rpctypes.RPCTransaction) (bool, error) {
txs = append(txs, tx)
return false, nil
})
if err != nil {
return nil, err

Check warning on line 125 in jsonrpc/backend/block.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/block.go#L120-L125

Added lines #L120 - L125 were not covered by tests
beer-1 marked this conversation as resolved.
Show resolved Hide resolved
}

return formatBlock(header, txs), nil
return formatBlock(header, txs, fullTx), nil

Check warning on line 128 in jsonrpc/backend/block.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/block.go#L128

Added line #L128 was not covered by tests
beer-1 marked this conversation as resolved.
Show resolved Hide resolved
}

func (b *JSONRPCBackend) GetBlockByHash(hash common.Hash, fullTx bool) (map[string]interface{}, error) {
Expand All @@ -145,23 +143,30 @@
}

txs := []*rpctypes.RPCTransaction{}
if fullTx {
blockNumber := header.Number.Uint64()
err = b.app.EVMIndexer().IterateBlockTxs(queryCtx, blockNumber, func(tx *rpctypes.RPCTransaction) (bool, error) {
txs = append(txs, tx)
return false, nil
})
if err != nil {
return nil, err
}
blockNumber := header.Number.Uint64()
err = b.app.EVMIndexer().IterateBlockTxs(queryCtx, blockNumber, func(tx *rpctypes.RPCTransaction) (bool, error) {
txs = append(txs, tx)
return false, nil
})
if err != nil {
return nil, err

Check warning on line 152 in jsonrpc/backend/block.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/block.go#L146-L152

Added lines #L146 - L152 were not covered by tests
beer-1 marked this conversation as resolved.
Show resolved Hide resolved
}

return formatBlock(header, txs), nil
return formatBlock(header, txs, fullTx), nil

Check warning on line 155 in jsonrpc/backend/block.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/block.go#L155

Added line #L155 was not covered by tests
beer-1 marked this conversation as resolved.
Show resolved Hide resolved
}

func formatBlock(header *coretypes.Header, txs []*rpctypes.RPCTransaction) map[string]interface{} {
func formatBlock(header *coretypes.Header, txs []*rpctypes.RPCTransaction, fullTx bool) map[string]interface{} {

Check warning on line 158 in jsonrpc/backend/block.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/block.go#L158

Added line #L158 was not covered by tests
beer-1 marked this conversation as resolved.
Show resolved Hide resolved
fields := formatHeader(header)
fields["transactions"] = txs

if fullTx {
fields["transactions"] = txs
} else {
txsHashes := []common.Hash{}
for _, tx := range txs {
txsHashes = append(txsHashes, tx.Hash)
}
fields["transactions"] = txsHashes

Check warning on line 168 in jsonrpc/backend/block.go

View check run for this annotation

Codecov / codecov/patch

jsonrpc/backend/block.go#L160-L168

Added lines #L160 - L168 were not covered by tests
beer-1 marked this conversation as resolved.
Show resolved Hide resolved
}

// empty values
fields["size"] = hexutil.Uint64(0)
Expand Down
Loading