Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
3a948b2d
Commit
3a948b2d
authored
Mar 31, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add hexdata and hexnum types
parent
8b51582b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
0 deletions
+76
-0
messages.go
rpc/messages.go
+76
-0
No files found.
rpc/messages.go
View file @
3a948b2d
...
...
@@ -19,8 +19,84 @@ package rpc
import
(
"encoding/json"
"fmt"
"math/big"
"strings"
"github.com/ethereum/go-ethereum/common"
)
type
hexdata
struct
{
data
[]
byte
}
func
(
d
*
hexdata
)
MarshalJSON
()
([]
byte
,
error
)
{
v
:=
common
.
Bytes2Hex
(
d
.
data
)
return
json
.
Marshal
(
"0x"
+
v
)
}
func
(
d
*
hexdata
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
d
.
data
=
common
.
FromHex
(
string
(
b
))
return
nil
}
func
newHexData
(
input
interface
{})
*
hexdata
{
d
:=
new
(
hexdata
)
switch
input
.
(
type
)
{
case
[]
byte
:
d
.
data
=
input
.
([]
byte
)
case
common
.
Hash
:
d
.
data
=
input
.
(
common
.
Hash
)
.
Bytes
()
case
common
.
Address
:
d
.
data
=
input
.
(
common
.
Address
)
.
Bytes
()
case
*
big
.
Int
:
d
.
data
=
input
.
(
*
big
.
Int
)
.
Bytes
()
case
int64
:
d
.
data
=
big
.
NewInt
(
input
.
(
int64
))
.
Bytes
()
case
uint64
:
d
.
data
=
big
.
NewInt
(
int64
(
input
.
(
uint64
)))
.
Bytes
()
case
int
:
d
.
data
=
big
.
NewInt
(
int64
(
input
.
(
int
)))
.
Bytes
()
case
uint
:
d
.
data
=
big
.
NewInt
(
int64
(
input
.
(
uint
)))
.
Bytes
()
case
string
:
d
.
data
=
common
.
Big
(
input
.
(
string
))
.
Bytes
()
default
:
d
.
data
=
nil
}
return
d
}
type
hexnum
struct
{
data
[]
byte
}
func
(
d
*
hexnum
)
MarshalJSON
()
([]
byte
,
error
)
{
// Get hex string from bytes
out
:=
common
.
Bytes2Hex
(
d
.
data
)
// Trim leading 0s
out
=
strings
.
Trim
(
out
,
"0"
)
// Output "0x0" when value is 0
if
len
(
out
)
==
0
{
out
=
"0"
}
return
json
.
Marshal
(
"0x"
+
out
)
}
func
(
d
*
hexnum
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
d
.
data
=
common
.
FromHex
(
string
(
b
))
return
nil
}
func
newHexNum
(
input
interface
{})
*
hexnum
{
d
:=
new
(
hexnum
)
d
.
data
=
newHexData
(
input
)
.
data
return
d
}
type
InvalidTypeError
struct
{
method
string
msg
string
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment