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
ac6248ed
Commit
ac6248ed
authored
Sep 17, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1793 from jeffallen/typo
common: Update README.md for the current package name
parents
bdf4fd60
4ce3dfe9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
18 deletions
+19
-18
README.md
common/README.md
+19
-18
No files found.
common/README.md
View file @
ac6248ed
#
ethutil
#
common
[
!
[
Build
[
!
[
Build
Status](https://travis-ci.org/ethereum/go-ethereum.png?branch=master)](https://travis-ci.org/ethereum/go-ethereum)
Status](https://travis-ci.org/ethereum/go-ethereum.png?branch=master)](https://travis-ci.org/ethereum/go-ethereum)
The
ethutil
package contains the ethereum utility library.
The
common
package contains the ethereum utility library.
# Installation
# Installation
`go get github.com/ethereum/ethutil-go`
As a subdirectory the main go-ethereum repository, you get it with
`go get github.com/ethereum/go-ethereum`
.
# Usage
# Usage
## RLP (Recursive Linear Prefix) Encoding
## RLP (Recursive Linear Prefix) Encoding
RLP Encoding is an encoding scheme u
tiliz
ed by the Ethereum project. It
RLP Encoding is an encoding scheme u
s
ed by the Ethereum project. It
encodes any native value or list to string.
encodes any native value or list to
a
string.
More in depth information about the
Encoding scheme see the
[
Wiki
](
http://wiki.ethereum.org/index.php/RLP
)
More in depth information about the
encoding scheme see the
article.
[
Wiki
](
http://wiki.ethereum.org/index.php/RLP
)
article.
```
go
```
go
rlp
:=
ethutil
.
Encode
(
"doge"
)
rlp
:=
common
.
Encode
(
"doge"
)
fmt
.
Printf
(
"%q
\n
"
,
rlp
)
// => "\0x83dog"
fmt
.
Printf
(
"%q
\n
"
,
rlp
)
// => "\0x83dog"
rlp
=
ethutil
.
Encode
([]
interface
{}{
"dog"
,
"cat"
})
rlp
=
common
.
Encode
([]
interface
{}{
"dog"
,
"cat"
})
fmt
.
Printf
(
"%q
\n
"
,
rlp
)
// => "\0xc8\0x83dog\0x83cat"
fmt
.
Printf
(
"%q
\n
"
,
rlp
)
// => "\0xc8\0x83dog\0x83cat"
decoded
:=
ethutil
.
Decode
(
rlp
)
decoded
:=
common
.
Decode
(
rlp
)
fmt
.
Println
(
decoded
)
// => ["dog" "cat"]
fmt
.
Println
(
decoded
)
// => ["dog" "cat"]
```
```
## Patricia Trie
## Patricia Trie
Patricie Tree is a merkle trie u
tiliz
ed by the Ethereum project.
Patricie Tree is a merkle trie u
s
ed by the Ethereum project.
More in depth information about the (modified) Patricia Trie can be
More in depth information about the (modified) Patricia Trie can be
found on the
[
Wiki
](
http://wiki.ethereum.org/index.php/Patricia_Tree
)
.
found on the
[
Wiki
](
http://wiki.ethereum.org/index.php/Patricia_Tree
)
.
The patricia trie uses a db as backend and could be anything as long as
The patricia trie uses a db as backend and could be anything as long as
it satisfies the Database interface found in
`
ethutil
/db.go`
.
it satisfies the Database interface found in
`
common
/db.go`
.
```
go
```
go
db
:=
NewDatabase
()
db
:=
NewDatabase
()
// db, root
// db, root
trie
:=
ethutil
.
NewTrie
(
db
,
""
)
trie
:=
common
.
NewTrie
(
db
,
""
)
trie
.
Put
(
"puppy"
,
"dog"
)
trie
.
Put
(
"puppy"
,
"dog"
)
trie
.
Put
(
"horse"
,
"stallion"
)
trie
.
Put
(
"horse"
,
"stallion"
)
...
@@ -65,7 +66,7 @@ all (key, value) bindings.
...
@@ -65,7 +66,7 @@ all (key, value) bindings.
// ... Create db/trie
// ... Create db/trie
// Note that RLP uses interface slices as list
// Note that RLP uses interface slices as list
value
:=
ethutil
.
Encode
([]
interface
{}{
"one"
,
2
,
"three"
,
[]
interface
{}{
42
}})
value
:=
common
.
Encode
([]
interface
{}{
"one"
,
2
,
"three"
,
[]
interface
{}{
42
}})
// Store the RLP encoded value of the list
// Store the RLP encoded value of the list
trie
.
Put
(
"mykey"
,
value
)
trie
.
Put
(
"mykey"
,
value
)
```
```
...
@@ -89,7 +90,7 @@ type (e.g. `Slice()` returns []interface{}, `Uint()` return 0, etc).
...
@@ -89,7 +90,7 @@ type (e.g. `Slice()` returns []interface{}, `Uint()` return 0, etc).
`Append(v)`
appends the value (v) to the current value/list.
`Append(v)`
appends the value (v) to the current value/list.
```
go
```
go
val
:=
ethutil
.
NewEmptyValue
()
.
Append
(
1
)
.
Append
(
"2"
)
val
:=
common
.
NewEmptyValue
()
.
Append
(
1
)
.
Append
(
"2"
)
val
.
AppendList
()
.
Append
(
3
)
val
.
AppendList
()
.
Append
(
3
)
```
```
...
@@ -110,7 +111,7 @@ val.AppendList().Append(3)
...
@@ -110,7 +111,7 @@ val.AppendList().Append(3)
`Byte()`
returns the value as a single byte.
`Byte()`
returns the value as a single byte.
```
go
```
go
val
:=
ethutil
.
NewValue
([]
interface
{}{
1
,
"2"
,[]
interface
{}{
3
}})
val
:=
common
.
NewValue
([]
interface
{}{
1
,
"2"
,[]
interface
{}{
3
}})
val
.
Get
(
0
)
.
Uint
()
// => 1
val
.
Get
(
0
)
.
Uint
()
// => 1
val
.
Get
(
1
)
.
Str
()
// => "2"
val
.
Get
(
1
)
.
Str
()
// => "2"
s
:=
val
.
Get
(
2
)
// => Value([]interface{}{3})
s
:=
val
.
Get
(
2
)
// => Value([]interface{}{3})
...
@@ -122,7 +123,7 @@ s.Get(0).Uint() // => 3
...
@@ -122,7 +123,7 @@ s.Get(0).Uint() // => 3
Decoding streams of RLP data is simplified
Decoding streams of RLP data is simplified
```
go
```
go
val
:=
ethutil
.
NewValueFromBytes
(
rlpData
)
val
:=
common
.
NewValueFromBytes
(
rlpData
)
val
.
Get
(
0
)
.
Uint
()
val
.
Get
(
0
)
.
Uint
()
```
```
...
@@ -132,7 +133,7 @@ Encoding from Value to RLP is done with the `Encode` method. The
...
@@ -132,7 +133,7 @@ Encoding from Value to RLP is done with the `Encode` method. The
underlying value can be anything RLP can encode (int, str, lists, bytes)
underlying value can be anything RLP can encode (int, str, lists, bytes)
```
go
```
go
val
:=
ethutil
.
NewValue
([]
interface
{}{
1
,
"2"
,[]
interface
{}{
3
}})
val
:=
common
.
NewValue
([]
interface
{}{
1
,
"2"
,[]
interface
{}{
3
}})
rlp
:=
val
.
Encode
()
rlp
:=
val
.
Encode
()
// Store the rlp data
// Store the rlp data
Store
(
rlp
)
Store
(
rlp
)
...
...
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