Class MerkleTrie
An ITrie implementation implemented Merkle Patricia Trie.
Implements
Inherited Members
Namespace: Libplanet.Store.Trie
Assembly: Libplanet.Store.dll
Syntax
public class MerkleTrie : ITrie
Constructors
| Improve this Doc View SourceMerkleTrie(IKeyValueStore, HashDigest<SHA256>, Boolean)
An ITrie implementation.
Declaration
public MerkleTrie(IKeyValueStore keyValueStore, HashDigest<SHA256> rootHash, bool secure = false)
Parameters
| Type | Name | Description |
|---|---|---|
| IKeyValueStore | keyValueStore | The IKeyValueStore storage to store nodes. |
| HashDigest<SHA256> | rootHash | The root Hash of MerkleTrie. |
| Boolean | secure | Whether to use MerkleTrie in secure mode. If it is turned on, MerkleTrie internally stores hashed keys instead of bare keys. Keys will be hashed with SHA-256. |
MerkleTrie(IKeyValueStore, INode, Boolean)
An ITrie implementation.
Declaration
public MerkleTrie(IKeyValueStore keyValueStore, INode root = null, bool secure = false)
Parameters
| Type | Name | Description |
|---|---|---|
| IKeyValueStore | keyValueStore | The IKeyValueStore storage to store nodes. |
| INode | root | The root node of MerkleTrie. If it is null, it will be treated like empty trie. |
| Boolean | secure | Whether to use MerkleTrie in secure mode. If it is true, MerkleTrie will stores the value with the hashed result from the given key as the key. Keys will be hashed with SHA-256. |
Fields
| Improve this Doc View SourceEmptyRootHash
An ITrie implementation implemented Merkle Patricia Trie.
Declaration
public static readonly HashDigest<SHA256> EmptyRootHash
Field Value
| Type | Description |
|---|---|
| HashDigest<SHA256> |
Properties
| Improve this Doc View SourceHash
The state root hash of the trie.
Declaration
public HashDigest<SHA256> Hash { get; }
Property Value
| Type | Description |
|---|---|
| HashDigest<SHA256> |
Recorded
Whether the trie root is recorded in the store.
Declaration
public bool Recorded { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
Remarks
Empty root is considered as recorded.
Root
An ITrie implementation implemented Merkle Patricia Trie.
Declaration
public INode Root { get; }
Property Value
| Type | Description |
|---|---|
| INode |
Methods
| Improve this Doc View SourceCommit()
Cleans up and stores the ITrie in storage.
Declaration
public ITrie Commit()
Returns
| Type | Description |
|---|---|
| ITrie | Returns new committed ITrie. |
Get(KeyBytes)
Gets the values stored with key in Set(in KeyBytes, IValue).
Declaration
public IValue Get(KeyBytes key)
Parameters
| Type | Name | Description |
|---|---|---|
| KeyBytes | key | The key used in Set(in KeyBytes, IValue) to store a value. |
Returns
| Type | Description |
|---|---|
| Bencodex.Types.IValue | The value associated to the specified |
Get(IReadOnlyList<KeyBytes>)
Gets the values stored with keys in Set(in KeyBytes, IValue).
Declaration
public IReadOnlyList<IValue> Get(IReadOnlyList<KeyBytes> keys)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyList<KeyBytes> | keys | The keys used in Set(in KeyBytes, IValue) to store a value. |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<Bencodex.Types.IValue> | The values associated to the specified |
IterateNodes()
An ITrie implementation implemented Merkle Patricia Trie.
Declaration
public IEnumerable<(INode Node, KeyBytes Path)> IterateNodes()
Returns
| Type | Description |
|---|---|
| IEnumerable<(T1 Item1, T2 Item2)<INode, KeyBytes>> |
Set(in KeyBytes, IValue)
Stores the value to the
node corresponding to given key.
Declaration
public ITrie Set(in KeyBytes key, IValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| KeyBytes | key | The unique key to associate with the |
| Bencodex.Types.IValue | value | The value to store. |
Returns
| Type | Description |
|---|---|
| ITrie | Returns new updated ITrie. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when the given
|