Don't expose backend directly

This commit is contained in:
Taylor Gerring 2015-03-24 16:33:37 +01:00
parent b9b7442b74
commit 59b6b619a2
2 changed files with 20 additions and 9 deletions

View File

@ -60,9 +60,9 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
} }
*reply = common.ToHex(crypto.Sha3(common.FromHex(args.Data))) *reply = common.ToHex(crypto.Sha3(common.FromHex(args.Data)))
case "web3_clientVersion": case "web3_clientVersion":
*reply = api.xeth().Backend().Version() *reply = api.xeth().ClientVersion()
case "net_version": case "net_version":
*reply = string(api.xeth().Backend().ProtocolVersion()) *reply = api.xeth().NetworkVersion()
case "net_listening": case "net_listening":
*reply = api.xeth().IsListening() *reply = api.xeth().IsListening()
case "net_peerCount": case "net_peerCount":
@ -84,7 +84,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
case "eth_accounts": case "eth_accounts":
*reply = api.xeth().Accounts() *reply = api.xeth().Accounts()
case "eth_blockNumber": case "eth_blockNumber":
v := api.xeth().Backend().ChainManager().CurrentBlock().Number() v := api.xeth().CurrentBlock().Number()
*reply = common.ToHex(v.Bytes()) *reply = common.ToHex(v.Bytes())
case "eth_getBalance": case "eth_getBalance":
args := new(GetBalanceArgs) args := new(GetBalanceArgs)

View File

@ -143,7 +143,7 @@ func (self *XEth) DefaultGasPrice() *big.Int { return defaultGasPrice }
func (self *XEth) RemoteMining() *miner.RemoteAgent { return self.agent } func (self *XEth) RemoteMining() *miner.RemoteAgent { return self.agent }
func (self *XEth) AtStateNum(num int64) *XEth { func (self *XEth) AtStateNum(num int64) *XEth {
chain := self.Backend().ChainManager() chain := self.backend.ChainManager()
var block *types.Block var block *types.Block
// -1 generally means "latest" // -1 generally means "latest"
@ -156,14 +156,13 @@ func (self *XEth) AtStateNum(num int64) *XEth {
var st *state.StateDB var st *state.StateDB
if block != nil { if block != nil {
st = state.New(block.Root(), self.Backend().StateDb()) st = state.New(block.Root(), self.backend.StateDb())
} else { } else {
st = chain.State() st = chain.State()
} }
return self.WithState(st) return self.WithState(st)
} }
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,
@ -224,6 +223,10 @@ func (self *XEth) EthBlockByNumber(num int64) *types.Block {
return self.backend.ChainManager().GetBlockByNumber(uint64(num)) return self.backend.ChainManager().GetBlockByNumber(uint64(num))
} }
func (self *XEth) CurrentBlock() *types.Block {
return self.backend.ChainManager().CurrentBlock()
}
func (self *XEth) Block(v interface{}) *Block { func (self *XEth) Block(v interface{}) *Block {
if n, ok := v.(int32); ok { if n, ok := v.(int32); ok {
return self.BlockByNumber(int64(n)) return self.BlockByNumber(int64(n))
@ -254,6 +257,14 @@ func (self *XEth) IsMining() bool {
return self.backend.IsMining() return self.backend.IsMining()
} }
func (self *XEth) NetworkVersion() string {
return string(self.backend.ProtocolVersion())
}
func (self *XEth) ClientVersion() string {
return self.backend.Version()
}
func (self *XEth) SetMining(shouldmine bool) bool { func (self *XEth) SetMining(shouldmine bool) bool {
ismining := self.backend.IsMining() ismining := self.backend.IsMining()
if shouldmine && !ismining { if shouldmine && !ismining {
@ -314,7 +325,7 @@ func (self *XEth) SecretToAddress(key string) string {
func (self *XEth) RegisterFilter(args *core.FilterOptions) int { func (self *XEth) RegisterFilter(args *core.FilterOptions) int {
var id int var id int
filter := core.NewFilter(self.Backend()) filter := core.NewFilter(self.backend)
filter.SetOptions(args) filter.SetOptions(args)
filter.LogsCallback = func(logs state.Logs) { filter.LogsCallback = func(logs state.Logs) {
self.logMut.Lock() self.logMut.Lock()
@ -340,7 +351,7 @@ func (self *XEth) UninstallFilter(id int) bool {
func (self *XEth) NewFilterString(word string) int { func (self *XEth) NewFilterString(word string) int {
var id int var id int
filter := core.NewFilter(self.Backend()) filter := core.NewFilter(self.backend)
switch word { switch word {
case "pending": case "pending":
@ -392,7 +403,7 @@ func (self *XEth) Logs(id int) state.Logs {
} }
func (self *XEth) AllLogs(args *core.FilterOptions) state.Logs { func (self *XEth) AllLogs(args *core.FilterOptions) state.Logs {
filter := core.NewFilter(self.Backend()) filter := core.NewFilter(self.backend)
filter.SetOptions(args) filter.SetOptions(args)
return filter.Find() return filter.Find()