aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-08-15 06:24:37 +0800
committerobscuren <geffobscura@gmail.com>2014-08-15 06:24:37 +0800
commit0fcc6065692f2692072cdf0d61fe1ada547fc235 (patch)
tree861e9a3ea910b7539b8d2808f625a9bcbb19fc8d /ethchain
parent07cfb7b64ac7932a4ff8c2480452114b84b421a6 (diff)
downloaddexon-0fcc6065692f2692072cdf0d61fe1ada547fc235.tar
dexon-0fcc6065692f2692072cdf0d61fe1ada547fc235.tar.gz
dexon-0fcc6065692f2692072cdf0d61fe1ada547fc235.tar.bz2
dexon-0fcc6065692f2692072cdf0d61fe1ada547fc235.tar.lz
dexon-0fcc6065692f2692072cdf0d61fe1ada547fc235.tar.xz
dexon-0fcc6065692f2692072cdf0d61fe1ada547fc235.tar.zst
dexon-0fcc6065692f2692072cdf0d61fe1ada547fc235.zip
Added new filter from map
Diffstat (limited to 'ethchain')
-rw-r--r--ethchain/filter.go83
1 files changed, 65 insertions, 18 deletions
diff --git a/ethchain/filter.go b/ethchain/filter.go
index 65c41c42d..4f3160b90 100644
--- a/ethchain/filter.go
+++ b/ethchain/filter.go
@@ -24,6 +24,46 @@ func NewFilter(eth EthManager) *Filter {
return &Filter{eth: eth}
}
+func NewFilterFromMap(object map[string]interface{}, eth EthManager) *Filter {
+ filter := NewFilter(eth)
+
+ if object["earliest"] != nil {
+ earliest := object["earliest"]
+ if e, ok := earliest.(string); ok {
+ filter.SetEarliestBlock(ethutil.Hex2Bytes(e))
+ } else {
+ filter.SetEarliestBlock(earliest)
+ }
+ }
+
+ if object["latest"] != nil {
+ latest := object["latest"]
+ if l, ok := latest.(string); ok {
+ filter.SetLatestBlock(ethutil.Hex2Bytes(l))
+ } else {
+ filter.SetLatestBlock(latest)
+ }
+ }
+
+ if object["to"] != nil {
+ filter.AddTo(ethutil.Hex2Bytes(object["to"].(string)))
+ }
+
+ if object["from"] != nil {
+ filter.AddFrom(ethutil.Hex2Bytes(object["from"].(string)))
+ }
+
+ if object["max"] != nil {
+ filter.SetMax(object["max"].(int))
+ }
+
+ if object["skip"] != nil {
+ filter.SetSkip(object["skip"].(int))
+ }
+
+ return filter
+}
+
// Set the earliest and latest block for filtering.
// -1 = latest block (i.e., the current block)
// hash = particular hash from-to
@@ -109,30 +149,37 @@ func (self *Filter) Find() []*ethstate.Message {
break
}
- includes := func(addresses [][]byte, a []byte) (found bool) {
- for _, addr := range addresses {
- if bytes.Compare(addr, a) == 0 {
- return true
- }
- }
+ messages = append(messages, self.FilterMessages(msgs)...)
+ }
- return
- }
- // Filter the messages for interesting stuff
- for _, message := range msgs {
- if len(self.to) > 0 && !includes(self.to, message.To) {
- continue
- }
+ block = self.eth.BlockChain().GetBlock(block.PrevHash)
+ }
- if len(self.from) > 0 && !includes(self.from, message.From) {
- continue
- }
+ return messages
+}
- messages = append(messages, message)
+func (self *Filter) FilterMessages(msgs []*ethstate.Message) []*ethstate.Message {
+ var messages []*ethstate.Message
+ includes := func(addresses [][]byte, a []byte) (found bool) {
+ for _, addr := range addresses {
+ if bytes.Compare(addr, a) == 0 {
+ return true
}
}
- block = self.eth.BlockChain().GetBlock(block.PrevHash)
+ return
+ }
+ // Filter the messages for interesting stuff
+ for _, message := range msgs {
+ if len(self.to) > 0 && !includes(self.to, message.To) {
+ continue
+ }
+
+ if len(self.from) > 0 && !includes(self.from, message.From) {
+ continue
+ }
+
+ messages = append(messages, message)
}
return messages