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
20b7162a
Commit
20b7162a
authored
Mar 16, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added functions to Hash & Address
* Set, SetString, SetBytes * StringTo*, BytesTo*
parent
dc864ee3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
1 deletion
+37
-1
types.go
common/types.go
+37
-1
No files found.
common/types.go
View file @
20b7162a
...
...
@@ -5,6 +5,25 @@ type (
Address
[
20
]
byte
)
var
(
zeroHash
Hash
zeroAddress
Address
)
func
BytesToHash
(
b
[]
byte
)
Hash
{
var
h
Hash
h
.
SetBytes
(
b
)
return
h
}
func
StringToHash
(
s
string
)
Hash
{
return
BytesToHash
([]
byte
(
s
))
}
func
BytesToAddress
(
b
[]
byte
)
Address
{
var
a
Address
a
.
SetBytes
(
b
)
return
a
}
func
StringToAddress
(
s
string
)
Address
{
return
BytesToAddress
([]
byte
(
s
))
}
// Don't use the default 'String' method in case we want to overwrite
// Get the string representation of the underlying hash
...
...
@@ -24,8 +43,16 @@ func (h Hash) SetBytes(b []byte) {
}
}
// Set string `s` to h. If s is larger than len(h) it will panic
func
(
h
Hash
)
SetString
(
s
string
)
{
h
.
SetBytes
([]
byte
(
s
))
}
// Sets h to other
func
(
h
Hash
)
Set
(
other
Hash
)
{
for
i
,
v
:=
range
other
{
h
[
i
]
=
v
}
}
// Get the string representation of the underlying address
func
(
a
Address
)
Str
()
string
{
return
string
(
a
[
:
])
...
...
@@ -42,4 +69,13 @@ func (a Address) SetBytes(b []byte) {
a
[
i
]
=
b
[
i
]
}
}
func
(
a
Address
)
SetString
(
s
string
)
{
h
.
SetBytes
([]
byte
(
a
))
}
// Set string `s` to a. If s is larger than len(a) it will panic
func
(
a
Address
)
SetString
(
s
string
)
{
a
.
SetBytes
([]
byte
(
s
))
}
// Sets a to other
func
(
a
Address
)
Set
(
other
Address
)
{
for
i
,
v
:=
range
other
{
a
[
i
]
=
v
}
}
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