Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
4ce3dfe9
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4ce3dfe9
编写于
9月 10, 2015
作者:
J
Jeff R. Allen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
common: Update README.md for the current package name
上级
90f1fe0e
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
19 addition
and
18 deletion
+19
-18
common/README.md
common/README.md
+19
-18
未找到文件。
common/README.md
浏览文件 @
4ce3dfe9
#
ethutil
#
common
[
![Build
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
`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
## RLP (Recursive Linear Prefix) Encoding
RLP Encoding is an encoding scheme u
tiliz
ed by the Ethereum project. It
encodes any native value or list to string.
RLP Encoding is an encoding scheme u
s
ed by the Ethereum project. It
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
)
article.
More in depth information about the
encoding scheme see the
[
Wiki
](
http://wiki.ethereum.org/index.php/RLP
)
article.
```
go
rlp
:=
ethutil
.
Encode
(
"doge"
)
rlp
:=
common
.
Encode
(
"doge"
)
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"
decoded
:=
ethutil
.
Decode
(
rlp
)
decoded
:=
common
.
Decode
(
rlp
)
fmt
.
Println
(
decoded
)
// => ["dog" "cat"]
```
## 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
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
it satisfies the Database interface found in
`
ethutil
/db.go`
.
it satisfies the Database interface found in
`
common
/db.go`
.
```
go
db
:=
NewDatabase
()
// db, root
trie
:=
ethutil
.
NewTrie
(
db
,
""
)
trie
:=
common
.
NewTrie
(
db
,
""
)
trie
.
Put
(
"puppy"
,
"dog"
)
trie
.
Put
(
"horse"
,
"stallion"
)
...
...
@@ -65,7 +66,7 @@ all (key, value) bindings.
// ... Create db/trie
// 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
trie
.
Put
(
"mykey"
,
value
)
```
...
...
@@ -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.
```
go
val
:=
ethutil
.
NewEmptyValue
()
.
Append
(
1
)
.
Append
(
"2"
)
val
:=
common
.
NewEmptyValue
()
.
Append
(
1
)
.
Append
(
"2"
)
val
.
AppendList
()
.
Append
(
3
)
```
...
...
@@ -110,7 +111,7 @@ val.AppendList().Append(3)
`Byte()`
returns the value as a single byte.
```
go
val
:=
ethutil
.
NewValue
([]
interface
{}{
1
,
"2"
,[]
interface
{}{
3
}})
val
:=
common
.
NewValue
([]
interface
{}{
1
,
"2"
,[]
interface
{}{
3
}})
val
.
Get
(
0
)
.
Uint
()
// => 1
val
.
Get
(
1
)
.
Str
()
// => "2"
s
:=
val
.
Get
(
2
)
// => Value([]interface{}{3})
...
...
@@ -122,7 +123,7 @@ s.Get(0).Uint() // => 3
Decoding streams of RLP data is simplified
```
go
val
:=
ethutil
.
NewValueFromBytes
(
rlpData
)
val
:=
common
.
NewValueFromBytes
(
rlpData
)
val
.
Get
(
0
)
.
Uint
()
```
...
...
@@ -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)
```
go
val
:=
ethutil
.
NewValue
([]
interface
{}{
1
,
"2"
,[]
interface
{}{
3
}})
val
:=
common
.
NewValue
([]
interface
{}{
1
,
"2"
,[]
interface
{}{
3
}})
rlp
:=
val
.
Encode
()
// Store the rlp data
Store
(
rlp
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录