@@ -30,17 +30,25 @@ import { BaseTrie as Trie } from 'merkle-patricia-tree'
3030const db = level (' ./testdb' )
3131const trie = new Trie (db )
3232
33- await trie .put (Buffer .from (' test' ), Buffer .from (' one' ))
34- const value = await trie .get (Buffer .from (' test' ))
35- console .log (value .toString ())
33+ async function test() {
34+ await trie .put (Buffer .from (' test' ), Buffer .from (' one' ))
35+ const value = await trie .get (Buffer .from (' test' ))
36+ console .log (value .toString ()) // 'one'
37+ }
38+
39+ await test ()
3640```
3741
3842## Merkle Proofs
3943
4044``` typescript
41- const prove = await Trie .prove (trie , Buffer .from (' test' ))
42- const value = await Trie .verifyProof (trie .root , Buffer .from (' test' ), prove )
43- console .log (value .toString ())
45+ async function test() {
46+ const prove = await Trie .prove (trie , Buffer .from (' test' ))
47+ const value = await Trie .verifyProof (trie .root , Buffer .from (' test' ), prove )
48+ console .log (value .toString ())
49+ }
50+
51+ await test ()
4452```
4553
4654## Read stream on Geth DB
@@ -79,28 +87,32 @@ const trie = new Trie(db, stateRoot)
7987
8088const address = ' AN_ETHEREUM_ACCOUNT_ADDRESS'
8189
82- const data = await trie .get (address )
83- const acc = new Account (data )
84-
85- console .log (' -------State-------' )
86- console .log (` nonce: ${new BN (acc .nonce )} ` )
87- console .log (` balance in wei: ${new BN (acc .balance )} ` )
88- console .log (` storageRoot: ${bufferToHex (acc .stateRoot )} ` )
89- console .log (` codeHash: ${bufferToHex (acc .codeHash )} ` )
90-
91- let storageTrie = trie .copy ()
92- storageTrie .root = acc .stateRoot
93-
94- console .log (' ------Storage------' )
95- const stream = storageTrie .createReadStream ()
96- stream
97- .on (' data' , (data ) => {
98- console .log (` key: ${bufferToHex (data .key )} ` )
99- console .log (` Value: ${bufferToHex (rlp .decode (data .value ))} ` )
100- })
101- .on (' end' , () => {
102- console .log (' Finished reading storage.' )
103- })
90+ async function test() {
91+ const data = await trie .get (address )
92+ const acc = new Account (data )
93+
94+ console .log (' -------State-------' )
95+ console .log (` nonce: ${new BN (acc .nonce )} ` )
96+ console .log (` balance in wei: ${new BN (acc .balance )} ` )
97+ console .log (` storageRoot: ${bufferToHex (acc .stateRoot )} ` )
98+ console .log (` codeHash: ${bufferToHex (acc .codeHash )} ` )
99+
100+ let storageTrie = trie .copy ()
101+ storageTrie .root = acc .stateRoot
102+
103+ console .log (' ------Storage------' )
104+ const stream = storageTrie .createReadStream ()
105+ stream
106+ .on (' data' , (data ) => {
107+ console .log (` key: ${bufferToHex (data .key )} ` )
108+ console .log (` Value: ${bufferToHex (rlp .decode (data .value ))} ` )
109+ })
110+ .on (' end' , () => {
111+ console .log (' Finished reading storage.' )
112+ })
113+ }
114+
115+ await test ()
104116```
105117
106118# API
0 commit comments