core, core/state, core/vm: remove exported account getters (#3618)

Removed exported statedb object accessors, reducing the chance for nasty
bugs to creep in. It's also ugly and unnecessary to have these methods.
This commit is contained in:
Jeffrey Wilcke
2017-02-22 23:29:59 +01:00
committed by Felix Lange
parent 46ec4357e7
commit 024d41d0c2
23 changed files with 245 additions and 238 deletions

View File

@ -32,7 +32,6 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger/glog"
@ -222,10 +221,12 @@ func (t *BlockTest) InsertPreState(db ethdb.Database) (*state.StateDB, error) {
if err != nil {
return nil, err
}
obj := statedb.CreateAccount(common.HexToAddress(addrString))
obj.SetCode(crypto.Keccak256Hash(code), code)
obj.SetBalance(balance)
obj.SetNonce(nonce)
addr := common.HexToAddress(addrString)
statedb.CreateAccount(addr)
statedb.SetCode(addr, code)
statedb.SetBalance(addr, balance)
statedb.SetNonce(addr, nonce)
for k, v := range acct.Storage {
statedb.SetState(common.HexToAddress(addrString), common.HexToHash(k), common.HexToHash(v))
}

View File

@ -165,25 +165,25 @@ func runStateTest(chainConfig *params.ChainConfig, test VmTest) error {
// check post state
for addr, account := range test.Post {
obj := statedb.GetStateObject(common.HexToAddress(addr))
if obj == nil {
address := common.HexToAddress(addr)
if !statedb.Exist(address) {
return fmt.Errorf("did not find expected post-state account: %s", addr)
}
if obj.Balance().Cmp(common.Big(account.Balance)) != 0 {
return fmt.Errorf("(%x) balance failed. Expected: %v have: %v\n", obj.Address().Bytes()[:4], common.String2Big(account.Balance), obj.Balance())
if balance := statedb.GetBalance(address); balance.Cmp(common.Big(account.Balance)) != 0 {
return fmt.Errorf("(%x) balance failed. Expected: %v have: %v\n", address[:4], common.String2Big(account.Balance), balance)
}
if obj.Nonce() != common.String2Big(account.Nonce).Uint64() {
return fmt.Errorf("(%x) nonce failed. Expected: %v have: %v\n", obj.Address().Bytes()[:4], account.Nonce, obj.Nonce())
if nonce := statedb.GetNonce(address); nonce != common.String2Big(account.Nonce).Uint64() {
return fmt.Errorf("(%x) nonce failed. Expected: %v have: %v\n", address[:4], account.Nonce, nonce)
}
for addr, value := range account.Storage {
v := statedb.GetState(obj.Address(), common.HexToHash(addr))
v := statedb.GetState(address, common.HexToHash(addr))
vexp := common.HexToHash(value)
if v != vexp {
return fmt.Errorf("storage failed:\n%x: %s:\nexpected: %x\nhave: %x\n(%v %v)\n", obj.Address().Bytes(), addr, vexp, v, vexp.Big(), v.Big())
return fmt.Errorf("storage failed:\n%x: %s:\nexpected: %x\nhave: %x\n(%v %v)\n", address[:4], addr, vexp, v, vexp.Big(), v.Big())
}
}
}

View File

@ -187,16 +187,16 @@ func runVmTest(test VmTest) error {
}
// check post state
for addr, account := range test.Post {
obj := statedb.GetStateObject(common.HexToAddress(addr))
if obj == nil {
for address, account := range test.Post {
accountAddr := common.HexToAddress(address)
if !statedb.Exist(accountAddr) {
continue
}
for addr, value := range account.Storage {
v := statedb.GetState(obj.Address(), common.HexToHash(addr))
v := statedb.GetState(accountAddr, common.HexToHash(addr))
vexp := common.HexToHash(value)
if v != vexp {
return fmt.Errorf("(%x: %s) storage failed. Expected %x, got %x (%v %v)\n", obj.Address().Bytes()[0:4], addr, vexp, v, vexp.Big(), v.Big())
return fmt.Errorf("(%x: %s) storage failed. Expected %x, got %x (%v %v)\n", addr[:4], addr, vexp, v, vexp.Big(), v.Big())
}
}
}