Renamed State => StateDB
This commit is contained in:
parent
3664cd58e3
commit
f298ffdbb8
@ -40,7 +40,7 @@ type DebuggerWindow struct {
|
|||||||
vm *vm.DebugVm
|
vm *vm.DebugVm
|
||||||
Db *Debugger
|
Db *Debugger
|
||||||
|
|
||||||
state *state.State
|
state *state.StateDB
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDebuggerWindow(lib *UiLib) *DebuggerWindow {
|
func NewDebuggerWindow(lib *UiLib) *DebuggerWindow {
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type VMEnv struct {
|
type VMEnv struct {
|
||||||
state *state.State
|
state *state.StateDB
|
||||||
block *types.Block
|
block *types.Block
|
||||||
|
|
||||||
transactor []byte
|
transactor []byte
|
||||||
@ -20,7 +20,7 @@ type VMEnv struct {
|
|||||||
Gas *big.Int
|
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{
|
return &VMEnv{
|
||||||
state: state,
|
state: state,
|
||||||
block: block,
|
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) Difficulty() *big.Int { return self.block.Difficulty }
|
||||||
func (self *VMEnv) BlockHash() []byte { return self.block.Hash() }
|
func (self *VMEnv) BlockHash() []byte { return self.block.Hash() }
|
||||||
func (self *VMEnv) Value() *big.Int { return self.value }
|
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) GasLimit() *big.Int { return self.block.GasLimit }
|
||||||
func (self *VMEnv) Depth() int { return self.depth }
|
func (self *VMEnv) Depth() int { return self.depth }
|
||||||
func (self *VMEnv) SetDepth(i int) { self.depth = i }
|
func (self *VMEnv) SetDepth(i int) { self.depth = i }
|
||||||
|
@ -62,10 +62,10 @@ type BlockManager struct {
|
|||||||
// Transiently state. The trans state isn't ever saved, validated and
|
// Transiently state. The trans state isn't ever saved, validated and
|
||||||
// it could be used for setting account nonces without effecting
|
// it could be used for setting account nonces without effecting
|
||||||
// the main states.
|
// the main states.
|
||||||
transState *state.State
|
transState *state.StateDB
|
||||||
// Mining state. The mining state is used purely and solely by the mining
|
// Mining state. The mining state is used purely and solely by the mining
|
||||||
// operation.
|
// operation.
|
||||||
miningState *state.State
|
miningState *state.StateDB
|
||||||
|
|
||||||
// The last attempted block is mainly used for debugging purposes
|
// The last attempted block is mainly used for debugging purposes
|
||||||
// This does not have to be a valid block and will be set during
|
// 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")
|
statelogger.Debugln("Stopping state manager")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *BlockManager) CurrentState() *state.State {
|
func (sm *BlockManager) CurrentState() *state.StateDB {
|
||||||
return sm.eth.ChainManager().CurrentBlock.State()
|
return sm.eth.ChainManager().CurrentBlock.State()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *BlockManager) TransState() *state.State {
|
func (sm *BlockManager) TransState() *state.StateDB {
|
||||||
return sm.transState
|
return sm.transState
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *BlockManager) MiningState() *state.State {
|
func (sm *BlockManager) MiningState() *state.StateDB {
|
||||||
return sm.miningState
|
return sm.miningState
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *BlockManager) NewMiningState() *state.State {
|
func (sm *BlockManager) NewMiningState() *state.StateDB {
|
||||||
sm.miningState = sm.eth.ChainManager().CurrentBlock.State().Copy()
|
sm.miningState = sm.eth.ChainManager().CurrentBlock.State().Copy()
|
||||||
|
|
||||||
return sm.miningState
|
return sm.miningState
|
||||||
@ -118,7 +118,7 @@ func (sm *BlockManager) ChainManager() *ChainManager {
|
|||||||
return sm.bc
|
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 := statedb.GetOrNewStateObject(block.Coinbase)
|
||||||
coinbase.SetGasPool(block.CalcGasLimit(parent))
|
coinbase.SetGasPool(block.CalcGasLimit(parent))
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ func (sm *BlockManager) TransitionState(statedb *state.State, parent, block *typ
|
|||||||
return receipts, nil
|
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 (
|
var (
|
||||||
receipts types.Receipts
|
receipts types.Receipts
|
||||||
handled, unhandled types.Transactions
|
handled, unhandled types.Transactions
|
||||||
@ -342,7 +342,7 @@ func (sm *BlockManager) ValidateBlock(block, parent *types.Block) error {
|
|||||||
return nil
|
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)
|
reward := new(big.Int).Set(BlockReward)
|
||||||
|
|
||||||
knownUncles := ethutil.Set(parent.Uncles)
|
knownUncles := ethutil.Set(parent.Uncles)
|
||||||
|
@ -31,13 +31,13 @@ type StateTransition struct {
|
|||||||
gas, gasPrice *big.Int
|
gas, gasPrice *big.Int
|
||||||
value *big.Int
|
value *big.Int
|
||||||
data []byte
|
data []byte
|
||||||
state *state.State
|
state *state.StateDB
|
||||||
block *types.Block
|
block *types.Block
|
||||||
|
|
||||||
cb, rec, sen *state.StateObject
|
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}
|
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
|
// 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)
|
addr := tx.CreationAddress(state)
|
||||||
|
|
||||||
contract := state.GetOrNewStateObject(addr)
|
contract := state.GetOrNewStateObject(addr)
|
||||||
|
@ -186,7 +186,7 @@ func (pool *TxPool) CurrentTransactions() []*types.Transaction {
|
|||||||
return txList
|
return txList
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pool *TxPool) RemoveInvalid(state *state.State) {
|
func (pool *TxPool) RemoveInvalid(state *state.StateDB) {
|
||||||
pool.mutex.Lock()
|
pool.mutex.Lock()
|
||||||
defer pool.mutex.Unlock()
|
defer pool.mutex.Unlock()
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ type Block struct {
|
|||||||
Coinbase []byte
|
Coinbase []byte
|
||||||
// Block Trie state
|
// Block Trie state
|
||||||
//state *ethutil.Trie
|
//state *ethutil.Trie
|
||||||
state *state.State
|
state *state.StateDB
|
||||||
// Difficulty for the current block
|
// Difficulty for the current block
|
||||||
Difficulty *big.Int
|
Difficulty *big.Int
|
||||||
// Creation time
|
// Creation time
|
||||||
@ -151,7 +151,7 @@ func (block *Block) HashNoNonce() []byte {
|
|||||||
return crypto.Sha3(ethutil.Encode(block.miningHeader()))
|
return crypto.Sha3(ethutil.Encode(block.miningHeader()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (block *Block) State() *state.State {
|
func (block *Block) State() *state.StateDB {
|
||||||
return block.state
|
return block.state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ func (tx *Transaction) IsContract() bool {
|
|||||||
return tx.CreatesContract()
|
return tx.CreatesContract()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Transaction) CreationAddress(state *state.State) []byte {
|
func (tx *Transaction) CreationAddress(state *state.StateDB) []byte {
|
||||||
// Generate a new address
|
// Generate a new address
|
||||||
return crypto.Sha3(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce}).Encode())[12:]
|
return crypto.Sha3(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce}).Encode())[12:]
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type VMEnv struct {
|
type VMEnv struct {
|
||||||
state *state.State
|
state *state.StateDB
|
||||||
block *types.Block
|
block *types.Block
|
||||||
tx *types.Transaction
|
tx *types.Transaction
|
||||||
depth int
|
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{
|
return &VMEnv{
|
||||||
state: state,
|
state: state,
|
||||||
block: block,
|
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) Difficulty() *big.Int { return self.block.Difficulty }
|
||||||
func (self *VMEnv) BlockHash() []byte { return self.block.Hash() }
|
func (self *VMEnv) BlockHash() []byte { return self.block.Hash() }
|
||||||
func (self *VMEnv) Value() *big.Int { return self.tx.Value }
|
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) GasLimit() *big.Int { return self.block.GasLimit }
|
||||||
func (self *VMEnv) Depth() int { return self.depth }
|
func (self *VMEnv) Depth() int { return self.depth }
|
||||||
func (self *VMEnv) SetDepth(i int) { self.depth = i }
|
func (self *VMEnv) SetDepth(i int) { self.depth = i }
|
||||||
|
@ -128,7 +128,7 @@ func (self *JSRE) initStdFuncs() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
func (self *JSRE) dump(call otto.FunctionCall) otto.Value {
|
func (self *JSRE) dump(call otto.FunctionCall) otto.Value {
|
||||||
var state *state.State
|
var state *state.StateDB
|
||||||
|
|
||||||
if len(call.ArgumentList) > 0 {
|
if len(call.ArgumentList) > 0 {
|
||||||
var block *types.Block
|
var block *types.Block
|
||||||
|
@ -20,7 +20,7 @@ type World struct {
|
|||||||
Accounts map[string]Account `json:"accounts"`
|
Accounts map[string]Account `json:"accounts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) Dump() []byte {
|
func (self *StateDB) Dump() []byte {
|
||||||
world := World{
|
world := World{
|
||||||
Root: ethutil.Bytes2Hex(self.Trie.GetRoot()),
|
Root: ethutil.Bytes2Hex(self.Trie.GetRoot()),
|
||||||
Accounts: make(map[string]Account),
|
Accounts: make(map[string]Account),
|
||||||
|
@ -10,12 +10,12 @@ import (
|
|||||||
|
|
||||||
var statelogger = logger.NewLogger("STATE")
|
var statelogger = logger.NewLogger("STATE")
|
||||||
|
|
||||||
// States within the ethereum protocol are used to store anything
|
// StateDBs within the ethereum protocol are used to store anything
|
||||||
// within the merkle trie. States take care of caching and storing
|
// within the merkle trie. StateDBs take care of caching and storing
|
||||||
// nested states. It's the general query interface to retrieve:
|
// nested states. It's the general query interface to retrieve:
|
||||||
// * Contracts
|
// * Contracts
|
||||||
// * Accounts
|
// * Accounts
|
||||||
type State struct {
|
type StateDB struct {
|
||||||
// The trie for this structure
|
// The trie for this structure
|
||||||
Trie *trie.Trie
|
Trie *trie.Trie
|
||||||
|
|
||||||
@ -29,24 +29,24 @@ type State struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a new state from a given trie
|
// Create a new state from a given trie
|
||||||
func New(trie *trie.Trie) *State {
|
func New(trie *trie.Trie) *StateDB {
|
||||||
return &State{Trie: trie, stateObjects: make(map[string]*StateObject), manifest: NewManifest(), refund: make(map[string][]refund)}
|
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
|
self.logs = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) AddLog(log *Log) {
|
func (self *StateDB) AddLog(log *Log) {
|
||||||
self.logs = append(self.logs, log)
|
self.logs = append(self.logs, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) Logs() Logs {
|
func (self *StateDB) Logs() Logs {
|
||||||
return self.logs
|
return self.logs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve the balance from the given address or 0 if object not found
|
// 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)
|
stateObject := self.GetStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
return stateObject.balance
|
return stateObject.balance
|
||||||
@ -59,18 +59,18 @@ type refund struct {
|
|||||||
gas, price *big.Int
|
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})
|
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)
|
stateObject := self.GetStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
stateObject.AddBalance(amount)
|
stateObject.AddBalance(amount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) GetNonce(addr []byte) uint64 {
|
func (self *StateDB) GetNonce(addr []byte) uint64 {
|
||||||
stateObject := self.GetStateObject(addr)
|
stateObject := self.GetStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
return stateObject.Nonce
|
return stateObject.Nonce
|
||||||
@ -79,14 +79,14 @@ func (self *State) GetNonce(addr []byte) uint64 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) SetNonce(addr []byte, nonce uint64) {
|
func (self *StateDB) SetNonce(addr []byte, nonce uint64) {
|
||||||
stateObject := self.GetStateObject(addr)
|
stateObject := self.GetStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
stateObject.Nonce = nonce
|
stateObject.Nonce = nonce
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) GetCode(addr []byte) []byte {
|
func (self *StateDB) GetCode(addr []byte) []byte {
|
||||||
stateObject := self.GetStateObject(addr)
|
stateObject := self.GetStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
return stateObject.Code
|
return stateObject.Code
|
||||||
@ -95,7 +95,7 @@ func (self *State) GetCode(addr []byte) []byte {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) GetState(a, b []byte) []byte {
|
func (self *StateDB) GetState(a, b []byte) []byte {
|
||||||
stateObject := self.GetStateObject(a)
|
stateObject := self.GetStateObject(a)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
return stateObject.GetState(b).Bytes()
|
return stateObject.GetState(b).Bytes()
|
||||||
@ -104,14 +104,14 @@ func (self *State) GetState(a, b []byte) []byte {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) SetState(addr, key []byte, value interface{}) {
|
func (self *StateDB) SetState(addr, key []byte, value interface{}) {
|
||||||
stateObject := self.GetStateObject(addr)
|
stateObject := self.GetStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
stateObject.SetState(key, ethutil.NewValue(value))
|
stateObject.SetState(key, ethutil.NewValue(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) Delete(addr []byte) bool {
|
func (self *StateDB) Delete(addr []byte) bool {
|
||||||
stateObject := self.GetStateObject(addr)
|
stateObject := self.GetStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
stateObject.MarkForDeletion()
|
stateObject.MarkForDeletion()
|
||||||
@ -127,7 +127,7 @@ func (self *State) Delete(addr []byte) bool {
|
|||||||
//
|
//
|
||||||
|
|
||||||
// Update the given state object and apply it to state trie
|
// 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()
|
addr := stateObject.Address()
|
||||||
|
|
||||||
if len(stateObject.CodeHash()) > 0 {
|
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
|
// 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()))
|
self.Trie.Delete(string(stateObject.Address()))
|
||||||
|
|
||||||
delete(self.stateObjects, string(stateObject.Address()))
|
delete(self.stateObjects, string(stateObject.Address()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve a state object given my the address. Nil if not found
|
// 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)
|
addr = ethutil.Address(addr)
|
||||||
|
|
||||||
stateObject := self.stateObjects[string(addr)]
|
stateObject := self.stateObjects[string(addr)]
|
||||||
@ -164,12 +164,12 @@ func (self *State) GetStateObject(addr []byte) *StateObject {
|
|||||||
return stateObject
|
return stateObject
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) SetStateObject(object *StateObject) {
|
func (self *StateDB) SetStateObject(object *StateObject) {
|
||||||
self.stateObjects[string(object.address)] = object
|
self.stateObjects[string(object.address)] = object
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve a state object or create a new state object if nil
|
// 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)
|
stateObject := self.GetStateObject(addr)
|
||||||
if stateObject == nil {
|
if stateObject == nil {
|
||||||
stateObject = self.NewStateObject(addr)
|
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
|
// 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)
|
addr = ethutil.Address(addr)
|
||||||
|
|
||||||
statelogger.Debugf("(+) %x\n", addr)
|
statelogger.Debugf("(+) %x\n", addr)
|
||||||
@ -191,7 +191,7 @@ func (self *State) NewStateObject(addr []byte) *StateObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated
|
// Deprecated
|
||||||
func (self *State) GetAccount(addr []byte) *StateObject {
|
func (self *StateDB) GetAccount(addr []byte) *StateObject {
|
||||||
return self.GetOrNewStateObject(addr)
|
return self.GetOrNewStateObject(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,11 +199,11 @@ func (self *State) GetAccount(addr []byte) *StateObject {
|
|||||||
// Setting, copying of the state methods
|
// 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)
|
return s.Trie.Cmp(other.Trie)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) Copy() *State {
|
func (self *StateDB) Copy() *StateDB {
|
||||||
if self.Trie != nil {
|
if self.Trie != nil {
|
||||||
state := New(self.Trie.Copy())
|
state := New(self.Trie.Copy())
|
||||||
for k, stateObject := range self.stateObjects {
|
for k, stateObject := range self.stateObjects {
|
||||||
@ -224,7 +224,7 @@ func (self *State) Copy() *State {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) Set(state *State) {
|
func (self *StateDB) Set(state *StateDB) {
|
||||||
if state == nil {
|
if state == nil {
|
||||||
panic("Tried setting 'state' to nil through 'Set'")
|
panic("Tried setting 'state' to nil through 'Set'")
|
||||||
}
|
}
|
||||||
@ -235,12 +235,12 @@ func (self *State) Set(state *State) {
|
|||||||
self.logs = state.logs
|
self.logs = state.logs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) Root() []byte {
|
func (s *StateDB) Root() []byte {
|
||||||
return s.Trie.GetRoot()
|
return s.Trie.GetRoot()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resets the trie and all siblings
|
// Resets the trie and all siblings
|
||||||
func (s *State) Reset() {
|
func (s *StateDB) Reset() {
|
||||||
s.Trie.Undo()
|
s.Trie.Undo()
|
||||||
|
|
||||||
// Reset all nested states
|
// Reset all nested states
|
||||||
@ -256,7 +256,7 @@ func (s *State) Reset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Syncs the trie and all siblings
|
// Syncs the trie and all siblings
|
||||||
func (s *State) Sync() {
|
func (s *StateDB) Sync() {
|
||||||
// Sync all nested states
|
// Sync all nested states
|
||||||
for _, stateObject := range s.stateObjects {
|
for _, stateObject := range s.stateObjects {
|
||||||
if stateObject.State == nil {
|
if stateObject.State == nil {
|
||||||
@ -271,12 +271,12 @@ func (s *State) Sync() {
|
|||||||
s.Empty()
|
s.Empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) Empty() {
|
func (self *StateDB) Empty() {
|
||||||
self.stateObjects = make(map[string]*StateObject)
|
self.stateObjects = make(map[string]*StateObject)
|
||||||
self.refund = make(map[string][]refund)
|
self.refund = make(map[string][]refund)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) Update(gasUsed *big.Int) {
|
func (self *StateDB) Update(gasUsed *big.Int) {
|
||||||
var deleted bool
|
var deleted bool
|
||||||
|
|
||||||
// Refund any gas that's left
|
// 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
|
return self.manifest
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug stuff
|
// Debug stuff
|
||||||
func (self *State) CreateOutputForDiff() {
|
func (self *StateDB) CreateOutputForDiff() {
|
||||||
for _, stateObject := range self.stateObjects {
|
for _, stateObject := range self.stateObjects {
|
||||||
stateObject.CreateOutputForDiff()
|
stateObject.CreateOutputForDiff()
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ type StateObject struct {
|
|||||||
codeHash []byte
|
codeHash []byte
|
||||||
Nonce uint64
|
Nonce uint64
|
||||||
// Contract related attributes
|
// Contract related attributes
|
||||||
State *State
|
State *StateDB
|
||||||
Code Code
|
Code Code
|
||||||
InitCode Code
|
InitCode Code
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
type Env struct {
|
type Env struct {
|
||||||
depth int
|
depth int
|
||||||
state *state.State
|
state *state.StateDB
|
||||||
skipTransfer bool
|
skipTransfer bool
|
||||||
Gas *big.Int
|
Gas *big.Int
|
||||||
|
|
||||||
@ -28,13 +28,13 @@ type Env struct {
|
|||||||
logs state.Logs
|
logs state.Logs
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEnv(state *state.State) *Env {
|
func NewEnv(state *state.StateDB) *Env {
|
||||||
return &Env{
|
return &Env{
|
||||||
state: state,
|
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 := NewEnv(state)
|
||||||
|
|
||||||
env.origin = ethutil.Hex2Bytes(exeValues["caller"])
|
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) Time() int64 { return self.time }
|
||||||
func (self *Env) Difficulty() *big.Int { return self.difficulty }
|
func (self *Env) Difficulty() *big.Int { return self.difficulty }
|
||||||
func (self *Env) BlockHash() []byte { return nil }
|
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) GasLimit() *big.Int { return self.gasLimit }
|
||||||
func (self *Env) AddLog(log *state.Log) {
|
func (self *Env) AddLog(log *state.Log) {
|
||||||
self.logs = append(self.logs, 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)
|
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 (
|
var (
|
||||||
to = FromHex(exec["address"])
|
to = FromHex(exec["address"])
|
||||||
from = FromHex(exec["caller"])
|
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
|
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 (
|
var (
|
||||||
keyPair, _ = crypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(tx["secretKey"])))
|
keyPair, _ = crypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(tx["secretKey"])))
|
||||||
to = FromHex(tx["to"])
|
to = FromHex(tx["to"])
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Environment interface {
|
type Environment interface {
|
||||||
State() *state.State
|
State() *state.StateDB
|
||||||
|
|
||||||
Origin() []byte
|
Origin() []byte
|
||||||
BlockNumber() *big.Int
|
BlockNumber() *big.Int
|
||||||
|
@ -95,7 +95,7 @@ type JSTransaction struct {
|
|||||||
Confirmations int `json:"confirmations"`
|
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())
|
hash := ethutil.Bytes2Hex(tx.Hash())
|
||||||
receiver := ethutil.Bytes2Hex(tx.Recipient)
|
receiver := ethutil.Bytes2Hex(tx.Recipient)
|
||||||
if receiver == "0000000000000000000000000000000000000000" {
|
if receiver == "0000000000000000000000000000000000000000" {
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
var pipelogger = logger.NewLogger("XETH")
|
var pipelogger = logger.NewLogger("XETH")
|
||||||
|
|
||||||
type VmVars struct {
|
type VmVars struct {
|
||||||
State *state.State
|
State *state.StateDB
|
||||||
}
|
}
|
||||||
|
|
||||||
type XEth struct {
|
type XEth struct {
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type VMEnv struct {
|
type VMEnv struct {
|
||||||
state *state.State
|
state *state.StateDB
|
||||||
block *types.Block
|
block *types.Block
|
||||||
value *big.Int
|
value *big.Int
|
||||||
sender []byte
|
sender []byte
|
||||||
@ -18,7 +18,7 @@ type VMEnv struct {
|
|||||||
depth int
|
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{
|
return &VMEnv{
|
||||||
state: state,
|
state: state,
|
||||||
block: block,
|
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) Difficulty() *big.Int { return self.block.Difficulty }
|
||||||
func (self *VMEnv) BlockHash() []byte { return self.block.Hash() }
|
func (self *VMEnv) BlockHash() []byte { return self.block.Hash() }
|
||||||
func (self *VMEnv) Value() *big.Int { return self.value }
|
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) GasLimit() *big.Int { return self.block.GasLimit }
|
||||||
func (self *VMEnv) Depth() int { return self.depth }
|
func (self *VMEnv) Depth() int { return self.depth }
|
||||||
func (self *VMEnv) SetDepth(i int) { self.depth = i }
|
func (self *VMEnv) SetDepth(i int) { self.depth = i }
|
||||||
|
@ -22,7 +22,7 @@ func (self *XEth) World() *World {
|
|||||||
return self.world
|
return self.world
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *World) State() *state.State {
|
func (self *World) State() *state.StateDB {
|
||||||
return self.pipe.blockManager.CurrentState()
|
return self.pipe.blockManager.CurrentState()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user