Remove redundant fields

This commit is contained in:
Taylor Gerring 2015-03-24 16:08:18 +01:00
parent ad420d099a
commit b9b7442b74

View File

@ -56,12 +56,9 @@ func (dummyFrontend) UnlockAccount([]byte) bool { return false
func (dummyFrontend) ConfirmTransaction(*types.Transaction) bool { return true } func (dummyFrontend) ConfirmTransaction(*types.Transaction) bool { return true }
type XEth struct { type XEth struct {
backend *eth.Ethereum backend *eth.Ethereum
blockProcessor *core.BlockProcessor state *State
chainManager *core.ChainManager whisper *Whisper
accountManager *accounts.Manager
state *State
whisper *Whisper
frontend Frontend frontend Frontend
@ -86,24 +83,21 @@ type XEth struct {
// confirms all transactions will be used. // confirms all transactions will be used.
func New(eth *eth.Ethereum, frontend Frontend) *XEth { func New(eth *eth.Ethereum, frontend Frontend) *XEth {
xeth := &XEth{ xeth := &XEth{
backend: eth, backend: eth,
blockProcessor: eth.BlockProcessor(), whisper: NewWhisper(eth.Whisper()),
chainManager: eth.ChainManager(), quit: make(chan struct{}),
accountManager: eth.AccountManager(), filterManager: filter.NewFilterManager(eth.EventMux()),
whisper: NewWhisper(eth.Whisper()), frontend: frontend,
quit: make(chan struct{}), logs: make(map[int]*logFilter),
filterManager: filter.NewFilterManager(eth.EventMux()), messages: make(map[int]*whisperFilter),
frontend: frontend, agent: miner.NewRemoteAgent(),
logs: make(map[int]*logFilter),
messages: make(map[int]*whisperFilter),
agent: miner.NewRemoteAgent(),
} }
eth.Miner().Register(xeth.agent) eth.Miner().Register(xeth.agent)
if frontend == nil { if frontend == nil {
xeth.frontend = dummyFrontend{} xeth.frontend = dummyFrontend{}
} }
xeth.state = NewState(xeth, xeth.chainManager.TransState()) xeth.state = NewState(xeth, xeth.backend.ChainManager().TransState())
go xeth.start() go xeth.start()
go xeth.filterManager.Start() go xeth.filterManager.Start()
@ -172,10 +166,7 @@ func (self *XEth) AtStateNum(num int64) *XEth {
func (self *XEth) Backend() *eth.Ethereum { return self.backend } func (self *XEth) Backend() *eth.Ethereum { return self.backend }
func (self *XEth) WithState(statedb *state.StateDB) *XEth { func (self *XEth) WithState(statedb *state.StateDB) *XEth {
xeth := &XEth{ xeth := &XEth{
backend: self.backend, backend: self.backend,
blockProcessor: self.blockProcessor,
chainManager: self.chainManager,
whisper: self.whisper,
} }
xeth.state = NewState(xeth, statedb) xeth.state = NewState(xeth, statedb)
@ -187,14 +178,14 @@ func (self *XEth) Whisper() *Whisper { return self.whisper }
func (self *XEth) BlockByHash(strHash string) *Block { func (self *XEth) BlockByHash(strHash string) *Block {
hash := common.HexToHash(strHash) hash := common.HexToHash(strHash)
block := self.chainManager.GetBlock(hash) block := self.backend.ChainManager().GetBlock(hash)
return NewBlock(block) return NewBlock(block)
} }
func (self *XEth) EthBlockByHash(strHash string) *types.Block { func (self *XEth) EthBlockByHash(strHash string) *types.Block {
hash := common.HexToHash(strHash) hash := common.HexToHash(strHash)
block := self.chainManager.GetBlock(hash) block := self.backend.ChainManager().GetBlock(hash)
return block return block
} }
@ -214,10 +205,10 @@ func (self *XEth) BlockByNumber(num int64) *Block {
} }
if num == -1 { if num == -1 {
return NewBlock(self.chainManager.CurrentBlock()) return NewBlock(self.backend.ChainManager().CurrentBlock())
} }
return NewBlock(self.chainManager.GetBlockByNumber(uint64(num))) return NewBlock(self.backend.ChainManager().GetBlockByNumber(uint64(num)))
} }
func (self *XEth) EthBlockByNumber(num int64) *types.Block { func (self *XEth) EthBlockByNumber(num int64) *types.Block {
@ -227,10 +218,10 @@ func (self *XEth) EthBlockByNumber(num int64) *types.Block {
} }
if num == -1 { if num == -1 {
return self.chainManager.CurrentBlock() return self.backend.ChainManager().CurrentBlock()
} }
return self.chainManager.GetBlockByNumber(uint64(num)) return self.backend.ChainManager().GetBlockByNumber(uint64(num))
} }
func (self *XEth) Block(v interface{}) *Block { func (self *XEth) Block(v interface{}) *Block {
@ -530,7 +521,7 @@ func (self *XEth) PushTx(encodedTx string) (string, error) {
} }
func (self *XEth) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { func (self *XEth) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) {
statedb := self.State().State() //self.chainManager.TransState() statedb := self.State().State() //self.eth.ChainManager().TransState()
msg := callmsg{ msg := callmsg{
from: statedb.GetOrNewStateObject(common.HexToAddress(fromStr)), from: statedb.GetOrNewStateObject(common.HexToAddress(fromStr)),
to: common.HexToAddress(toStr), to: common.HexToAddress(toStr),
@ -547,8 +538,8 @@ func (self *XEth) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr st
msg.gasPrice = defaultGasPrice msg.gasPrice = defaultGasPrice
} }
block := self.chainManager.CurrentBlock() block := self.backend.ChainManager().CurrentBlock()
vmenv := core.NewEnv(statedb, self.chainManager, msg, block) vmenv := core.NewEnv(statedb, self.backend.ChainManager(), msg, block)
res, err := vmenv.Call(msg.from, msg.to, msg.data, msg.gas, msg.gasPrice, msg.value) res, err := vmenv.Call(msg.from, msg.to, msg.data, msg.gas, msg.gasPrice, msg.value)
return common.ToHex(res), err return common.ToHex(res), err
@ -609,7 +600,7 @@ func (self *XEth) Transact(fromStr, toStr, valueStr, gasStr, gasPriceStr, codeSt
tx = types.NewTransactionMessage(to, value.BigInt(), gas, price, data) tx = types.NewTransactionMessage(to, value.BigInt(), gas, price, data)
} }
state := self.chainManager.TxState() state := self.backend.ChainManager().TxState()
nonce := state.NewNonce(from) nonce := state.NewNonce(from)
tx.SetNonce(nonce) tx.SetNonce(nonce)
@ -630,7 +621,7 @@ func (self *XEth) Transact(fromStr, toStr, valueStr, gasStr, gasPriceStr, codeSt
} }
func (self *XEth) sign(tx *types.Transaction, from common.Address, didUnlock bool) error { func (self *XEth) sign(tx *types.Transaction, from common.Address, didUnlock bool) error {
sig, err := self.accountManager.Sign(accounts.Account{Address: from.Bytes()}, tx.Hash().Bytes()) sig, err := self.backend.AccountManager().Sign(accounts.Account{Address: from.Bytes()}, tx.Hash().Bytes())
if err == accounts.ErrLocked { if err == accounts.ErrLocked {
if didUnlock { if didUnlock {
return fmt.Errorf("sender account still locked after successful unlock") return fmt.Errorf("sender account still locked after successful unlock")