tuweni / org.apache.tuweni.trie / MerklePatriciaTrie

MerklePatriciaTrie

class MerklePatriciaTrie<V> : MerkleTrie<Bytes, V> (source)

An in-memory MerkleTrie.

Parameters

valueSerializer - A function for serializing values to bytes.

Parameters

Constructors

<init>

MerklePatriciaTrie(valueSerializer: (V) -> Bytes)

Creates an empty trie.

Functions

get

suspend fun get(key: Bytes): V?

Returns the value that corresponds to the specified key, or an empty byte array if no such value exists.

getAsync

fun getAsync(key: Bytes): AsyncResult<V?>

Returns the value that corresponds to the specified key, or an empty byte array if no such value exists.

put

suspend fun put(key: Bytes, value: V?): Unit

Updates the value that corresponds to the specified key, creating the value if one does not already exist.

putAsync

fun putAsync(key: Bytes, value: V?): AsyncCompletion

Updates the value that corresponds to the specified key, creating the value if one does not already exist.

remove

suspend fun remove(key: Bytes): Unit

Deletes the value that corresponds to the specified key, if such a value exists.

removeAsync

fun removeAsync(key: Bytes): AsyncCompletion

Deletes the value that corresponds to the specified key, if such a value exists.

rootHash

fun rootHash(): Bytes32

Returns the KECCAK256 hash of the root node of the trie.

toString

fun toString(): String

Inherited Functions

getAsync

open fun getAsync(dispatcher: CoroutineDispatcher, key: K): AsyncResult<V?>

Returns the value that corresponds to the specified key, or an empty byte array if no such value exists.

putAsync

open fun putAsync(dispatcher: CoroutineDispatcher, key: K, value: V?): AsyncCompletion

Updates the value that corresponds to the specified key, creating the value if one does not already exist.

removeAsync

open fun removeAsync(dispatcher: CoroutineDispatcher, key: K): AsyncCompletion

Deletes the value that corresponds to the specified key, if such a value exists.

Companion Object Functions

create

fun <V> create(valueSerializer: Function<V, Bytes>): MerklePatriciaTrie<V>

Create a trie.

storingBytes

fun storingBytes(): MerklePatriciaTrie<Bytes>

Create a trie with keys and values of type Bytes.

storingStrings

fun storingStrings(): MerklePatriciaTrie<String>

Create a trie with value of type String.