aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/Storage.ml
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/kernel/Storage.ml20
-rw-r--r--lib/kernel/Storage.mli3
2 files changed, 23 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
diff --git a/lib/kernel/Storage.mli b/lib/kernel/Storage.mli
index 9a10984..b8c0e5b 100644
--- a/lib/kernel/Storage.mli
+++ b/lib/kernel/Storage.mli
@@ -8,7 +8,10 @@ module Make : functor (S : Abstract.Storage.STORAGE) -> sig
val deref : S.transaction -> 'a t -> ('a, Concepts.Condition.condition) result
end
+ val as_hash : S.address -> Concepts.Hash.hash
+
val finish : S.transaction -> ('a, Concepts.Condition.condition) result -> ('a, Concepts.Condition.condition) result
val with_transaction : S.connection -> (S.transaction -> ('a, Concepts.Condition.condition) result) -> ('a, Concepts.Condition.condition) result
val store_blob : S.transaction -> Concepts.Blob.t -> (Concepts.Hash.hash, Concepts.Condition.condition) result
+ val get_req: S.transaction -> S.address -> (Concepts.Blob.t, Concepts.Condition.condition) result
end