1- # ethutil
1+ # common
22
33[ ![ Build
44Status] ( https://travis-ci.org/ethereum/go-ethereum.png?branch=master )] ( https://travis-ci.org/ethereum/go-ethereum )
55
6- The ethutil package contains the ethereum utility library.
6+ The common package contains the ethereum utility library.
77
88# Installation
99
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 ` .
1112
1213# Usage
1314
1415## RLP (Recursive Linear Prefix) Encoding
1516
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.
1819
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.
2122
2223``` go
23- rlp := ethutil .Encode (" doge" )
24+ rlp := common .Encode (" doge" )
2425fmt.Printf (" %q \n " , rlp) // => "\0x83dog"
2526
26- rlp = ethutil .Encode ([]interface {}{" dog" , " cat" })
27+ rlp = common .Encode ([]interface {}{" dog" , " cat" })
2728fmt.Printf (" %q \n " , rlp) // => "\0xc8\0x83dog\0x83cat"
28- decoded := ethutil .Decode (rlp)
29+ decoded := common .Decode (rlp)
2930fmt.Println (decoded) // => ["dog" "cat"]
3031```
3132
3233## Patricia Trie
3334
34- Patricie Tree is a merkle trie utilized by the Ethereum project.
35+ Patricie Tree is a merkle trie used by the Ethereum project.
3536
3637More in depth information about the (modified) Patricia Trie can be
3738found on the [ Wiki] ( http://wiki.ethereum.org/index.php/Patricia_Tree ) .
3839
3940The 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` .
4142
4243``` go
4344db := NewDatabase ()
4445
4546// db, root
46- trie := ethutil .NewTrie (db, " " )
47+ trie := common .NewTrie (db, " " )
4748
4849trie.Put (" puppy" , " dog" )
4950trie.Put (" horse" , " stallion" )
@@ -65,7 +66,7 @@ all (key, value) bindings.
6566// ... Create db/trie
6667
6768// 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 }})
6970// Store the RLP encoded value of the list
7071trie.Put (" mykey" , value)
7172```
@@ -89,7 +90,7 @@ type (e.g. `Slice()` returns []interface{}, `Uint()` return 0, etc).
8990` Append(v) ` appends the value (v) to the current value/list.
9091
9192``` go
92- val := ethutil .NewEmptyValue ().Append (1 ).Append (" 2" )
93+ val := common .NewEmptyValue ().Append (1 ).Append (" 2" )
9394val.AppendList ().Append (3 )
9495```
9596
@@ -110,7 +111,7 @@ val.AppendList().Append(3)
110111` Byte() ` returns the value as a single byte.
111112
112113``` go
113- val := ethutil .NewValue ([]interface {}{1 ," 2" ,[]interface {}{3 }})
114+ val := common .NewValue ([]interface {}{1 ," 2" ,[]interface {}{3 }})
114115val.Get (0 ).Uint () // => 1
115116val.Get (1 ).Str () // => "2"
116117s := val.Get (2 ) // => Value([]interface{}{3})
@@ -122,7 +123,7 @@ s.Get(0).Uint() // => 3
122123Decoding streams of RLP data is simplified
123124
124125``` go
125- val := ethutil .NewValueFromBytes (rlpData)
126+ val := common .NewValueFromBytes (rlpData)
126127val.Get (0 ).Uint ()
127128```
128129
@@ -132,7 +133,7 @@ Encoding from Value to RLP is done with the `Encode` method. The
132133underlying value can be anything RLP can encode (int, str, lists, bytes)
133134
134135``` go
135- val := ethutil .NewValue ([]interface {}{1 ," 2" ,[]interface {}{3 }})
136+ val := common .NewValue ([]interface {}{1 ," 2" ,[]interface {}{3 }})
136137rlp := val.Encode ()
137138// Store the rlp data
138139Store (rlp)
0 commit comments