aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-04-01 01:02:46 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-04-01 01:02:46 +0800
commita2501ecfcd0709db8bd43ecdc4077d072230fb28 (patch)
tree1d19c6b4761abc851efaf4c4a4f342abd3456f6a /rpc
parent8f0e095f4c269c48ac2c182c891e6346929de57b (diff)
downloaddexon-a2501ecfcd0709db8bd43ecdc4077d072230fb28.tar
dexon-a2501ecfcd0709db8bd43ecdc4077d072230fb28.tar.gz
dexon-a2501ecfcd0709db8bd43ecdc4077d072230fb28.tar.bz2
dexon-a2501ecfcd0709db8bd43ecdc4077d072230fb28.tar.lz
dexon-a2501ecfcd0709db8bd43ecdc4077d072230fb28.tar.xz
dexon-a2501ecfcd0709db8bd43ecdc4077d072230fb28.tar.zst
dexon-a2501ecfcd0709db8bd43ecdc4077d072230fb28.zip
Make new types Stringers
Diffstat (limited to 'rpc')
-rw-r--r--rpc/messages.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/rpc/messages.go b/rpc/messages.go
index 108a07ed8..1ad41654b 100644
--- a/rpc/messages.go
+++ b/rpc/messages.go
@@ -29,9 +29,12 @@ type hexdata struct {
data []byte
}
+func (d *hexdata) String() string {
+ return "0x" + common.Bytes2Hex(d.data)
+}
+
func (d *hexdata) MarshalJSON() ([]byte, error) {
- v := common.Bytes2Hex(d.data)
- return json.Marshal("0x" + v)
+ return json.Marshal(d.String())
}
func (d *hexdata) UnmarshalJSON(b []byte) (err error) {
@@ -72,7 +75,7 @@ type hexnum struct {
data []byte
}
-func (d *hexnum) MarshalJSON() ([]byte, error) {
+func (d *hexnum) String() string {
// Get hex string from bytes
out := common.Bytes2Hex(d.data)
// Trim leading 0s
@@ -81,7 +84,11 @@ func (d *hexnum) MarshalJSON() ([]byte, error) {
if len(out) == 0 {
out = "0"
}
- return json.Marshal("0x" + out)
+ return "0x" + out
+}
+
+func (d *hexnum) MarshalJSON() ([]byte, error) {
+ return json.Marshal(d.String())
}
func (d *hexnum) UnmarshalJSON(b []byte) (err error) {