Module Prove.Database

val exists : Registry.t -> db_index:int64 -> key:bytes -> (bool, Registry.invalid_argument_error) Stdlib.result

exists registry ~db_index ~key returns true if key exists in the database at db_index. Returns an error if db_index is out of bounds or key exceeds 256 bytes.

val set : Registry.t -> db_index:int64 -> key:bytes -> value:bytes -> (unit, Registry.invalid_argument_error) Stdlib.result

set registry ~db_index ~key ~value associates key with value in the database at db_index, replacing any previous value entirely. Returns an error if db_index is out of bounds or key exceeds 256 bytes.

val write : Registry.t -> db_index:int64 -> key:bytes -> offset:int64 -> value:bytes -> (int64, Registry.invalid_argument_error) Stdlib.result

write registry ~db_index ~key ~offset ~value writes value starting at byte position offset within the existing value associated with key. The value is extended if the write goes past the current end but is never truncated. Writing at offset 0L to a non-existent key creates it. Returns the number of bytes written (i.e. Bytes.length value). Returns an error if the key does not exist and offset is non-zero, if offset exceeds the current value length, if key exceeds 256 bytes, or if db_index is out of bounds.

val read : Registry.t -> db_index:int64 -> key:bytes -> offset:int64 -> len:int64 -> (bytes, Registry.invalid_argument_error) Stdlib.result

read registry ~db_index ~key ~offset ~len reads up to len bytes starting at byte position offset from the value associated with key. The returned byte sequence may be shorter than len if the value ends before offset + len. Returns an error if the key does not exist, if offset exceeds the value length, if key exceeds 256 bytes, or if db_index is out of bounds.

val value_length : Registry.t -> db_index:int64 -> key:bytes -> (int64, Registry.invalid_argument_error) Stdlib.result

value_length registry ~db_index ~key returns the length in bytes of the value associated with key. Returns an error if the key does not exist, if key exceeds 256 bytes, or if db_index is out of bounds.

val delete : Registry.t -> db_index:int64 -> key:bytes -> (unit, Registry.invalid_argument_error) Stdlib.result

delete registry ~db_index ~key removes key and its associated value. Deleting a non-existent key is a silent no-op (the root hash is unchanged). Returns an error if key exceeds 256 bytes or db_index is out of bounds.

val hash : Registry.t -> db_index:int64 -> (bytes, Registry.invalid_argument_error) Stdlib.result

hash registry ~db_index returns the Merkle root hash of the database at db_index. Returns an error if db_index is out of bounds.