Skip to content

Commit

Permalink
Fix getBlock bug (#1418)
Browse files Browse the repository at this point in the history
* fix stateRoot rpc type

* fix stateRoot rpc type

* fix

* add bloom
  • Loading branch information
hero5512 authored Dec 9, 2022
1 parent 3b7b0b2 commit ce0b99d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
12 changes: 10 additions & 2 deletions http/ethrpc/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,11 @@ func (api *EthereumAPI) GetBlockByHash(hash common.Hash, fullTx bool) (interface
if block == nil {
return nil, nil
}
return utils2.EthBlockFromOntology(block, fullTx), nil
bloom, err := bactor.GetBloomData(block.Header.Height)
if err != nil {
return nil, err
}
return utils2.EthBlockFromOntology(block, fullTx, bloom), nil
}

func (api *EthereumAPI) GetBlockByNumber(blockNum types2.BlockNumber, fullTx bool) (interface{}, error) {
Expand All @@ -428,7 +432,11 @@ func (api *EthereumAPI) GetBlockByNumber(blockNum types2.BlockNumber, fullTx boo
if block == nil {
return nil, nil
}
return utils2.EthBlockFromOntology(block, fullTx), nil
bloom, err := bactor.GetBloomData(block.Header.Height)
if err != nil {
return nil, err
}
return utils2.EthBlockFromOntology(block, fullTx, bloom), nil
}

func (api *EthereumAPI) GetTransactionByHash(hash common.Hash) (*types2.Transaction, error) {
Expand Down
26 changes: 15 additions & 11 deletions http/ethrpc/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
types3 "github.com/ontio/ontology/http/ethrpc/types"
)

func EthBlockFromOntology(block *types.Block, fullTx bool) map[string]interface{} {
func EthBlockFromOntology(block *types.Block, fullTx bool, bloom types2.Bloom) map[string]interface{} {
if block == nil {
return nil
}
Expand All @@ -45,7 +45,7 @@ func EthBlockFromOntology(block *types.Block, fullTx bool) map[string]interface{
} else {
blockTxs = transactions
}
return FormatBlock(*block, 0, gasUsed, blockTxs)
return FormatBlock(*block, 0, gasUsed, blockTxs, bloom)
}

func RawEthBlockFromOntology(block *types.Block, bloom types2.Bloom) *types2.Block {
Expand Down Expand Up @@ -116,30 +116,34 @@ func OntTxToEthTx(tx types.Transaction, blockHash common.Hash, blockNumber, inde
return NewTransaction(eip155Tx, common.Hash(tx.Hash()), blockHash, blockNumber, index)
}

func FormatBlock(block types.Block, gasLimit uint64, gasUsed *big.Int, transactions interface{}) map[string]interface{} {
func FormatBlock(block types.Block, gasLimit uint64, gasUsed *big.Int, transactions interface{}, bloom types2.Bloom) map[string]interface{} {
size := len(block.ToArray())
header := block.Header
hash := header.Hash()
transactionsRoot := types2.EmptyRootHash
if oComm.UINT256_EMPTY != header.TransactionsRoot {
transactionsRoot = common.BytesToHash(header.TransactionsRoot[:])
}
ret := map[string]interface{}{
"number": hexutil.Uint64(header.Height),
"hash": hexutil.Bytes(hash[:]),
"parentHash": hexutil.Bytes(header.PrevBlockHash[:]),
"hash": common.BytesToHash(hash[:]),
"parentHash": common.BytesToHash(header.PrevBlockHash[:]),
"nonce": types2.BlockNonce{}, // PoW specific
"sha3Uncles": common.Hash{},
"logsBloom": types2.Bloom{},
"transactionsRoot": hexutil.Bytes(header.TransactionsRoot[:]),
"sha3Uncles": types2.EmptyUncleHash,
"logsBloom": bloom,
"transactionsRoot": transactionsRoot,
"stateRoot": common.Hash{},
"miner": common.Address{},
"mixHash": common.Hash{},
"difficulty": hexutil.Uint64(0),
"totalDifficulty": hexutil.Uint64(0),
"extraData": hexutil.Bytes{},
"size": hexutil.Uint64(size),
"gasLimit": hexutil.Uint64(gasLimit), // TODO Static gas limit
"gasLimit": hexutil.Uint64(gasLimit),
"gasUsed": (*hexutil.Big)(gasUsed),
"timestamp": hexutil.Uint64(header.Timestamp),
"uncles": []string{},
"receiptsRoot": common.Hash{},
"uncles": []common.Hash{},
"receiptsRoot": types2.EmptyRootHash,
}
if !reflect.ValueOf(transactions).IsNil() {
switch transactions.(type) {
Expand Down

0 comments on commit ce0b99d

Please sign in to comment.