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
5c1e0a6d
Commit
5c1e0a6d
authored
Jun 29, 2014
by
zelig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move ethutil hex conversion functions to bytes
parent
7489fb78
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
2 deletions
+12
-2
bytes.go
ethutil/bytes.go
+12
-2
No files found.
ethutil/bytes.go
View file @
5c1e0a6d
...
...
@@ -3,6 +3,7 @@ package ethutil
import
(
"bytes"
"encoding/binary"
"encoding/hex"
"fmt"
"math/big"
"strings"
...
...
@@ -91,9 +92,18 @@ func IsHex(str string) bool {
return
l
>=
4
&&
l
%
2
==
0
&&
str
[
0
:
2
]
==
"0x"
}
func
Bytes2Hex
(
d
[]
byte
)
string
{
return
hex
.
EncodeToString
(
d
)
}
func
Hex2Bytes
(
str
string
)
[]
byte
{
h
,
_
:=
hex
.
DecodeString
(
str
)
return
h
}
func
StringToByteFunc
(
str
string
,
cb
func
(
str
string
)
[]
byte
)
(
ret
[]
byte
)
{
if
len
(
str
)
>
1
&&
str
[
0
:
2
]
==
"0x"
&&
!
strings
.
Contains
(
str
,
"
\n
"
)
{
ret
=
FromHex
(
str
[
2
:
])
ret
=
Hex2Bytes
(
str
[
2
:
])
}
else
{
ret
=
cb
(
str
)
}
...
...
@@ -110,7 +120,7 @@ func FormatData(data string) []byte {
if
data
[
0
:
1
]
==
"
\"
"
&&
data
[
len
(
data
)
-
1
:
]
==
"
\"
"
{
d
.
SetBytes
([]
byte
(
data
[
1
:
len
(
data
)
-
1
]))
}
else
if
len
(
data
)
>
1
&&
data
[
:
2
]
==
"0x"
{
d
.
SetBytes
(
FromHex
(
data
[
2
:
]))
d
.
SetBytes
(
Hex2Bytes
(
data
[
2
:
]))
}
else
{
d
.
SetString
(
data
,
0
)
}
...
...
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