Skip to content

Commit ef4135e

Browse files
committed
Added topic utility functions to whisper
1 parent c3ba4ac commit ef4135e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

whisper/util.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package whisper
2+
3+
import "github.com/ethereum/go-ethereum/crypto"
4+
5+
func hashTopic(topic []byte) []byte {
6+
return crypto.Sha3(topic)[:4]
7+
}
8+
9+
// NOTE this isn't DRY, but I don't want to iterate twice.
10+
11+
// Returns a formatted topics byte slice.
12+
// data: unformatted data (e.g., no hashes needed)
13+
func Topics(data [][]byte) [][]byte {
14+
d := make([][]byte, len(data))
15+
for i, byts := range data {
16+
d[i] = hashTopic(byts)
17+
}
18+
return d
19+
}
20+
21+
func TopicsFromString(data []string) [][]byte {
22+
d := make([][]byte, len(data))
23+
for i, str := range data {
24+
d[i] = hashTopic([]byte(str))
25+
}
26+
return d
27+
}

0 commit comments

Comments
 (0)