2014-08-04 09:25:53 -05:00
|
|
|
package ethpipe
|
|
|
|
|
|
|
|
import (
|
|
|
|
"container/list"
|
|
|
|
|
2014-10-23 08:01:27 -05:00
|
|
|
"github.com/ethereum/go-ethereum/ethstate"
|
2014-08-04 09:25:53 -05:00
|
|
|
)
|
|
|
|
|
2014-08-05 04:30:12 -05:00
|
|
|
type World struct {
|
2014-08-04 09:25:53 -05:00
|
|
|
pipe *Pipe
|
2014-08-05 04:31:39 -05:00
|
|
|
cfg *Config
|
2014-08-04 09:25:53 -05:00
|
|
|
}
|
|
|
|
|
2014-08-05 04:30:12 -05:00
|
|
|
func NewWorld(pipe *Pipe) *World {
|
|
|
|
world := &World{pipe, nil}
|
2014-08-05 04:31:39 -05:00
|
|
|
world.cfg = &Config{pipe}
|
2014-08-04 09:25:53 -05:00
|
|
|
|
|
|
|
return world
|
|
|
|
}
|
|
|
|
|
2014-08-05 04:30:12 -05:00
|
|
|
func (self *Pipe) World() *World {
|
2014-08-04 09:25:53 -05:00
|
|
|
return self.world
|
|
|
|
}
|
|
|
|
|
2014-08-05 04:30:12 -05:00
|
|
|
func (self *World) State() *ethstate.State {
|
2014-08-04 09:25:53 -05:00
|
|
|
return self.pipe.stateManager.CurrentState()
|
|
|
|
}
|
|
|
|
|
2014-08-05 04:30:12 -05:00
|
|
|
func (self *World) Get(addr []byte) *Object {
|
2014-08-05 04:26:12 -05:00
|
|
|
return &Object{self.State().GetStateObject(addr)}
|
2014-08-04 09:25:53 -05:00
|
|
|
}
|
|
|
|
|
2014-08-15 06:05:13 -05:00
|
|
|
func (self *World) SafeGet(addr []byte) *Object {
|
|
|
|
return &Object{self.safeGet(addr)}
|
|
|
|
}
|
|
|
|
|
2014-08-05 04:30:12 -05:00
|
|
|
func (self *World) safeGet(addr []byte) *ethstate.StateObject {
|
2014-08-05 04:10:24 -05:00
|
|
|
object := self.State().GetStateObject(addr)
|
|
|
|
if object == nil {
|
|
|
|
object = ethstate.NewStateObject(addr)
|
2014-08-04 09:25:53 -05:00
|
|
|
}
|
|
|
|
|
2014-08-05 04:10:24 -05:00
|
|
|
return object
|
2014-08-04 09:25:53 -05:00
|
|
|
}
|
|
|
|
|
2014-08-05 04:30:12 -05:00
|
|
|
func (self *World) Coinbase() *ethstate.StateObject {
|
2014-08-04 09:25:53 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-08-05 04:30:12 -05:00
|
|
|
func (self *World) IsMining() bool {
|
2014-08-04 09:25:53 -05:00
|
|
|
return self.pipe.obj.IsMining()
|
|
|
|
}
|
|
|
|
|
2014-08-05 04:30:12 -05:00
|
|
|
func (self *World) IsListening() bool {
|
2014-08-04 09:25:53 -05:00
|
|
|
return self.pipe.obj.IsListening()
|
|
|
|
}
|
|
|
|
|
2014-08-05 04:30:12 -05:00
|
|
|
func (self *World) Peers() *list.List {
|
2014-08-05 03:17:26 -05:00
|
|
|
return self.pipe.obj.Peers()
|
2014-08-04 09:25:53 -05:00
|
|
|
}
|
|
|
|
|
2014-08-05 04:31:39 -05:00
|
|
|
func (self *World) Config() *Config {
|
2014-08-04 09:25:53 -05:00
|
|
|
return self.cfg
|
|
|
|
}
|