mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
core: never use so directly
This commit is contained in:
parent
4728db84aa
commit
fc3ee373ab
4 changed files with 26 additions and 11 deletions
|
|
@ -17,6 +17,7 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -71,8 +72,7 @@ func exec(env vm.Environment, caller vm.ContractRef, address, codeAddr *common.A
|
||||||
}
|
}
|
||||||
|
|
||||||
if !env.CanTransfer(caller.Address(), value) {
|
if !env.CanTransfer(caller.Address(), value) {
|
||||||
caller.ReturnGas(gas, gasPrice)
|
fmt.Println("insuf", value)
|
||||||
|
|
||||||
return nil, common.Address{}, ValueTransferErr("insufficient funds to transfer value. Req %v, has %v", value, env.Db().GetBalance(caller.Address()))
|
return nil, common.Address{}, ValueTransferErr("insufficient funds to transfer value. Req %v, has %v", value, env.Db().GetBalance(caller.Address()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,24 @@ func (self *StateDB) RawDump() Dump {
|
||||||
}
|
}
|
||||||
dump.Accounts[common.Bytes2Hex(addr)] = account
|
dump.Accounts[common.Bytes2Hex(addr)] = account
|
||||||
}
|
}
|
||||||
|
for addr, stateObject := range self.stateObjects {
|
||||||
|
account := DumpAccount{
|
||||||
|
Balance: stateObject.data.Balance.String(),
|
||||||
|
Nonce: stateObject.data.Nonce,
|
||||||
|
Root: common.Bytes2Hex(stateObject.data.Root[:]),
|
||||||
|
CodeHash: common.Bytes2Hex(stateObject.data.CodeHash),
|
||||||
|
Code: common.Bytes2Hex(stateObject.Code(self.db)),
|
||||||
|
Storage: make(map[string]string),
|
||||||
|
}
|
||||||
|
storageIt := stateObject.getTrie(self.db).Iterator()
|
||||||
|
for storageIt.Next() {
|
||||||
|
account.Storage[common.Bytes2Hex(self.trie.GetKey(storageIt.Key))] = common.Bytes2Hex(storageIt.Value)
|
||||||
|
}
|
||||||
|
for storageAddr, value := range stateObject.cachedStorage {
|
||||||
|
account.Storage[storageAddr.Hex()] = value.Hex()
|
||||||
|
}
|
||||||
|
dump.Accounts[addr.Hex()] = account
|
||||||
|
}
|
||||||
return dump
|
return dump
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -410,8 +410,6 @@ func (s *StateDB) GetOrNewStateObject(address common.Address) *StateObject {
|
||||||
if !s.localStateObjects[address] {
|
if !s.localStateObjects[address] {
|
||||||
stateObject = stateObject.Copy(s.db, s.MarkStateObjectDirty)
|
stateObject = stateObject.Copy(s.db, s.MarkStateObjectDirty)
|
||||||
s.SetOwnedStateObject(address, stateObject)
|
s.SetOwnedStateObject(address, stateObject)
|
||||||
//s.stateObjects[address] = stateObject
|
|
||||||
//s.localStateObjects[address] = true
|
|
||||||
}
|
}
|
||||||
return stateObject
|
return stateObject
|
||||||
}
|
}
|
||||||
|
|
@ -421,8 +419,6 @@ func (s *StateDB) GetOrNewStateObject(address common.Address) *StateObject {
|
||||||
stateObject.SetNonce(StartingNonce)
|
stateObject.SetNonce(StartingNonce)
|
||||||
|
|
||||||
s.SetOwnedStateObject(address, stateObject)
|
s.SetOwnedStateObject(address, stateObject)
|
||||||
//s.stateObjects[address] = stateObject
|
|
||||||
//s.localStateObjects[address] = true
|
|
||||||
}
|
}
|
||||||
return stateObject
|
return stateObject
|
||||||
}
|
}
|
||||||
|
|
@ -432,7 +428,6 @@ func (s *StateDB) GetStateObject(address common.Address) *StateObject {
|
||||||
if account != nil {
|
if account != nil {
|
||||||
if s.stateObjects[address] == nil {
|
if s.stateObjects[address] == nil {
|
||||||
s.SetStateObject(account)
|
s.SetStateObject(account)
|
||||||
//s.stateObjects[address] = account
|
|
||||||
}
|
}
|
||||||
return account
|
return account
|
||||||
}
|
}
|
||||||
|
|
@ -477,8 +472,8 @@ func (self *StateDB) CreateAccount(addr common.Address) vm.Account {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateDB) Set(state *StateDB) {
|
func (self *StateDB) Set(state *StateDB) {
|
||||||
self.lock.Lock()
|
//self.lock.Lock()
|
||||||
defer self.lock.Unlock()
|
//defer self.lock.Unlock()
|
||||||
|
|
||||||
*self = *state
|
*self = *state
|
||||||
/*
|
/*
|
||||||
|
|
@ -641,7 +636,7 @@ func IntermediateRoot(state *StateDB) common.Hash {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state.stateObjectsDirty = make(map[common.Address]struct{})
|
//state.stateObjectsDirty = make(map[common.Address]struct{})
|
||||||
return state.trie.Hash()
|
return state.trie.Hash()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -198,7 +198,9 @@ func (self *StateTransition) buyGas() error {
|
||||||
}
|
}
|
||||||
self.addGas(mgas)
|
self.addGas(mgas)
|
||||||
self.initialGas.Set(mgas)
|
self.initialGas.Set(mgas)
|
||||||
sender.SubBalance(mgval)
|
|
||||||
|
self.state.(*state.StateDB).SubBalance(sender.Address(), mgval)
|
||||||
|
// sender.SubBalance(mgval)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue