aboutsummaryrefslogtreecommitdiffstats
path: root/ui/filter.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-01-10 07:51:56 +0800
committerobscuren <geffobscura@gmail.com>2015-01-10 07:51:56 +0800
commite3da85faedf21a3ddb73a0fa29decf65364e6c39 (patch)
tree516faf70a5346bec9016bbdd308b6bcc23d5bccb /ui/filter.go
parent491c23a728e4f5cdedfa040aded6a6b136f6bee0 (diff)
downloaddexon-e3da85faedf21a3ddb73a0fa29decf65364e6c39.tar.gz
dexon-e3da85faedf21a3ddb73a0fa29decf65364e6c39.tar.zst
dexon-e3da85faedf21a3ddb73a0fa29decf65364e6c39.zip
Implemented filter for ws + fixes
* proper 0xhex * filters fixed * start of filter manager * accounts for ws. Closes #246
Diffstat (limited to 'ui/filter.go')
-rw-r--r--ui/filter.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/ui/filter.go b/ui/filter.go
index 88faad5ca..e0797dad2 100644
--- a/ui/filter.go
+++ b/ui/filter.go
@@ -5,6 +5,16 @@ import (
"github.com/ethereum/go-ethereum/ethutil"
)
+func fromHex(s string) []byte {
+ if len(s) > 1 {
+ if s[0:2] == "0x" {
+ s = s[2:]
+ }
+ return ethutil.Hex2Bytes(s)
+ }
+ return nil
+}
+
func NewFilterFromMap(object map[string]interface{}, eth core.EthManager) *core.Filter {
filter := core.NewFilter(eth)
@@ -20,12 +30,12 @@ func NewFilterFromMap(object map[string]interface{}, eth core.EthManager) *core.
if object["to"] != nil {
val := ethutil.NewValue(object["to"])
- filter.AddTo(ethutil.Hex2Bytes(val.Str()))
+ filter.AddTo(fromHex(val.Str()))
}
if object["from"] != nil {
val := ethutil.NewValue(object["from"])
- filter.AddFrom(ethutil.Hex2Bytes(val.Str()))
+ filter.AddFrom(fromHex(val.Str()))
}
if object["max"] != nil {
@@ -48,11 +58,11 @@ func NewFilterFromMap(object map[string]interface{}, eth core.EthManager) *core.
// Conversion methodn
func mapToAccountChange(m map[string]interface{}) (d core.AccountChange) {
if str, ok := m["id"].(string); ok {
- d.Address = ethutil.Hex2Bytes(str)
+ d.Address = fromHex(str)
}
if str, ok := m["at"].(string); ok {
- d.StateAddress = ethutil.Hex2Bytes(str)
+ d.StateAddress = fromHex(str)
}
return
@@ -62,7 +72,7 @@ func mapToAccountChange(m map[string]interface{}) (d core.AccountChange) {
// ["aabbccdd", {id: "ccddee", at: "11223344"}], "aabbcc", {id: "ccddee", at: "1122"}
func makeAltered(v interface{}) (d []core.AccountChange) {
if str, ok := v.(string); ok {
- d = append(d, core.AccountChange{ethutil.Hex2Bytes(str), nil})
+ d = append(d, core.AccountChange{fromHex(str), nil})
} else if obj, ok := v.(map[string]interface{}); ok {
d = append(d, mapToAccountChange(obj))
} else if slice, ok := v.([]interface{}); ok {