states moved to chain
This commit is contained in:
parent
af6afbaa56
commit
5553e5aaed
@ -103,7 +103,7 @@ func (self *Gui) DumpState(hash, path string) {
|
||||
var stateDump []byte
|
||||
|
||||
if len(hash) == 0 {
|
||||
stateDump = self.eth.BlockManager().CurrentState().Dump()
|
||||
stateDump = self.eth.ChainManager().State().Dump()
|
||||
} else {
|
||||
var block *types.Block
|
||||
if hash[0] == '#' {
|
||||
|
@ -141,8 +141,8 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data
|
||||
keyPair = self.lib.eth.KeyManager().KeyPair()
|
||||
)
|
||||
|
||||
statedb := self.lib.eth.BlockManager().TransState()
|
||||
account := self.lib.eth.BlockManager().TransState().GetAccount(keyPair.Address())
|
||||
statedb := self.lib.eth.ChainManager().TransState()
|
||||
account := self.lib.eth.ChainManager().TransState().GetAccount(keyPair.Address())
|
||||
contract := statedb.NewStateObject([]byte{0})
|
||||
contract.SetCode(script)
|
||||
contract.SetBalance(value)
|
||||
|
@ -401,7 +401,7 @@ func (gui *Gui) update() {
|
||||
generalUpdateTicker := time.NewTicker(500 * time.Millisecond)
|
||||
statsUpdateTicker := time.NewTicker(5 * time.Second)
|
||||
|
||||
state := gui.eth.BlockManager().TransState()
|
||||
state := gui.eth.ChainManager().TransState()
|
||||
|
||||
gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.address()).Balance())))
|
||||
|
||||
@ -428,14 +428,14 @@ func (gui *Gui) update() {
|
||||
case core.NewBlockEvent:
|
||||
gui.processBlock(ev.Block, false)
|
||||
if bytes.Compare(ev.Block.Coinbase, gui.address()) == 0 {
|
||||
gui.setWalletValue(gui.eth.BlockManager().CurrentState().GetAccount(gui.address()).Balance(), nil)
|
||||
gui.setWalletValue(gui.eth.ChainManager().State().GetBalance(gui.address()), nil)
|
||||
}
|
||||
|
||||
case core.TxPreEvent:
|
||||
tx := ev.Tx
|
||||
|
||||
tstate := gui.eth.BlockManager().TransState()
|
||||
cstate := gui.eth.BlockManager().CurrentState()
|
||||
tstate := gui.eth.ChainManager().TransState()
|
||||
cstate := gui.eth.ChainManager().State()
|
||||
|
||||
taccount := tstate.GetAccount(gui.address())
|
||||
caccount := cstate.GetAccount(gui.address())
|
||||
|
@ -200,7 +200,7 @@ func (ui *UiLib) AssetPath(p string) string {
|
||||
|
||||
func (self *UiLib) StartDbWithContractAndData(contractHash, data string) {
|
||||
dbWindow := NewDebuggerWindow(self)
|
||||
object := self.eth.BlockManager().CurrentState().GetStateObject(ethutil.Hex2Bytes(contractHash))
|
||||
object := self.eth.ChainManager().State().GetStateObject(ethutil.Hex2Bytes(contractHash))
|
||||
if len(object.Code) > 0 {
|
||||
dbWindow.SetCode("0x" + ethutil.Bytes2Hex(object.Code))
|
||||
}
|
||||
|
@ -84,20 +84,10 @@ func NewBlockManager(ethereum EthManager) *BlockManager {
|
||||
eth: ethereum,
|
||||
bc: ethereum.ChainManager(),
|
||||
}
|
||||
sm.transState = ethereum.ChainManager().CurrentBlock.State().Copy()
|
||||
sm.miningState = ethereum.ChainManager().CurrentBlock.State().Copy()
|
||||
|
||||
return sm
|
||||
}
|
||||
|
||||
func (sm *BlockManager) CurrentState() *state.StateDB {
|
||||
return sm.eth.ChainManager().CurrentBlock.State()
|
||||
}
|
||||
|
||||
func (sm *BlockManager) TransState() *state.StateDB {
|
||||
return sm.transState
|
||||
}
|
||||
|
||||
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))
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/state"
|
||||
)
|
||||
|
||||
var chainlogger = logger.NewLogger("CHAIN")
|
||||
@ -55,6 +56,8 @@ type ChainManager struct {
|
||||
|
||||
CurrentBlock *types.Block
|
||||
LastBlockHash []byte
|
||||
|
||||
transState *state.StateDB
|
||||
}
|
||||
|
||||
func NewChainManager(mux *event.TypeMux) *ChainManager {
|
||||
@ -64,6 +67,8 @@ func NewChainManager(mux *event.TypeMux) *ChainManager {
|
||||
|
||||
bc.setLastBlock()
|
||||
|
||||
bc.transState = bc.State().Copy()
|
||||
|
||||
return bc
|
||||
}
|
||||
|
||||
@ -71,6 +76,14 @@ func (self *ChainManager) SetProcessor(proc types.BlockProcessor) {
|
||||
self.processor = proc
|
||||
}
|
||||
|
||||
func (self *ChainManager) State() *state.StateDB {
|
||||
return self.CurrentBlock.State()
|
||||
}
|
||||
|
||||
func (self *ChainManager) TransState() *state.StateDB {
|
||||
return self.transState
|
||||
}
|
||||
|
||||
func (bc *ChainManager) setLastBlock() {
|
||||
data, _ := ethutil.Config.Db.Get([]byte("LastBlock"))
|
||||
if len(data) != 0 {
|
||||
|
@ -116,7 +116,7 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
|
||||
}
|
||||
|
||||
// Get the sender
|
||||
sender := pool.Ethereum.BlockManager().CurrentState().GetAccount(tx.Sender())
|
||||
sender := pool.Ethereum.ChainManager().State().GetAccount(tx.Sender())
|
||||
|
||||
totAmount := new(big.Int).Set(tx.Value)
|
||||
// Make sure there's enough in the sender's account. Having insufficient
|
||||
|
@ -150,7 +150,7 @@ func (self *JSRE) dump(call otto.FunctionCall) otto.Value {
|
||||
|
||||
state = block.State()
|
||||
} else {
|
||||
state = self.ethereum.BlockManager().CurrentState()
|
||||
state = self.ethereum.ChainManager().State()
|
||||
}
|
||||
|
||||
v, _ := self.Vm.ToValue(state.Dump())
|
||||
|
@ -232,7 +232,7 @@ func (self *Miner) finiliseTxs() types.Transactions {
|
||||
actualSize := len(self.localTxs) // See copy below
|
||||
txs := make(types.Transactions, actualSize+self.eth.TxPool().Size())
|
||||
|
||||
state := self.eth.BlockManager().TransState()
|
||||
state := self.eth.ChainManager().TransState()
|
||||
// XXX This has to change. Coinbase is, for new, same as key.
|
||||
key := self.eth.KeyManager()
|
||||
for i, ltx := range self.localTxs {
|
||||
|
12
xeth/pipe.go
12
xeth/pipe.go
@ -22,7 +22,7 @@ type VmVars struct {
|
||||
type XEth struct {
|
||||
obj core.EthManager
|
||||
blockManager *core.BlockManager
|
||||
blockChain *core.ChainManager
|
||||
chainManager *core.ChainManager
|
||||
world *World
|
||||
|
||||
Vm VmVars
|
||||
@ -32,7 +32,7 @@ func New(obj core.EthManager) *XEth {
|
||||
pipe := &XEth{
|
||||
obj: obj,
|
||||
blockManager: obj.BlockManager(),
|
||||
blockChain: obj.ChainManager(),
|
||||
chainManager: obj.ChainManager(),
|
||||
}
|
||||
pipe.world = NewWorld(pipe)
|
||||
|
||||
@ -51,7 +51,7 @@ func (self *XEth) Nonce(addr []byte) uint64 {
|
||||
}
|
||||
|
||||
func (self *XEth) Block(hash []byte) *types.Block {
|
||||
return self.blockChain.GetBlock(hash)
|
||||
return self.chainManager.GetBlock(hash)
|
||||
}
|
||||
|
||||
func (self *XEth) Storage(addr, storageAddr []byte) *ethutil.Value {
|
||||
@ -82,7 +82,7 @@ func (self *XEth) Execute(addr []byte, data []byte, value, gas, price *ethutil.V
|
||||
func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) {
|
||||
var (
|
||||
initiator = state.NewStateObject(self.obj.KeyManager().KeyPair().Address())
|
||||
block = self.blockChain.CurrentBlock
|
||||
block = self.chainManager.CurrentBlock
|
||||
)
|
||||
|
||||
self.Vm.State = self.World().State().Copy()
|
||||
@ -131,14 +131,14 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et
|
||||
tx = types.NewTransactionMessage(hash, value.BigInt(), gas.BigInt(), price.BigInt(), data)
|
||||
}
|
||||
|
||||
state := self.blockManager.TransState()
|
||||
state := self.chainManager.TransState()
|
||||
nonce := state.GetNonce(key.Address())
|
||||
|
||||
tx.Nonce = nonce
|
||||
tx.Sign(key.PrivateKey)
|
||||
|
||||
// Do some pre processing for our "pre" events and hooks
|
||||
block := self.blockChain.NewBlock(key.Address())
|
||||
block := self.chainManager.NewBlock(key.Address())
|
||||
coinbase := state.GetStateObject(key.Address())
|
||||
coinbase.SetGasPool(block.GasLimit)
|
||||
self.blockManager.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true)
|
||||
|
@ -23,7 +23,7 @@ func (self *XEth) World() *World {
|
||||
}
|
||||
|
||||
func (self *World) State() *state.StateDB {
|
||||
return self.pipe.blockManager.CurrentState()
|
||||
return self.pipe.chainManager.State()
|
||||
}
|
||||
|
||||
func (self *World) Get(addr []byte) *Object {
|
||||
|
Loading…
Reference in New Issue
Block a user