Merge branch 'tgerring-rpcupdates' into develop
This commit is contained in:
commit
82cae27737
@ -396,8 +396,9 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
|
|||||||
self.mu.Unlock()
|
self.mu.Unlock()
|
||||||
|
|
||||||
if chain {
|
if chain {
|
||||||
//self.setTransState(state.New(block.Root(), self.db))
|
fmt.Println("POST START")
|
||||||
//self.eventMux.Post(ChainEvent{block, td})
|
self.eventMux.Post(ChainEvent{block, td})
|
||||||
|
fmt.Println("POST END")
|
||||||
}
|
}
|
||||||
|
|
||||||
if split {
|
if split {
|
||||||
@ -413,7 +414,3 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
|
|||||||
func (self *ChainManager) GetAccount(addr []byte) *state.StateObject {
|
func (self *ChainManager) GetAccount(addr []byte) *state.StateObject {
|
||||||
return self.State().GetAccount(addr)
|
return self.State().GetAccount(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ChainManager) TransMut() *sync.RWMutex {
|
|
||||||
return &self.tsmu
|
|
||||||
}
|
|
||||||
|
@ -3,6 +3,7 @@ package filter
|
|||||||
// TODO make use of the generic filtering system
|
// TODO make use of the generic filtering system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
@ -37,17 +38,18 @@ func (self *FilterManager) Stop() {
|
|||||||
|
|
||||||
func (self *FilterManager) InstallFilter(filter *core.Filter) (id int) {
|
func (self *FilterManager) InstallFilter(filter *core.Filter) (id int) {
|
||||||
self.filterMu.Lock()
|
self.filterMu.Lock()
|
||||||
|
defer self.filterMu.Unlock()
|
||||||
id = self.filterId
|
id = self.filterId
|
||||||
self.filters[id] = filter
|
self.filters[id] = filter
|
||||||
self.filterId++
|
self.filterId++
|
||||||
self.filterMu.Unlock()
|
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *FilterManager) UninstallFilter(id int) {
|
func (self *FilterManager) UninstallFilter(id int) {
|
||||||
self.filterMu.Lock()
|
self.filterMu.Lock()
|
||||||
|
defer self.filterMu.Unlock()
|
||||||
delete(self.filters, id)
|
delete(self.filters, id)
|
||||||
self.filterMu.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFilter retrieves a filter installed using InstallFilter.
|
// GetFilter retrieves a filter installed using InstallFilter.
|
||||||
@ -62,7 +64,7 @@ func (self *FilterManager) filterLoop() {
|
|||||||
// Subscribe to events
|
// Subscribe to events
|
||||||
events := self.eventMux.Subscribe(
|
events := self.eventMux.Subscribe(
|
||||||
core.PendingBlockEvent{},
|
core.PendingBlockEvent{},
|
||||||
core.ChainEvent{},
|
//core.ChainEvent{},
|
||||||
state.Logs(nil))
|
state.Logs(nil))
|
||||||
|
|
||||||
out:
|
out:
|
||||||
@ -73,6 +75,7 @@ out:
|
|||||||
case event := <-events.Chan():
|
case event := <-events.Chan():
|
||||||
switch event := event.(type) {
|
switch event := event.(type) {
|
||||||
case core.ChainEvent:
|
case core.ChainEvent:
|
||||||
|
fmt.Println("filter start")
|
||||||
self.filterMu.RLock()
|
self.filterMu.RLock()
|
||||||
for _, filter := range self.filters {
|
for _, filter := range self.filters {
|
||||||
if filter.BlockCallback != nil {
|
if filter.BlockCallback != nil {
|
||||||
@ -80,6 +83,7 @@ out:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.filterMu.RUnlock()
|
self.filterMu.RUnlock()
|
||||||
|
fmt.Println("filter stop")
|
||||||
|
|
||||||
case core.PendingBlockEvent:
|
case core.PendingBlockEvent:
|
||||||
self.filterMu.RLock()
|
self.filterMu.RLock()
|
||||||
|
@ -117,9 +117,11 @@ out:
|
|||||||
case event := <-events.Chan():
|
case event := <-events.Chan():
|
||||||
switch ev := event.(type) {
|
switch ev := event.(type) {
|
||||||
case core.ChainEvent:
|
case core.ChainEvent:
|
||||||
|
println("miner start")
|
||||||
if self.current.block != ev.Block {
|
if self.current.block != ev.Block {
|
||||||
self.commitNewWork()
|
self.commitNewWork()
|
||||||
}
|
}
|
||||||
|
println("miner end")
|
||||||
case core.NewMinedBlockEvent:
|
case core.NewMinedBlockEvent:
|
||||||
self.commitNewWork()
|
self.commitNewWork()
|
||||||
}
|
}
|
||||||
|
@ -201,6 +201,36 @@ func (req *RpcRequest) ToGetCodeAtArgs() (*GetCodeAtArgs, error) {
|
|||||||
return args, nil
|
return args, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (req *RpcRequest) ToBoolArgs() (bool, error) {
|
||||||
|
if len(req.Params) < 1 {
|
||||||
|
return false, NewErrorResponse(ErrorArguments)
|
||||||
|
}
|
||||||
|
|
||||||
|
var args bool
|
||||||
|
err := json.Unmarshal(req.Params[0], &args)
|
||||||
|
if err != nil {
|
||||||
|
return false, NewErrorResponse(ErrorDecodeArgs)
|
||||||
|
}
|
||||||
|
|
||||||
|
rpclogger.DebugDetailf("%T %v", args, args)
|
||||||
|
return args, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (req *RpcRequest) ToCompileArgs() (string, error) {
|
||||||
|
if len(req.Params) < 1 {
|
||||||
|
return "", NewErrorResponse(ErrorArguments)
|
||||||
|
}
|
||||||
|
|
||||||
|
var args string
|
||||||
|
err := json.Unmarshal(req.Params[0], &args)
|
||||||
|
if err != nil {
|
||||||
|
return "", NewErrorResponse(ErrorDecodeArgs)
|
||||||
|
}
|
||||||
|
|
||||||
|
rpclogger.DebugDetailf("%T %v", args, args)
|
||||||
|
return args, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (req *RpcRequest) ToFilterArgs() (*FilterOptions, error) {
|
func (req *RpcRequest) ToFilterArgs() (*FilterOptions, error) {
|
||||||
if len(req.Params) < 1 {
|
if len(req.Params) < 1 {
|
||||||
return nil, NewErrorResponse(ErrorArguments)
|
return nil, NewErrorResponse(ErrorArguments)
|
||||||
@ -231,6 +261,36 @@ func (req *RpcRequest) ToFilterStringArgs() (string, error) {
|
|||||||
return args, nil
|
return args, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (req *RpcRequest) ToUninstallFilterArgs() (int, error) {
|
||||||
|
if len(req.Params) < 1 {
|
||||||
|
return 0, NewErrorResponse(ErrorArguments)
|
||||||
|
}
|
||||||
|
|
||||||
|
var args int
|
||||||
|
err := json.Unmarshal(req.Params[0], &args)
|
||||||
|
if err != nil {
|
||||||
|
return 0, NewErrorResponse(ErrorDecodeArgs)
|
||||||
|
}
|
||||||
|
|
||||||
|
rpclogger.DebugDetailf("%T %v", args, args)
|
||||||
|
return args, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (req *RpcRequest) ToFilterChangedArgs() (int, error) {
|
||||||
|
if len(req.Params) < 1 {
|
||||||
|
return 0, NewErrorResponse(ErrorArguments)
|
||||||
|
}
|
||||||
|
|
||||||
|
var id int
|
||||||
|
r := bytes.NewReader(req.Params[0])
|
||||||
|
err := json.NewDecoder(r).Decode(&id)
|
||||||
|
if err != nil {
|
||||||
|
return 0, NewErrorResponse(ErrorDecodeArgs)
|
||||||
|
}
|
||||||
|
rpclogger.DebugDetailf("%T %v", id, id)
|
||||||
|
return id, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (req *RpcRequest) ToDbPutArgs() (*DbArgs, error) {
|
func (req *RpcRequest) ToDbPutArgs() (*DbArgs, error) {
|
||||||
if len(req.Params) < 3 {
|
if len(req.Params) < 3 {
|
||||||
return nil, NewErrorResponse(ErrorArguments)
|
return nil, NewErrorResponse(ErrorArguments)
|
||||||
|
@ -113,6 +113,13 @@ func (self *EthereumApi) NewFilter(args *FilterOptions, reply *interface{}) erro
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *EthereumApi) UninstallFilter(id int, reply *interface{}) error {
|
||||||
|
delete(self.logs, id)
|
||||||
|
self.filterManager.UninstallFilter(id)
|
||||||
|
*reply = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (self *EthereumApi) NewFilterString(args string, reply *interface{}) error {
|
func (self *EthereumApi) NewFilterString(args string, reply *interface{}) error {
|
||||||
var id int
|
var id int
|
||||||
filter := core.NewFilter(self.xeth.Backend())
|
filter := core.NewFilter(self.xeth.Backend())
|
||||||
@ -273,6 +280,11 @@ func (p *EthereumApi) GetIsMining(reply *interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *EthereumApi) SetMining(shouldmine bool, reply *interface{}) error {
|
||||||
|
*reply = p.xeth.SetMining(shouldmine)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p *EthereumApi) BlockNumber(reply *interface{}) error {
|
func (p *EthereumApi) BlockNumber(reply *interface{}) error {
|
||||||
*reply = p.xeth.Backend().ChainManager().CurrentBlock().Number()
|
*reply = p.xeth.Backend().ChainManager().CurrentBlock().Number()
|
||||||
return nil
|
return nil
|
||||||
@ -306,6 +318,21 @@ func (p *EthereumApi) GetCodeAt(args *GetCodeAtArgs, reply *interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *EthereumApi) GetCompilers(reply *interface{}) error {
|
||||||
|
c := []string{"serpent"}
|
||||||
|
*reply = c
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *EthereumApi) CompileSerpent(script string, reply *interface{}) error {
|
||||||
|
res, err := ethutil.Compile(script, false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*reply = res
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p *EthereumApi) Sha3(args *Sha3Args, reply *interface{}) error {
|
func (p *EthereumApi) Sha3(args *Sha3Args, reply *interface{}) error {
|
||||||
*reply = toHex(crypto.Sha3(fromHex(args.Data)))
|
*reply = toHex(crypto.Sha3(fromHex(args.Data)))
|
||||||
return nil
|
return nil
|
||||||
@ -394,6 +421,12 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
|||||||
return p.GetIsListening(reply)
|
return p.GetIsListening(reply)
|
||||||
case "eth_mining":
|
case "eth_mining":
|
||||||
return p.GetIsMining(reply)
|
return p.GetIsMining(reply)
|
||||||
|
case "eth_setMining":
|
||||||
|
args, err := req.ToBoolArgs()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return p.SetMining(args, reply)
|
||||||
case "eth_peerCount":
|
case "eth_peerCount":
|
||||||
return p.GetPeerCount(reply)
|
return p.GetPeerCount(reply)
|
||||||
case "eth_number":
|
case "eth_number":
|
||||||
@ -460,6 +493,12 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return p.NewFilterString(args, reply)
|
return p.NewFilterString(args, reply)
|
||||||
|
case "eth_uninstallFilter":
|
||||||
|
args, err := req.ToUninstallFilterArgs()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return p.UninstallFilter(args, reply)
|
||||||
case "eth_changed":
|
case "eth_changed":
|
||||||
args, err := req.ToIdArgs()
|
args, err := req.ToIdArgs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -493,6 +532,14 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return p.WatchTx(args, reply)
|
return p.WatchTx(args, reply)
|
||||||
|
case "eth_compilers":
|
||||||
|
return p.GetCompilers(reply)
|
||||||
|
case "eth_serpent":
|
||||||
|
args, err := req.ToCompileArgs()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return p.CompileSerpent(args, reply)
|
||||||
case "web3_sha3":
|
case "web3_sha3":
|
||||||
args, err := req.ToSha3Args()
|
args, err := req.ToSha3Args()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
11
xeth/xeth.go
11
xeth/xeth.go
@ -103,6 +103,17 @@ func (self *XEth) IsMining() bool {
|
|||||||
return self.miner.Mining()
|
return self.miner.Mining()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *XEth) SetMining(shouldmine bool) bool {
|
||||||
|
ismining := self.miner.Mining()
|
||||||
|
if shouldmine && !ismining {
|
||||||
|
self.miner.Start()
|
||||||
|
}
|
||||||
|
if ismining && !shouldmine {
|
||||||
|
self.miner.Stop()
|
||||||
|
}
|
||||||
|
return self.miner.Mining()
|
||||||
|
}
|
||||||
|
|
||||||
func (self *XEth) IsListening() bool {
|
func (self *XEth) IsListening() bool {
|
||||||
return self.eth.IsListening()
|
return self.eth.IsListening()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user