2014-10-31 13:30:08 +00:00
|
|
|
package xeth
|
2014-08-04 14:25:53 +00:00
|
|
|
|
|
|
|
import (
|
2014-12-14 18:09:33 +00:00
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
2014-10-31 13:43:14 +00:00
|
|
|
"github.com/ethereum/go-ethereum/state"
|
2014-08-04 14:25:53 +00:00
|
|
|
)
|
|
|
|
|
2014-08-05 09:30:12 +00:00
|
|
|
type World struct {
|
2014-10-31 13:30:08 +00:00
|
|
|
pipe *XEth
|
2014-08-05 09:31:39 +00:00
|
|
|
cfg *Config
|
2014-08-04 14:25:53 +00:00
|
|
|
}
|
|
|
|
|
2014-10-31 13:30:08 +00:00
|
|
|
func NewWorld(pipe *XEth) *World {
|
2014-08-05 09:30:12 +00:00
|
|
|
world := &World{pipe, nil}
|
2014-08-05 09:31:39 +00:00
|
|
|
world.cfg = &Config{pipe}
|
2014-08-04 14:25:53 +00:00
|
|
|
|
|
|
|
return world
|
|
|
|
}
|
|
|
|
|
2014-10-31 13:30:08 +00:00
|
|
|
func (self *XEth) World() *World {
|
2014-08-04 14:25:53 +00:00
|
|
|
return self.world
|
|
|
|
}
|
|
|
|
|
2014-12-04 10:40:20 +00:00
|
|
|
func (self *World) State() *state.StateDB {
|
2014-12-10 18:59:12 +00:00
|
|
|
return self.pipe.chainManager.State()
|
2014-08-04 14:25:53 +00:00
|
|
|
}
|
|
|
|
|
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-15 11:05:13 +00:00
|
|
|
func (self *World) SafeGet(addr []byte) *Object {
|
|
|
|
return &Object{self.safeGet(addr)}
|
|
|
|
}
|
|
|
|
|
2014-10-31 13:43:14 +00:00
|
|
|
func (self *World) safeGet(addr []byte) *state.StateObject {
|
2014-08-05 09:10:24 +00:00
|
|
|
object := self.State().GetStateObject(addr)
|
|
|
|
if object == nil {
|
2014-10-31 13:43:14 +00:00
|
|
|
object = state.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-10-31 13:43:14 +00:00
|
|
|
func (self *World) Coinbase() *state.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-12-14 18:09:33 +00:00
|
|
|
func (self *World) Peers() []*p2p.Peer {
|
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:31:39 +00:00
|
|
|
func (self *World) Config() *Config {
|
2014-08-04 14:25:53 +00:00
|
|
|
return self.cfg
|
|
|
|
}
|