-
Notifications
You must be signed in to change notification settings - Fork 763
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
verkle: move static constructor to 'constructors.ts'
- Loading branch information
Showing
4 changed files
with
50 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { KeyEncoding, MapDB, ValueEncoding } from '@ethereumjs/util' | ||
import { loadVerkleCrypto } from 'verkle-cryptography-wasm' | ||
|
||
import { ROOT_DB_KEY } from './types.js' | ||
import { VerkleTree } from './verkleTree.js' | ||
|
||
import type { VerkleTreeOpts } from './types.js' | ||
|
||
export async function createVerkleTree(opts?: VerkleTreeOpts) { | ||
const key = ROOT_DB_KEY | ||
|
||
if (opts?.db !== undefined && opts?.useRootPersistence === true) { | ||
if (opts?.root === undefined) { | ||
opts.root = await opts?.db.get(key, { | ||
keyEncoding: KeyEncoding.Bytes, | ||
valueEncoding: ValueEncoding.Bytes, | ||
}) | ||
} else { | ||
await opts?.db.put(key, opts.root, { | ||
keyEncoding: KeyEncoding.Bytes, | ||
valueEncoding: ValueEncoding.Bytes, | ||
}) | ||
} | ||
} | ||
|
||
if (opts?.verkleCrypto === undefined) { | ||
const verkleCrypto = await loadVerkleCrypto() | ||
if (opts === undefined) | ||
opts = { | ||
verkleCrypto, | ||
db: new MapDB<Uint8Array, Uint8Array>(), | ||
} | ||
else { | ||
opts.verkleCrypto = verkleCrypto | ||
} | ||
} | ||
|
||
const trie = new VerkleTree(opts) | ||
await trie['_createRootNode']() | ||
return trie | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters