diff --git a/core/store/ledgerstore/state_store.go b/core/store/ledgerstore/state_store.go index b67d513ec..fbeb5bfd6 100644 --- a/core/store/ledgerstore/state_store.go +++ b/core/store/ledgerstore/state_store.go @@ -328,6 +328,9 @@ func (self *StateStore) GetEthState(addr common2.Address, stateKey common2.Hash) key := genStateKey(addr, stateKey) value, err := self.store.Get(key) if err != nil { + if err == scom.ErrNotFound { + return nil, nil + } return nil, err } return value, nil diff --git a/http/ethrpc/eth/api.go b/http/ethrpc/eth/api.go index 2e0ff2bd7..b9564b4f3 100644 --- a/http/ethrpc/eth/api.go +++ b/http/ethrpc/eth/api.go @@ -36,6 +36,7 @@ import ( "github.com/ontio/ontology/common/log" "github.com/ontio/ontology/core/states" common2 "github.com/ontio/ontology/core/store/common" + sCom "github.com/ontio/ontology/core/store/common" otypes "github.com/ontio/ontology/core/types" ontErrors "github.com/ontio/ontology/errors" bactor "github.com/ontio/ontology/http/base/actor" @@ -202,7 +203,7 @@ func (api *EthereumAPI) GetCode(address common.Address, blockNumber types2.Block if err != nil { return nil, err } - if account.IsEmpty() { + if account.IsEmptyContract() { return nil, nil } code, err := bactor.GetEthCode(account.CodeHash) @@ -401,10 +402,13 @@ func (api *EthereumAPI) GetBlockByHash(hash common.Hash, fullTx bool) (interface log.Debugf("eth_getBlockByHash hash %v, fullTx %v", hash, fullTx) block, err := bactor.GetBlockFromStore(oComm.Uint256(hash)) if err != nil { + if err == sCom.ErrNotFound { + return nil, nil + } return nil, err } if block == nil { - return nil, fmt.Errorf("block: %v not found", hash.String()) + return nil, nil } return utils2.EthBlockFromOntology(block, fullTx), nil } @@ -417,10 +421,13 @@ func (api *EthereumAPI) GetBlockByNumber(blockNum types2.BlockNumber, fullTx boo } block, err := bactor.GetBlockByHeight(height) if err != nil { + if err == sCom.ErrNotFound { + return nil, nil + } return nil, err } if block == nil { - return nil, fmt.Errorf("block: %v not found", blockNum.Int64()) + return nil, nil } return utils2.EthBlockFromOntology(block, fullTx), nil } @@ -462,16 +469,19 @@ func (api *EthereumAPI) GetTransactionByBlockHashAndIndex(hash common.Hash, idx log.Debugf("eth_getTransactionByBlockHashAndIndex hash %v, idx %v", hash.Hex(), idx.String()) block, err := bactor.GetBlockFromStore(oComm.Uint256(hash)) if err != nil { + if err == sCom.ErrNotFound { + return nil, nil + } return nil, err } if block == nil { - return nil, fmt.Errorf("block: %v not found", hash.Hex()) + return nil, nil } header := block.Header blockHash := header.Hash() txs := block.Transactions if len(txs) >= int(idx) { - return nil, fmt.Errorf("access block: %v overflow %v", hash.Hex(), idx) + return nil, nil } tx := txs[idx] return utils2.OntTxToEthTx(*tx, common.Hash(blockHash), uint64(header.Height), uint64(idx)) @@ -485,16 +495,19 @@ func (api *EthereumAPI) GetTransactionByBlockNumberAndIndex(blockNum types2.Bloc } block, err := bactor.GetBlockByHeight(height) if err != nil { + if err == sCom.ErrNotFound { + return nil, nil + } return nil, err } if block == nil { - return nil, fmt.Errorf("block: %v not found", height) + return nil, nil } header := block.Header blockHash := header.Hash() txs := block.Transactions if len(txs) >= int(idx) { - return nil, fmt.Errorf("access block: %v overflow %v", height, idx) + return nil, nil } tx := txs[idx] return utils2.OntTxToEthTx(*tx, common.Hash(blockHash), uint64(header.Height), uint64(idx)) @@ -504,6 +517,9 @@ func (api *EthereumAPI) GetTransactionReceipt(hash common.Hash) (interface{}, er log.Debugf("eth_getTransactionReceipt hash %d", hash.Hex()) notify, err := bactor.GetEventNotifyByTxHash(utils2.EthToOntHash(hash)) if err != nil { + if err == sCom.ErrNotFound { + return nil, nil + } return nil, nil } if notify == nil { @@ -578,7 +594,7 @@ func (api *EthereumAPI) PendingTransactionsByHash(target common.Hash) (*types2.T log.Debugf("eth_pendingTransactionsByHash target %v", target.Hex()) ethTx := api.txpool.PendingTransactionsByHash(target) if ethTx == nil { - return nil, fmt.Errorf("tx: %v not found", target.String()) + return nil, nil } return utils2.NewTransaction(ethTx, ethTx.Hash(), common.Hash{}, 0, 0) } diff --git a/smartcontract/storage/statedb.go b/smartcontract/storage/statedb.go index 5c9b5b907..bc8942c21 100644 --- a/smartcontract/storage/statedb.go +++ b/smartcontract/storage/statedb.go @@ -169,6 +169,10 @@ func (self *EthAccount) IsEmpty() bool { return self.Nonce == 0 && self.CodeHash == common.Hash{} } +func (self *EthAccount) IsEmptyContract() bool { + return self.CodeHash == common.Hash{} +} + func (self *EthAccount) Serialization(sink *comm.ZeroCopySink) { sink.WriteUint64(self.Nonce) sink.WriteHash(comm.Uint256(self.CodeHash))