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