aboutsummaryrefslogtreecommitdiffstats
path: root/javascript
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2014-10-15 01:38:38 +0800
committerFelix Lange <fjl@twurst.com>2014-10-15 01:38:38 +0800
commit0aea5fc4a3ed9c08272d3a894c0a31212dc25a7a (patch)
tree2b483bc46c8db872a1bebc7ac0b47cd9a3046617 /javascript
parent83a4b8b49bc28dad0539d040dceca48b7b75baf2 (diff)
downloadgo-tangerine-0aea5fc4a3ed9c08272d3a894c0a31212dc25a7a.tar
go-tangerine-0aea5fc4a3ed9c08272d3a894c0a31212dc25a7a.tar.gz
go-tangerine-0aea5fc4a3ed9c08272d3a894c0a31212dc25a7a.tar.bz2
go-tangerine-0aea5fc4a3ed9c08272d3a894c0a31212dc25a7a.tar.lz
go-tangerine-0aea5fc4a3ed9c08272d3a894c0a31212dc25a7a.tar.xz
go-tangerine-0aea5fc4a3ed9c08272d3a894c0a31212dc25a7a.tar.zst
go-tangerine-0aea5fc4a3ed9c08272d3a894c0a31212dc25a7a.zip
adapt to new event package
Diffstat (limited to 'javascript')
-rw-r--r--javascript/javascript_runtime.go35
1 files changed, 12 insertions, 23 deletions
diff --git a/javascript/javascript_runtime.go b/javascript/javascript_runtime.go
index ffc672a63..16e22964f 100644
--- a/javascript/javascript_runtime.go
+++ b/javascript/javascript_runtime.go
@@ -11,9 +11,9 @@ import (
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethpipe"
- "github.com/ethereum/eth-go/ethreact"
"github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethutil"
+ "github.com/ethereum/eth-go/event"
"github.com/ethereum/go-ethereum/utils"
"github.com/obscuren/otto"
)
@@ -25,9 +25,8 @@ type JSRE struct {
Vm *otto.Otto
pipe *ethpipe.JSPipe
- blockChan chan ethreact.Event
- changeChan chan ethreact.Event
- quitChan chan bool
+ events event.Subscription
+ quitChan chan bool
objectCb map[string][]otto.Value
}
@@ -51,8 +50,7 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
ethereum,
otto.New(),
ethpipe.NewJSPipe(ethereum),
- make(chan ethreact.Event, 10),
- make(chan ethreact.Event, 10),
+ nil,
make(chan bool),
make(map[string][]otto.Value),
}
@@ -68,8 +66,8 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
go re.mainLoop()
// Subscribe to events
- reactor := ethereum.Reactor()
- reactor.Subscribe("newBlock", re.blockChan)
+ mux := ethereum.EventMux()
+ re.events = mux.Subscribe(ethchain.NewBlockEvent{})
re.Bind("eth", &JSEthereum{re.pipe, re.Vm, ethereum})
@@ -105,25 +103,16 @@ func (self *JSRE) Require(file string) error {
}
func (self *JSRE) Stop() {
+ self.events.Unsubscribe()
// Kill the main loop
self.quitChan <- true
- close(self.blockChan)
close(self.quitChan)
- close(self.changeChan)
jsrelogger.Infoln("stopped")
}
func (self *JSRE) mainLoop() {
-out:
- for {
- select {
- case <-self.quitChan:
- break out
- case block := <-self.blockChan:
- if _, ok := block.Resource.(*ethchain.Block); ok {
- }
- }
+ for _ = range self.events.Chan() {
}
}
@@ -201,13 +190,13 @@ func (self *JSRE) watch(call otto.FunctionCall) otto.Value {
if storageCallback {
self.objectCb[addr+storageAddr] = append(self.objectCb[addr+storageAddr], cb)
- event := "storage:" + string(ethutil.Hex2Bytes(addr)) + ":" + string(ethutil.Hex2Bytes(storageAddr))
- self.ethereum.Reactor().Subscribe(event, self.changeChan)
+ // event := "storage:" + string(ethutil.Hex2Bytes(addr)) + ":" + string(ethutil.Hex2Bytes(storageAddr))
+ // self.ethereum.EventMux().Subscribe(event, self.changeChan)
} else {
self.objectCb[addr] = append(self.objectCb[addr], cb)
- event := "object:" + string(ethutil.Hex2Bytes(addr))
- self.ethereum.Reactor().Subscribe(event, self.changeChan)
+ // event := "object:" + string(ethutil.Hex2Bytes(addr))
+ // self.ethereum.EventMux().Subscribe(event, self.changeChan)
}
return otto.UndefinedValue()