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
08b21acf
Commit
08b21acf
authored
Mar 22, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move ToHex/FromHex into bytes
parent
9682a3ef
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
42 deletions
+43
-42
bytes.go
common/bytes.go
+22
-0
bytes_test.go
common/bytes_test.go
+21
-0
common.go
common/common.go
+0
-21
common_test.go
common/common_test.go
+0
-21
No files found.
common/bytes.go
View file @
08b21acf
...
...
@@ -9,6 +9,28 @@ import (
"strings"
)
func
ToHex
(
b
[]
byte
)
string
{
hex
:=
Bytes2Hex
(
b
)
// Prefer output of "0x0" instead of "0x"
if
len
(
hex
)
==
0
{
hex
=
"0"
}
return
"0x"
+
hex
}
func
FromHex
(
s
string
)
[]
byte
{
if
len
(
s
)
>
1
{
if
s
[
0
:
2
]
==
"0x"
{
s
=
s
[
2
:
]
}
if
len
(
s
)
%
2
==
1
{
s
=
"0"
+
s
}
return
Hex2Bytes
(
s
)
}
return
nil
}
type
Bytes
[]
byte
func
(
self
Bytes
)
String
()
string
{
...
...
common/bytes_test.go
View file @
08b21acf
package
common
import
(
"bytes"
"testing"
checker
"gopkg.in/check.v1"
)
...
...
@@ -191,3 +194,21 @@ func (s *BytesSuite) TestRightPadString(c *checker.C) {
c
.
Assert
(
resstd
,
checker
.
Equals
,
exp
)
c
.
Assert
(
resshrt
,
checker
.
Equals
,
val
)
}
func
TestFromHex
(
t
*
testing
.
T
)
{
input
:=
"0x01"
expected
:=
[]
byte
{
1
}
result
:=
FromHex
(
input
)
if
bytes
.
Compare
(
expected
,
result
)
!=
0
{
t
.
Errorf
(
"Expected % x got % x"
,
expected
,
result
)
}
}
func
TestFromHexOddLength
(
t
*
testing
.
T
)
{
input
:=
"0x1"
expected
:=
[]
byte
{
1
}
result
:=
FromHex
(
input
)
if
bytes
.
Compare
(
expected
,
result
)
!=
0
{
t
.
Errorf
(
"Expected % x got % x"
,
expected
,
result
)
}
}
common/common.go
View file @
08b21acf
...
...
@@ -65,27 +65,6 @@ func DefaultDataDir() string {
}
}
func
ToHex
(
b
[]
byte
)
string
{
hex
:=
Bytes2Hex
(
b
)
// Prefer output of "0x0" instead of "0x"
if
len
(
hex
)
==
0
{
hex
=
"0"
}
return
"0x"
+
hex
}
func
FromHex
(
s
string
)
[]
byte
{
if
len
(
s
)
>
1
{
if
s
[
0
:
2
]
==
"0x"
{
s
=
s
[
2
:
]
}
if
len
(
s
)
%
2
==
1
{
s
=
"0"
+
s
}
return
Hex2Bytes
(
s
)
}
return
nil
}
func
IsWindows
()
bool
{
return
runtime
.
GOOS
==
"windows"
}
...
...
common/common_test.go
View file @
08b21acf
package
common
import
(
"bytes"
"math/big"
"os"
"testing"
checker
"gopkg.in/check.v1"
)
...
...
@@ -68,22 +66,3 @@ func (s *CommonSuite) TestLarge(c *checker.C) {
c
.
Assert
(
adalarge
,
checker
.
Equals
,
"10000E7 Einstein"
)
c
.
Assert
(
weilarge
,
checker
.
Equals
,
"100 Babbage"
)
}
//fromHex
func
TestFromHex
(
t
*
testing
.
T
)
{
input
:=
"0x01"
expected
:=
[]
byte
{
1
}
result
:=
FromHex
(
input
)
if
bytes
.
Compare
(
expected
,
result
)
!=
0
{
t
.
Errorf
(
"Expected % x got % x"
,
expected
,
result
)
}
}
func
TestFromHexOddLength
(
t
*
testing
.
T
)
{
input
:=
"0x1"
expected
:=
[]
byte
{
1
}
result
:=
FromHex
(
input
)
if
bytes
.
Compare
(
expected
,
result
)
!=
0
{
t
.
Errorf
(
"Expected % x got % x"
,
expected
,
result
)
}
}
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