diff options
author | obscuren <geffobscura@gmail.com> | 2014-08-20 19:05:26 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-08-20 19:05:26 +0800 |
commit | 55a2f35a648ef70cdcc88bd751265e30831b54e5 (patch) | |
tree | 7d5fef53c640eabf599e74873cb3c6e32d046607 /ethpipe/js_pipe.go | |
parent | b97ea0e447c24c0a85f63a7714a2eb221a7faccd (diff) | |
download | dexon-55a2f35a648ef70cdcc88bd751265e30831b54e5.tar dexon-55a2f35a648ef70cdcc88bd751265e30831b54e5.tar.gz dexon-55a2f35a648ef70cdcc88bd751265e30831b54e5.tar.bz2 dexon-55a2f35a648ef70cdcc88bd751265e30831b54e5.tar.lz dexon-55a2f35a648ef70cdcc88bd751265e30831b54e5.tar.xz dexon-55a2f35a648ef70cdcc88bd751265e30831b54e5.tar.zst dexon-55a2f35a648ef70cdcc88bd751265e30831b54e5.zip |
JS Filter
Diffstat (limited to 'ethpipe/js_pipe.go')
-rw-r--r-- | ethpipe/js_pipe.go | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index 0d0928fc3..4b0d6a849 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -1,6 +1,7 @@ package ethpipe import ( + "bytes" "encoding/json" "fmt" "sync/atomic" @@ -119,6 +120,28 @@ func (self *JSPipe) EachStorage(addr string) string { return string(valuesJson) } +func (self *JSPipe) ToAscii(str string) string { + padded := ethutil.RightPadBytes([]byte(str), 32) + + return "0x" + ethutil.Bytes2Hex(padded) +} + +func (self *JSPipe) FromAscii(str string) string { + if ethutil.IsHex(str) { + str = str[2:] + } + + return string(bytes.Trim(ethutil.Hex2Bytes(str), "\x00")) +} + +func (self *JSPipe) FromNumber(str string) string { + if ethutil.IsHex(str) { + str = str[2:] + } + + return ethutil.BigD(ethutil.Hex2Bytes(str)).String() +} + func (self *JSPipe) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (*JSReceipt, error) { var hash []byte var contractCreation bool @@ -200,8 +223,7 @@ func (self *JSPipe) Watch(object map[string]interface{}) *JSFilter { func (self *JSPipe) Messages(object map[string]interface{}) string { filter := self.Watch(object) - - defer filter.Uninstall() + filter.Uninstall() return filter.Messages() @@ -247,8 +269,8 @@ func (self *JSFilter) Messages() string { } func (self *JSFilter) mainLoop() { - blockChan := make(chan ethreact.Event, 1) - messageChan := make(chan ethreact.Event, 1) + blockChan := make(chan ethreact.Event, 5) + messageChan := make(chan ethreact.Event, 5) // Subscribe to events reactor := self.eth.Reactor() reactor.Subscribe("newBlock", blockChan) @@ -267,8 +289,11 @@ out: case msg := <-messageChan: if messages, ok := msg.Resource.(ethstate.Messages); ok { if self.MessageCallback != nil { + println("messages!") msgs := self.FilterMessages(messages) - self.MessageCallback(msgs) + if len(msgs) > 0 { + self.MessageCallback(msgs) + } } } } |