aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/whisperv5/topic.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-06-26 18:44:35 +0800
committerGitHub <noreply@github.com>2017-06-26 18:44:35 +0800
commitfeb29327066d6076d1802cdc1492d43a39cec276 (patch)
tree93f3231648b0f225c0c8d44bf81304282f93b605 /whisper/whisperv5/topic.go
parentf321ed23fbaad8a13cc672f601b15f5272b4b2bb (diff)
parentea1d1825a8509b3353c535c9444861e15471942a (diff)
downloaddexon-feb29327066d6076d1802cdc1492d43a39cec276.tar
dexon-feb29327066d6076d1802cdc1492d43a39cec276.tar.gz
dexon-feb29327066d6076d1802cdc1492d43a39cec276.tar.bz2
dexon-feb29327066d6076d1802cdc1492d43a39cec276.tar.lz
dexon-feb29327066d6076d1802cdc1492d43a39cec276.tar.xz
dexon-feb29327066d6076d1802cdc1492d43a39cec276.tar.zst
dexon-feb29327066d6076d1802cdc1492d43a39cec276.zip
Merge pull request #14540 from bas-vk/whisper-api
whisperv5: integrate whisper and implement API
Diffstat (limited to 'whisper/whisperv5/topic.go')
-rw-r--r--whisper/whisperv5/topic.go32
1 files changed, 9 insertions, 23 deletions
diff --git a/whisper/whisperv5/topic.go b/whisper/whisperv5/topic.go
index 54d7422d1..d1996c460 100644
--- a/whisper/whisperv5/topic.go
+++ b/whisper/whisperv5/topic.go
@@ -19,10 +19,8 @@
package whisperv5
import (
- "fmt"
- "strings"
-
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/common/hexutil"
)
// Topic represents a cryptographically secure, probabilistic partial
@@ -46,24 +44,12 @@ func (topic *TopicType) String() string {
return string(common.ToHex(topic[:]))
}
-// UnmarshalJSON parses a hex representation to a topic.
-func (t *TopicType) UnmarshalJSON(input []byte) error {
- length := len(input)
- if length >= 2 && input[0] == '"' && input[length-1] == '"' {
- input = input[1 : length-1]
- }
- // strip "0x" for length check
- if len(input) > 1 && strings.ToLower(string(input[:2])) == "0x" {
- input = input[2:]
- }
- // validate the length of the input
- if len(input) != TopicLength*2 {
- return fmt.Errorf("unmarshalJSON failed: topic must be exactly %d bytes", TopicLength)
- }
- b := common.FromHex(string(input))
- if b == nil {
- return fmt.Errorf("unmarshalJSON failed: wrong topic format")
- }
- *t = BytesToTopic(b)
- return nil
+// MarshalText returns the hex representation of t.
+func (t TopicType) MarshalText() ([]byte, error) {
+ return hexutil.Bytes(t[:]).MarshalText()
+}
+
+// UnmarshalText parses a hex representation to a topic.
+func (t *TopicType) UnmarshalText(input []byte) error {
+ return hexutil.UnmarshalFixedText("Topic", input, t[:])
}