浏览代码

Renamed State => StateDB

obscuren 11 年之前
父节点
当前提交
f298ffdbb8

+ 1 - 1
cmd/mist/debugger.go

@@ -40,7 +40,7 @@ type DebuggerWindow struct {
 	vm *vm.DebugVm
 	Db *Debugger
 
-	state *state.State
+	state *state.StateDB
 }
 
 func NewDebuggerWindow(lib *UiLib) *DebuggerWindow {

+ 3 - 3
cmd/utils/vm_env.go

@@ -10,7 +10,7 @@ import (
 )
 
 type VMEnv struct {
-	state *state.State
+	state *state.StateDB
 	block *types.Block
 
 	transactor []byte
@@ -20,7 +20,7 @@ type VMEnv struct {
 	Gas   *big.Int
 }
 
-func NewEnv(state *state.State, block *types.Block, transactor []byte, value *big.Int) *VMEnv {
+func NewEnv(state *state.StateDB, block *types.Block, transactor []byte, value *big.Int) *VMEnv {
 	return &VMEnv{
 		state:      state,
 		block:      block,
@@ -37,7 +37,7 @@ func (self *VMEnv) Time() int64           { return self.block.Time }
 func (self *VMEnv) Difficulty() *big.Int  { return self.block.Difficulty }
 func (self *VMEnv) BlockHash() []byte     { return self.block.Hash() }
 func (self *VMEnv) Value() *big.Int       { return self.value }
-func (self *VMEnv) State() *state.State   { return self.state }
+func (self *VMEnv) State() *state.StateDB { return self.state }
 func (self *VMEnv) GasLimit() *big.Int    { return self.block.GasLimit }
 func (self *VMEnv) Depth() int            { return self.depth }
 func (self *VMEnv) SetDepth(i int)        { self.depth = i }

+ 9 - 9
core/block_manager.go

@@ -62,10 +62,10 @@ type BlockManager struct {
 	// Transiently state. The trans state isn't ever saved, validated and
 	// it could be used for setting account nonces without effecting
 	// the main states.
-	transState *state.State
+	transState *state.StateDB
 	// Mining state. The mining state is used purely and solely by the mining
 	// operation.
-	miningState *state.State
+	miningState *state.StateDB
 
 	// The last attempted block is mainly used for debugging purposes
 	// This does not have to be a valid block and will be set during
@@ -96,19 +96,19 @@ func (self *BlockManager) Stop() {
 	statelogger.Debugln("Stopping state manager")
 }
 
-func (sm *BlockManager) CurrentState() *state.State {
+func (sm *BlockManager) CurrentState() *state.StateDB {
 	return sm.eth.ChainManager().CurrentBlock.State()
 }
 
-func (sm *BlockManager) TransState() *state.State {
+func (sm *BlockManager) TransState() *state.StateDB {
 	return sm.transState
 }
 
-func (sm *BlockManager) MiningState() *state.State {
+func (sm *BlockManager) MiningState() *state.StateDB {
 	return sm.miningState
 }
 
-func (sm *BlockManager) NewMiningState() *state.State {
+func (sm *BlockManager) NewMiningState() *state.StateDB {
 	sm.miningState = sm.eth.ChainManager().CurrentBlock.State().Copy()
 
 	return sm.miningState
@@ -118,7 +118,7 @@ func (sm *BlockManager) ChainManager() *ChainManager {
 	return sm.bc
 }
 
-func (sm *BlockManager) TransitionState(statedb *state.State, parent, block *types.Block) (receipts types.Receipts, err error) {
+func (sm *BlockManager) TransitionState(statedb *state.StateDB, parent, block *types.Block) (receipts types.Receipts, err error) {
 	coinbase := statedb.GetOrNewStateObject(block.Coinbase)
 	coinbase.SetGasPool(block.CalcGasLimit(parent))
 
@@ -131,7 +131,7 @@ func (sm *BlockManager) TransitionState(statedb *state.State, parent, block *typ
 	return receipts, nil
 }
 
-func (self *BlockManager) ProcessTransactions(coinbase *state.StateObject, state *state.State, block, parent *types.Block, txs types.Transactions) (types.Receipts, types.Transactions, types.Transactions, types.Transactions, error) {
+func (self *BlockManager) ProcessTransactions(coinbase *state.StateObject, state *state.StateDB, block, parent *types.Block, txs types.Transactions) (types.Receipts, types.Transactions, types.Transactions, types.Transactions, error) {
 	var (
 		receipts           types.Receipts
 		handled, unhandled types.Transactions
@@ -342,7 +342,7 @@ func (sm *BlockManager) ValidateBlock(block, parent *types.Block) error {
 	return nil
 }
 
-func (sm *BlockManager) AccumelateRewards(statedb *state.State, block, parent *types.Block) error {
+func (sm *BlockManager) AccumelateRewards(statedb *state.StateDB, block, parent *types.Block) error {
 	reward := new(big.Int).Set(BlockReward)
 
 	knownUncles := ethutil.Set(parent.Uncles)

+ 3 - 3
core/state_transition.go

@@ -31,13 +31,13 @@ type StateTransition struct {
 	gas, gasPrice      *big.Int
 	value              *big.Int
 	data               []byte
-	state              *state.State
+	state              *state.StateDB
 	block              *types.Block
 
 	cb, rec, sen *state.StateObject
 }
 
-func NewStateTransition(coinbase *state.StateObject, tx *types.Transaction, state *state.State, block *types.Block) *StateTransition {
+func NewStateTransition(coinbase *state.StateObject, tx *types.Transaction, state *state.StateDB, block *types.Block) *StateTransition {
 	return &StateTransition{coinbase.Address(), tx.Recipient, tx, new(big.Int), new(big.Int).Set(tx.GasPrice), tx.Value, tx.Data, state, block, coinbase, nil, nil}
 }
 
@@ -188,7 +188,7 @@ func (self *StateTransition) TransitionState() (err error) {
 }
 
 // Converts an transaction in to a state object
-func MakeContract(tx *types.Transaction, state *state.State) *state.StateObject {
+func MakeContract(tx *types.Transaction, state *state.StateDB) *state.StateObject {
 	addr := tx.CreationAddress(state)
 
 	contract := state.GetOrNewStateObject(addr)

+ 1 - 1
core/transaction_pool.go

@@ -186,7 +186,7 @@ func (pool *TxPool) CurrentTransactions() []*types.Transaction {
 	return txList
 }
 
-func (pool *TxPool) RemoveInvalid(state *state.State) {
+func (pool *TxPool) RemoveInvalid(state *state.StateDB) {
 	pool.mutex.Lock()
 	defer pool.mutex.Unlock()
 

+ 2 - 2
core/types/block.go

@@ -77,7 +77,7 @@ type Block struct {
 	Coinbase []byte
 	// Block Trie state
 	//state *ethutil.Trie
-	state *state.State
+	state *state.StateDB
 	// Difficulty for the current block
 	Difficulty *big.Int
 	// Creation time
@@ -151,7 +151,7 @@ func (block *Block) HashNoNonce() []byte {
 	return crypto.Sha3(ethutil.Encode(block.miningHeader()))
 }
 
-func (block *Block) State() *state.State {
+func (block *Block) State() *state.StateDB {
 	return block.state
 }
 

+ 1 - 1
core/types/transaction.go

@@ -77,7 +77,7 @@ func (tx *Transaction) IsContract() bool {
 	return tx.CreatesContract()
 }
 
-func (tx *Transaction) CreationAddress(state *state.State) []byte {
+func (tx *Transaction) CreationAddress(state *state.StateDB) []byte {
 	// Generate a new address
 	return crypto.Sha3(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce}).Encode())[12:]
 }

+ 3 - 3
core/vm_env.go

@@ -9,13 +9,13 @@ import (
 )
 
 type VMEnv struct {
-	state *state.State
+	state *state.StateDB
 	block *types.Block
 	tx    *types.Transaction
 	depth int
 }
 
-func NewEnv(state *state.State, tx *types.Transaction, block *types.Block) *VMEnv {
+func NewEnv(state *state.StateDB, tx *types.Transaction, block *types.Block) *VMEnv {
 	return &VMEnv{
 		state: state,
 		block: block,
@@ -31,7 +31,7 @@ func (self *VMEnv) Time() int64           { return self.block.Time }
 func (self *VMEnv) Difficulty() *big.Int  { return self.block.Difficulty }
 func (self *VMEnv) BlockHash() []byte     { return self.block.Hash() }
 func (self *VMEnv) Value() *big.Int       { return self.tx.Value }
-func (self *VMEnv) State() *state.State   { return self.state }
+func (self *VMEnv) State() *state.StateDB { return self.state }
 func (self *VMEnv) GasLimit() *big.Int    { return self.block.GasLimit }
 func (self *VMEnv) Depth() int            { return self.depth }
 func (self *VMEnv) SetDepth(i int)        { self.depth = i }

+ 1 - 1
javascript/javascript_runtime.go

@@ -128,7 +128,7 @@ func (self *JSRE) initStdFuncs() {
  */
 
 func (self *JSRE) dump(call otto.FunctionCall) otto.Value {
-	var state *state.State
+	var state *state.StateDB
 
 	if len(call.ArgumentList) > 0 {
 		var block *types.Block

+ 1 - 1
state/dump.go

@@ -20,7 +20,7 @@ type World struct {
 	Accounts map[string]Account `json:"accounts"`
 }
 
-func (self *State) Dump() []byte {
+func (self *StateDB) Dump() []byte {
 	world := World{
 		Root:     ethutil.Bytes2Hex(self.Trie.GetRoot()),
 		Accounts: make(map[string]Account),

+ 34 - 34
state/state.go

@@ -10,12 +10,12 @@ import (
 
 var statelogger = logger.NewLogger("STATE")
 
-// States within the ethereum protocol are used to store anything
-// within the merkle trie. States take care of caching and storing
+// StateDBs within the ethereum protocol are used to store anything
+// within the merkle trie. StateDBs take care of caching and storing
 // nested states. It's the general query interface to retrieve:
 // * Contracts
 // * Accounts
-type State struct {
+type StateDB struct {
 	// The trie for this structure
 	Trie *trie.Trie
 
@@ -29,24 +29,24 @@ type State struct {
 }
 
 // Create a new state from a given trie
-func New(trie *trie.Trie) *State {
-	return &State{Trie: trie, stateObjects: make(map[string]*StateObject), manifest: NewManifest(), refund: make(map[string][]refund)}
+func New(trie *trie.Trie) *StateDB {
+	return &StateDB{Trie: trie, stateObjects: make(map[string]*StateObject), manifest: NewManifest(), refund: make(map[string][]refund)}
 }
 
-func (self *State) EmptyLogs() {
+func (self *StateDB) EmptyLogs() {
 	self.logs = nil
 }
 
-func (self *State) AddLog(log *Log) {
+func (self *StateDB) AddLog(log *Log) {
 	self.logs = append(self.logs, log)
 }
 
-func (self *State) Logs() Logs {
+func (self *StateDB) Logs() Logs {
 	return self.logs
 }
 
 // Retrieve the balance from the given address or 0 if object not found
-func (self *State) GetBalance(addr []byte) *big.Int {
+func (self *StateDB) GetBalance(addr []byte) *big.Int {
 	stateObject := self.GetStateObject(addr)
 	if stateObject != nil {
 		return stateObject.balance
@@ -59,18 +59,18 @@ type refund struct {
 	gas, price *big.Int
 }
 
-func (self *State) Refund(addr []byte, gas, price *big.Int) {
+func (self *StateDB) Refund(addr []byte, gas, price *big.Int) {
 	self.refund[string(addr)] = append(self.refund[string(addr)], refund{gas, price})
 }
 
-func (self *State) AddBalance(addr []byte, amount *big.Int) {
+func (self *StateDB) AddBalance(addr []byte, amount *big.Int) {
 	stateObject := self.GetStateObject(addr)
 	if stateObject != nil {
 		stateObject.AddBalance(amount)
 	}
 }
 
-func (self *State) GetNonce(addr []byte) uint64 {
+func (self *StateDB) GetNonce(addr []byte) uint64 {
 	stateObject := self.GetStateObject(addr)
 	if stateObject != nil {
 		return stateObject.Nonce
@@ -79,14 +79,14 @@ func (self *State) GetNonce(addr []byte) uint64 {
 	return 0
 }
 
-func (self *State) SetNonce(addr []byte, nonce uint64) {
+func (self *StateDB) SetNonce(addr []byte, nonce uint64) {
 	stateObject := self.GetStateObject(addr)
 	if stateObject != nil {
 		stateObject.Nonce = nonce
 	}
 }
 
-func (self *State) GetCode(addr []byte) []byte {
+func (self *StateDB) GetCode(addr []byte) []byte {
 	stateObject := self.GetStateObject(addr)
 	if stateObject != nil {
 		return stateObject.Code
@@ -95,7 +95,7 @@ func (self *State) GetCode(addr []byte) []byte {
 	return nil
 }
 
-func (self *State) GetState(a, b []byte) []byte {
+func (self *StateDB) GetState(a, b []byte) []byte {
 	stateObject := self.GetStateObject(a)
 	if stateObject != nil {
 		return stateObject.GetState(b).Bytes()
@@ -104,14 +104,14 @@ func (self *State) GetState(a, b []byte) []byte {
 	return nil
 }
 
-func (self *State) SetState(addr, key []byte, value interface{}) {
+func (self *StateDB) SetState(addr, key []byte, value interface{}) {
 	stateObject := self.GetStateObject(addr)
 	if stateObject != nil {
 		stateObject.SetState(key, ethutil.NewValue(value))
 	}
 }
 
-func (self *State) Delete(addr []byte) bool {
+func (self *StateDB) Delete(addr []byte) bool {
 	stateObject := self.GetStateObject(addr)
 	if stateObject != nil {
 		stateObject.MarkForDeletion()
@@ -127,7 +127,7 @@ func (self *State) Delete(addr []byte) bool {
 //
 
 // Update the given state object and apply it to state trie
-func (self *State) UpdateStateObject(stateObject *StateObject) {
+func (self *StateDB) UpdateStateObject(stateObject *StateObject) {
 	addr := stateObject.Address()
 
 	if len(stateObject.CodeHash()) > 0 {
@@ -138,14 +138,14 @@ func (self *State) UpdateStateObject(stateObject *StateObject) {
 }
 
 // Delete the given state object and delete it from the state trie
-func (self *State) DeleteStateObject(stateObject *StateObject) {
+func (self *StateDB) DeleteStateObject(stateObject *StateObject) {
 	self.Trie.Delete(string(stateObject.Address()))
 
 	delete(self.stateObjects, string(stateObject.Address()))
 }
 
 // Retrieve a state object given my the address. Nil if not found
-func (self *State) GetStateObject(addr []byte) *StateObject {
+func (self *StateDB) GetStateObject(addr []byte) *StateObject {
 	addr = ethutil.Address(addr)
 
 	stateObject := self.stateObjects[string(addr)]
@@ -164,12 +164,12 @@ func (self *State) GetStateObject(addr []byte) *StateObject {
 	return stateObject
 }
 
-func (self *State) SetStateObject(object *StateObject) {
+func (self *StateDB) SetStateObject(object *StateObject) {
 	self.stateObjects[string(object.address)] = object
 }
 
 // Retrieve a state object or create a new state object if nil
-func (self *State) GetOrNewStateObject(addr []byte) *StateObject {
+func (self *StateDB) GetOrNewStateObject(addr []byte) *StateObject {
 	stateObject := self.GetStateObject(addr)
 	if stateObject == nil {
 		stateObject = self.NewStateObject(addr)
@@ -179,7 +179,7 @@ func (self *State) GetOrNewStateObject(addr []byte) *StateObject {
 }
 
 // Create a state object whether it exist in the trie or not
-func (self *State) NewStateObject(addr []byte) *StateObject {
+func (self *StateDB) NewStateObject(addr []byte) *StateObject {
 	addr = ethutil.Address(addr)
 
 	statelogger.Debugf("(+) %x\n", addr)
@@ -191,7 +191,7 @@ func (self *State) NewStateObject(addr []byte) *StateObject {
 }
 
 // Deprecated
-func (self *State) GetAccount(addr []byte) *StateObject {
+func (self *StateDB) GetAccount(addr []byte) *StateObject {
 	return self.GetOrNewStateObject(addr)
 }
 
@@ -199,11 +199,11 @@ func (self *State) GetAccount(addr []byte) *StateObject {
 // Setting, copying of the state methods
 //
 
-func (s *State) Cmp(other *State) bool {
+func (s *StateDB) Cmp(other *StateDB) bool {
 	return s.Trie.Cmp(other.Trie)
 }
 
-func (self *State) Copy() *State {
+func (self *StateDB) Copy() *StateDB {
 	if self.Trie != nil {
 		state := New(self.Trie.Copy())
 		for k, stateObject := range self.stateObjects {
@@ -224,7 +224,7 @@ func (self *State) Copy() *State {
 	return nil
 }
 
-func (self *State) Set(state *State) {
+func (self *StateDB) Set(state *StateDB) {
 	if state == nil {
 		panic("Tried setting 'state' to nil through 'Set'")
 	}
@@ -235,12 +235,12 @@ func (self *State) Set(state *State) {
 	self.logs = state.logs
 }
 
-func (s *State) Root() []byte {
+func (s *StateDB) Root() []byte {
 	return s.Trie.GetRoot()
 }
 
 // Resets the trie and all siblings
-func (s *State) Reset() {
+func (s *StateDB) Reset() {
 	s.Trie.Undo()
 
 	// Reset all nested states
@@ -256,7 +256,7 @@ func (s *State) Reset() {
 }
 
 // Syncs the trie and all siblings
-func (s *State) Sync() {
+func (s *StateDB) Sync() {
 	// Sync all nested states
 	for _, stateObject := range s.stateObjects {
 		if stateObject.State == nil {
@@ -271,12 +271,12 @@ func (s *State) Sync() {
 	s.Empty()
 }
 
-func (self *State) Empty() {
+func (self *StateDB) Empty() {
 	self.stateObjects = make(map[string]*StateObject)
 	self.refund = make(map[string][]refund)
 }
 
-func (self *State) Update(gasUsed *big.Int) {
+func (self *StateDB) Update(gasUsed *big.Int) {
 	var deleted bool
 
 	// Refund any gas that's left
@@ -313,12 +313,12 @@ func (self *State) Update(gasUsed *big.Int) {
 	}
 }
 
-func (self *State) Manifest() *Manifest {
+func (self *StateDB) Manifest() *Manifest {
 	return self.manifest
 }
 
 // Debug stuff
-func (self *State) CreateOutputForDiff() {
+func (self *StateDB) CreateOutputForDiff() {
 	for _, stateObject := range self.stateObjects {
 		stateObject.CreateOutputForDiff()
 	}

+ 1 - 1
state/state_object.go

@@ -35,7 +35,7 @@ type StateObject struct {
 	codeHash []byte
 	Nonce    uint64
 	// Contract related attributes
-	State    *State
+	State    *StateDB
 	Code     Code
 	InitCode Code
 

+ 6 - 6
tests/helper/vm.go

@@ -12,7 +12,7 @@ import (
 
 type Env struct {
 	depth        int
-	state        *state.State
+	state        *state.StateDB
 	skipTransfer bool
 	Gas          *big.Int
 
@@ -28,13 +28,13 @@ type Env struct {
 	logs state.Logs
 }
 
-func NewEnv(state *state.State) *Env {
+func NewEnv(state *state.StateDB) *Env {
 	return &Env{
 		state: state,
 	}
 }
 
-func NewEnvFromMap(state *state.State, envValues map[string]string, exeValues map[string]string) *Env {
+func NewEnvFromMap(state *state.StateDB, envValues map[string]string, exeValues map[string]string) *Env {
 	env := NewEnv(state)
 
 	env.origin = ethutil.Hex2Bytes(exeValues["caller"])
@@ -55,7 +55,7 @@ func (self *Env) Coinbase() []byte      { return self.coinbase }
 func (self *Env) Time() int64           { return self.time }
 func (self *Env) Difficulty() *big.Int  { return self.difficulty }
 func (self *Env) BlockHash() []byte     { return nil }
-func (self *Env) State() *state.State   { return self.state }
+func (self *Env) State() *state.StateDB { return self.state }
 func (self *Env) GasLimit() *big.Int    { return self.gasLimit }
 func (self *Env) AddLog(log *state.Log) {
 	self.logs = append(self.logs, log)
@@ -91,7 +91,7 @@ func (self *Env) Create(caller vm.ClosureRef, addr, data []byte, gas, price, val
 	return exe.Create(caller)
 }
 
-func RunVm(state *state.State, env, exec map[string]string) ([]byte, state.Logs, *big.Int, error) {
+func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, state.Logs, *big.Int, error) {
 	var (
 		to    = FromHex(exec["address"])
 		from  = FromHex(exec["caller"])
@@ -110,7 +110,7 @@ func RunVm(state *state.State, env, exec map[string]string) ([]byte, state.Logs,
 	return ret, vmenv.logs, vmenv.Gas, err
 }
 
-func RunState(state *state.State, env, tx map[string]string) ([]byte, state.Logs, *big.Int, error) {
+func RunState(state *state.StateDB, env, tx map[string]string) ([]byte, state.Logs, *big.Int, error) {
 	var (
 		keyPair, _ = crypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(tx["secretKey"])))
 		to         = FromHex(tx["to"])

+ 1 - 1
vm/environment.go

@@ -9,7 +9,7 @@ import (
 )
 
 type Environment interface {
-	State() *state.State
+	State() *state.StateDB
 
 	Origin() []byte
 	BlockNumber() *big.Int

+ 1 - 1
xeth/js_types.go

@@ -95,7 +95,7 @@ type JSTransaction struct {
 	Confirmations   int    `json:"confirmations"`
 }
 
-func NewJSTx(tx *types.Transaction, state *state.State) *JSTransaction {
+func NewJSTx(tx *types.Transaction, state *state.StateDB) *JSTransaction {
 	hash := ethutil.Bytes2Hex(tx.Hash())
 	receiver := ethutil.Bytes2Hex(tx.Recipient)
 	if receiver == "0000000000000000000000000000000000000000" {

+ 1 - 1
xeth/pipe.go

@@ -16,7 +16,7 @@ import (
 var pipelogger = logger.NewLogger("XETH")
 
 type VmVars struct {
-	State *state.State
+	State *state.StateDB
 }
 
 type XEth struct {

+ 3 - 3
xeth/vm_env.go

@@ -10,7 +10,7 @@ import (
 )
 
 type VMEnv struct {
-	state  *state.State
+	state  *state.StateDB
 	block  *types.Block
 	value  *big.Int
 	sender []byte
@@ -18,7 +18,7 @@ type VMEnv struct {
 	depth int
 }
 
-func NewEnv(state *state.State, block *types.Block, value *big.Int, sender []byte) *VMEnv {
+func NewEnv(state *state.StateDB, block *types.Block, value *big.Int, sender []byte) *VMEnv {
 	return &VMEnv{
 		state:  state,
 		block:  block,
@@ -35,7 +35,7 @@ func (self *VMEnv) Time() int64           { return self.block.Time }
 func (self *VMEnv) Difficulty() *big.Int  { return self.block.Difficulty }
 func (self *VMEnv) BlockHash() []byte     { return self.block.Hash() }
 func (self *VMEnv) Value() *big.Int       { return self.value }
-func (self *VMEnv) State() *state.State   { return self.state }
+func (self *VMEnv) State() *state.StateDB { return self.state }
 func (self *VMEnv) GasLimit() *big.Int    { return self.block.GasLimit }
 func (self *VMEnv) Depth() int            { return self.depth }
 func (self *VMEnv) SetDepth(i int)        { self.depth = i }

+ 1 - 1
xeth/world.go

@@ -22,7 +22,7 @@ func (self *XEth) World() *World {
 	return self.world
 }
 
-func (self *World) State() *state.State {
+func (self *World) State() *state.StateDB {
 	return self.pipe.blockManager.CurrentState()
 }