core/state, internal/ethapi: GetAccountInfo handle error properly, close XFN-79 (#1663)

This commit is contained in:
Daniel Liu 2025-11-14 18:58:18 +08:00 committed by GitHub
parent 39b8184f57
commit 2c40021f71
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View file

@ -314,14 +314,18 @@ func (s *StateDB) GetAccountInfo(addr common.Address) *AccountInfo {
stateObject := s.getStateObject(addr) stateObject := s.getStateObject(addr)
if stateObject == nil { if stateObject == nil {
result.Balance = common.Big0 result.Balance = new(big.Int)
return &result return &result
} }
if stateObject.code != nil { if stateObject.code != nil {
result.CodeSize = len(stateObject.code) result.CodeSize = len(stateObject.code)
} else { } else {
result.CodeSize, _ = s.db.ContractCodeSize(stateObject.addrHash, common.BytesToHash(stateObject.CodeHash())) size, err := s.db.ContractCodeSize(stateObject.addrHash, common.BytesToHash(stateObject.CodeHash()))
if err != nil {
s.setError(err)
}
result.CodeSize = size
} }
result.Nonce = stateObject.Nonce() result.Nonce = stateObject.Nonce()
result.Balance = stateObject.Balance() result.Balance = stateObject.Balance()

View file

@ -509,7 +509,7 @@ func (api *BlockChainAPI) GetAccountInfo(ctx context.Context, address common.Add
"nonce": info.Nonce, "nonce": info.Nonce,
"storageHash": info.StorageHash, "storageHash": info.StorageHash,
} }
return result, nil return result, state.Error()
} }
// GetStorageAt returns the storage from the state at the given address, key and // GetStorageAt returns the storage from the state at the given address, key and