diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-04-22 17:50:48 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-04-28 15:49:04 +0800 |
commit | db615a85ec000dab7f73a6d4b1b46428ba4acdee (patch) | |
tree | 0ffc36dae8454fcbdcde7fa0d1e616365e87ad29 /whisper/filter.go | |
parent | ae4bfc3cfb3f1debad9dd0211950ce09038ffa90 (diff) | |
download | dexon-db615a85ec000dab7f73a6d4b1b46428ba4acdee.tar dexon-db615a85ec000dab7f73a6d4b1b46428ba4acdee.tar.gz dexon-db615a85ec000dab7f73a6d4b1b46428ba4acdee.tar.bz2 dexon-db615a85ec000dab7f73a6d4b1b46428ba4acdee.tar.lz dexon-db615a85ec000dab7f73a6d4b1b46428ba4acdee.tar.xz dexon-db615a85ec000dab7f73a6d4b1b46428ba4acdee.tar.zst dexon-db615a85ec000dab7f73a6d4b1b46428ba4acdee.zip |
ui/qt/qwhisper, whisper, xeth: polish topic filter, fix wildcards
Diffstat (limited to 'whisper/filter.go')
-rw-r--r-- | whisper/filter.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/whisper/filter.go b/whisper/filter.go index 8a398ab76..c946d9380 100644 --- a/whisper/filter.go +++ b/whisper/filter.go @@ -16,6 +16,66 @@ type Filter struct { Fn func(msg *Message) // Handler in case of a match } +// NewFilterTopics creates a 2D topic array used by whisper.Filter from binary +// data elements. +func NewFilterTopics(data ...[][]byte) [][]Topic { + filter := make([][]Topic, len(data)) + for i, condition := range data { + // Handle the special case of condition == [[]byte{}] + if len(condition) == 1 && len(condition[0]) == 0 { + filter[i] = []Topic{} + continue + } + // Otherwise flatten normally + filter[i] = NewTopics(condition...) + } + return filter +} + +// NewFilterTopicsFlat creates a 2D topic array used by whisper.Filter from flat +// binary data elements. +func NewFilterTopicsFlat(data ...[]byte) [][]Topic { + filter := make([][]Topic, len(data)) + for i, element := range data { + // Only add non-wildcard topics + filter[i] = make([]Topic, 0, 1) + if len(element) > 0 { + filter[i] = append(filter[i], NewTopic(element)) + } + } + return filter +} + +// NewFilterTopicsFromStrings creates a 2D topic array used by whisper.Filter +// from textual data elements. +func NewFilterTopicsFromStrings(data ...[]string) [][]Topic { + filter := make([][]Topic, len(data)) + for i, condition := range data { + // Handle the special case of condition == [""] + if len(condition) == 1 && condition[0] == "" { + filter[i] = []Topic{} + continue + } + // Otherwise flatten normally + filter[i] = NewTopicsFromStrings(condition...) + } + return filter +} + +// NewFilterTopicsFromStringsFlat creates a 2D topic array used by whisper.Filter from flat +// binary data elements. +func NewFilterTopicsFromStringsFlat(data ...string) [][]Topic { + filter := make([][]Topic, len(data)) + for i, element := range data { + // Only add non-wildcard topics + filter[i] = make([]Topic, 0, 1) + if element != "" { + filter[i] = append(filter[i], NewTopicFromString(element)) + } + } + return filter +} + // filterer is the internal, fully initialized filter ready to match inbound // messages to a variety of criteria. type filterer struct { |