1
- # ethutil
1
+ # common
2
2
3
3
[ ![ Build
4
4
Status] ( https://travis-ci.org/ethereum/go-ethereum.png?branch=master )] ( https://travis-ci.org/ethereum/go-ethereum )
5
5
6
- The ethutil package contains the ethereum utility library.
6
+ The common package contains the ethereum utility library.
7
7
8
8
# Installation
9
9
10
- ` go get github.com/ethereum/ethutil-go `
10
+ As a subdirectory the main go-ethereum repository, you get it with
11
+ ` go get github.com/ethereum/go-ethereum ` .
11
12
12
13
# Usage
13
14
14
15
## RLP (Recursive Linear Prefix) Encoding
15
16
16
- RLP Encoding is an encoding scheme utilized by the Ethereum project. It
17
- encodes any native value or list to string.
17
+ RLP Encoding is an encoding scheme used by the Ethereum project. It
18
+ encodes any native value or list to a string.
18
19
19
- More in depth information about the Encoding scheme see the [ Wiki ] ( http://wiki.ethereum.org/index.php/RLP )
20
- article.
20
+ More in depth information about the encoding scheme see the
21
+ [ Wiki ] ( http://wiki.ethereum.org/index.php/RLP ) article.
21
22
22
23
``` go
23
- rlp := ethutil .Encode (" doge" )
24
+ rlp := common .Encode (" doge" )
24
25
fmt.Printf (" %q \n " , rlp) // => "\0x83dog"
25
26
26
- rlp = ethutil .Encode ([]interface {}{" dog" , " cat" })
27
+ rlp = common .Encode ([]interface {}{" dog" , " cat" })
27
28
fmt.Printf (" %q \n " , rlp) // => "\0xc8\0x83dog\0x83cat"
28
- decoded := ethutil .Decode (rlp)
29
+ decoded := common .Decode (rlp)
29
30
fmt.Println (decoded) // => ["dog" "cat"]
30
31
```
31
32
32
33
## Patricia Trie
33
34
34
- Patricie Tree is a merkle trie utilized by the Ethereum project.
35
+ Patricie Tree is a merkle trie used by the Ethereum project.
35
36
36
37
More in depth information about the (modified) Patricia Trie can be
37
38
found on the [ Wiki] ( http://wiki.ethereum.org/index.php/Patricia_Tree ) .
38
39
39
40
The patricia trie uses a db as backend and could be anything as long as
40
- it satisfies the Database interface found in ` ethutil /db.go` .
41
+ it satisfies the Database interface found in ` common /db.go` .
41
42
42
43
``` go
43
44
db := NewDatabase ()
44
45
45
46
// db, root
46
- trie := ethutil .NewTrie (db, " " )
47
+ trie := common .NewTrie (db, " " )
47
48
48
49
trie.Put (" puppy" , " dog" )
49
50
trie.Put (" horse" , " stallion" )
@@ -65,7 +66,7 @@ all (key, value) bindings.
65
66
// ... Create db/trie
66
67
67
68
// Note that RLP uses interface slices as list
68
- value := ethutil .Encode ([]interface {}{" one" , 2 , " three" , []interface {}{42 }})
69
+ value := common .Encode ([]interface {}{" one" , 2 , " three" , []interface {}{42 }})
69
70
// Store the RLP encoded value of the list
70
71
trie.Put (" mykey" , value)
71
72
```
@@ -89,7 +90,7 @@ type (e.g. `Slice()` returns []interface{}, `Uint()` return 0, etc).
89
90
` Append(v) ` appends the value (v) to the current value/list.
90
91
91
92
``` go
92
- val := ethutil .NewEmptyValue ().Append (1 ).Append (" 2" )
93
+ val := common .NewEmptyValue ().Append (1 ).Append (" 2" )
93
94
val.AppendList ().Append (3 )
94
95
```
95
96
@@ -110,7 +111,7 @@ val.AppendList().Append(3)
110
111
` Byte() ` returns the value as a single byte.
111
112
112
113
``` go
113
- val := ethutil .NewValue ([]interface {}{1 ," 2" ,[]interface {}{3 }})
114
+ val := common .NewValue ([]interface {}{1 ," 2" ,[]interface {}{3 }})
114
115
val.Get (0 ).Uint () // => 1
115
116
val.Get (1 ).Str () // => "2"
116
117
s := val.Get (2 ) // => Value([]interface{}{3})
@@ -122,7 +123,7 @@ s.Get(0).Uint() // => 3
122
123
Decoding streams of RLP data is simplified
123
124
124
125
``` go
125
- val := ethutil .NewValueFromBytes (rlpData)
126
+ val := common .NewValueFromBytes (rlpData)
126
127
val.Get (0 ).Uint ()
127
128
```
128
129
@@ -132,7 +133,7 @@ Encoding from Value to RLP is done with the `Encode` method. The
132
133
underlying value can be anything RLP can encode (int, str, lists, bytes)
133
134
134
135
``` go
135
- val := ethutil .NewValue ([]interface {}{1 ," 2" ,[]interface {}{3 }})
136
+ val := common .NewValue ([]interface {}{1 ," 2" ,[]interface {}{3 }})
136
137
rlp := val.Encode ()
137
138
// Store the rlp data
138
139
Store (rlp)
0 commit comments