Class MerkleTrie
An ITrie implementation implemented Merkle Patricia Trie.
Implements
Namespace: Libplanet.Store.Trie
Assembly: Libplanet.dll
Syntax
public class MerkleTrie : object, 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. Hash(Byte[]) is used to hash them. |
Fields
| Improve this Doc View SourceEmptyRootHash
Declaration
public static readonly HashDigest<SHA256> EmptyRootHash
Field Value
Type | Description |
---|---|
HashDigest<SHA256> |
Properties
| Improve this Doc View SourceHash
Declaration
public HashDigest<SHA256> Hash { get; }
Property Value
Type | Description |
---|---|
HashDigest<SHA256> |
Methods
| Improve this Doc View SourceCommit(Boolean)
Cleans up and stores the ITrie in storage.
Declaration
public ITrie Commit(bool rehearsal = false)
Parameters
Type | Name | Description |
---|---|---|
Boolean | rehearsal | Whether to store nodes. |
Returns
Type | Description |
---|---|
ITrie | Returns new committed ITrie. |
Set(Byte[], IValue)
Stores the value
to the
node corresponding to given key
.
Declaration
public ITrie Set(byte[] key, IValue value)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | key | An index to look with TryGet(Byte[], out Nullable<IValue>) after. |
IValue | value | The value to store. |
Returns
Type | Description |
---|---|
ITrie | Returns new updated ITrie. |
TryGet(Byte[], out Nullable<IValue>)
Gets the value stored with key
in Set(Byte[], IValue).
Declaration
public bool TryGet(byte[] key, out IValue? value)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | key | The key used in Set(Byte[], IValue) to store a value. |
Nullable<IValue> | value | The reference pointer to be set the value stored. |
Returns
Type | Description |
---|---|
Boolean | If there is a value corresponded to |
Operators
| Improve this Doc View SourceEquality(MerkleTrie, MerkleTrie)
Declaration
public static bool operator ==(MerkleTrie left, MerkleTrie right)
Parameters
Type | Name | Description |
---|---|---|
MerkleTrie | left | |
MerkleTrie | right |
Returns
Type | Description |
---|---|
Boolean |
Inequality(MerkleTrie, MerkleTrie)
Declaration
public static bool operator !=(MerkleTrie left, MerkleTrie right)
Parameters
Type | Name | Description |
---|---|---|
MerkleTrie | left | |
MerkleTrie | right |
Returns
Type | Description |
---|---|
Boolean |