diff options
| author | Estevan Castilho <tevo@riajuu.net> | 2026-08-27 01:35:53 +0000 |
|---|---|---|
| committer | Estevan Castilho <tevo@riajuu.net> | 2026-08-27 01:41:12 +0000 |
| commit | e61404f0219cd8f07c6c278f7ee952c70ce5bdf4 (patch) | |
| tree | 412aa6ca71df835fb154427a32bb2573944faa8a /lib/kernel/Storage.ml | |
| parent | 9efb32195a905de2d66ce29164cc22970833c2d7 (diff) | |
| download | RNT-e61404f0219cd8f07c6c278f7ee952c70ce5bdf4.tar.gz RNT-e61404f0219cd8f07c6c278f7ee952c70ce5bdf4.zip | |
Branch serialization
Diffstat (limited to 'lib/kernel/Storage.ml')
| -rw-r--r-- | lib/kernel/Storage.ml | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/kernel/Storage.ml b/lib/kernel/Storage.ml index e6a84ba..dd06783 100644 --- a/lib/kernel/Storage.ml +++ b/lib/kernel/Storage.ml @@ -11,6 +11,22 @@ module Make (S : Abstract.Storage.STORAGE) = struct let deref tx { addr; loader } = loader tx addr end + let as_hash = function + | S.Hash h -> h + | _ -> failwith "A label was provided where a hash was expected." + + let to_hum_string = function + | S.Hash h -> "Hash " ^ (Concepts.Hash.to_hum_string h) + | S.Label l -> "Label " ^ l + + module Error = struct + open Concepts.Condition + + let missing_data addr = + condition "missing-data" "An expected value was not found on the underlying storage. Is your database corrupted?" + ("address" |=| Concepts.Value.String (to_hum_string addr)) + end + let finish tx = function | Ok value -> let open Utilities.Result in @@ -31,4 +47,8 @@ module Make (S : Abstract.Storage.STORAGE) = struct let* () = S.put tx (S.Hash address) blob in Ok address + let get_req tx addr = + S.get tx addr + |> Utilities.Result.fmap (Option.to_result ~none:(Error.missing_data addr)) + end |
