diff options
| author | Estevan Castilho <tevo@riajuu.net> | 2026-09-26 00:48:26 +0000 |
|---|---|---|
| committer | Estevan Castilho <tevo@riajuu.net> | 2026-09-26 00:48:26 +0000 |
| commit | c7b754e96714eeeb9d315ee3de402d73a27d47db (patch) | |
| tree | 274792f6cdb60387e9bd4b5b7508463b4228bc4a /lib/kernel/Branch.ml | |
| parent | b06d16a2eb0846799b3b039dee989cf1cb258b6a (diff) | |
| parent | 0ec1e8a052305f5246d7cd66e11300cd29bc6d64 (diff) | |
| download | RNT-c7b754e96714eeeb9d315ee3de402d73a27d47db.tar.gz RNT-c7b754e96714eeeb9d315ee3de402d73a27d47db.zip | |
Merge branch 'branch-registration'
Diffstat (limited to '')
| -rw-r--r-- | lib/kernel/Branch.ml | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/lib/kernel/Branch.ml b/lib/kernel/Branch.ml index b8d331f..53f6fa1 100644 --- a/lib/kernel/Branch.ml +++ b/lib/kernel/Branch.ml @@ -12,12 +12,14 @@ module Make (S : Abstract.Storage.STORAGE) = struct module MultigroupM = Merkle.Interface (S) (Merkle.StringKey) (M) module MMDirectory = Prototype.Directory.OfTree (S) (Merkle.StringKey) (M) module MMAssociative = Prototype.Associative.OfTree (S) (Merkle.StringKey) + module MMAddressable = Prototype.Addressable.OfTree (S) (Merkle.StringKey) module Error = struct open Concepts.Condition - let incomplete_branch addr = condition "incomplete-branch" "A stored branch is missing part of its expected structure. Is your storage corrupted?" - ("address" |=| Concepts.Value.String (Concepts.Hash.to_hum_string addr)) + let incomplete_branch addr = + condition "incomplete-branch" "A stored branch is missing part of its expected structure. Is your storage corrupted?" + ("address" |=| Concepts.Value.String (Concepts.Hash.to_hum_string addr)) end type t = { @@ -29,10 +31,6 @@ module Make (S : Abstract.Storage.STORAGE) = struct and Body : Concepts.Encoding.Record.BODY = struct type nonrec t = t - let load tx addr = - SI.get_req tx addr - |> Utilities.Result.fmap Representation.of_blob - let tag = 'Y' let malformed () = Concepts.Condition. @@ -56,30 +54,51 @@ module Make (S : Abstract.Storage.STORAGE) = struct |> fmap (Value.option_of_bencode (fun v -> Value.hash_of_bencode v |> Result.map (fun hash -> S.Hash hash) - |> Result.map (Fun.flip (SI.Pointer.make) load))) in + |> Result.map (SI.Pointer.make Loader.load))) in Ok { multigroups; previous } end + and Loader : sig val load : (S.transaction -> S.address -> (t, Concepts.Condition.condition) result) end = struct + let load tx addr = + SI.get_req tx addr + |> Utilities.Result.fmap Representation.of_blob + end + + let pointer_of hash = SI.Pointer.make Loader.load (S.Hash hash) class branch storage value node = object (self) inherit Lifecycle.null + method to_string = "branch" + val storage : S.connection = storage val branch : t = value val node = node (* FIXME: can we not place this inside `t`? *) + method deriving branch' = + let open Utilities.Result in + let branch'' = { branch' with previous = self#address + |> pointer_of + |> Option.some } in + let* node' = SI.with_transaction storage (fun tx -> + let* _ = SI.store_blob tx (Representation.to_blob branch'') in + MultigroupM.find tx branch'.multigroups + |> fmap (Option.to_result ~none:(Error.incomplete_branch branch'.multigroups))) in + new branch storage branch'' node' |> Protocols.Handle.make |> Result.ok + method protocols : Protocols.Handle.protocol list = + let open Utilities.Result in Protocols.[ Addressable.make self; Prototype.Associative.(of_properties [ "multigroup", update_only (fun node' -> - let open Utilities.Result in - let* addressable = Handle.require Addressable.from node' in - let addr = Addressable.address addressable in - ignore addr; - failwith "TODO") ]); + Handle.require Addressable.from node' + |> Result.map Addressable.address + |> fmap (fun addr -> self#deriving { branch with multigroups = addr })) ]); Prototype.Directory.of_properties [ "multigroup", Prototype.mixture_of node (fun make node -> - [ MMDirectory.make + [ MMAddressable.make + ~node:(MultigroupM.into node); + MMDirectory.make ~storage ~node ~constructor:(M.wrap storage); MMAssociative.make |
