Skip to content

Commit

Permalink
Rename variable in merkle_path_dependencies_exn
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeee committed Nov 28, 2023
1 parent d10bf7e commit f8c7017
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/lib/merkle_ledger/location.ml
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,23 @@ module T = struct
| Right ->
(sibling, base)

(* Returns a reverse of traversal path from top of the tree to the location
(direction to take and sibling's hash).contents
By reverse it means that head of returned list contains direction from
location's parent to the location along with the location's sibling.
*)
let merkle_path_dependencies_exn (location : t) : (t * Direction.t) list =
let rec loop k acc =
if Addr.depth k = 0 then acc
let rec loop k =
if Addr.depth k = 0 then []
else
let sibling = Hash (Addr.sibling k) in
let sibling_dir = last_direction k in
loop (Addr.parent_exn k) ((sibling, sibling_dir) :: acc)
let dir = last_direction k in
(sibling, dir) :: loop (Addr.parent_exn k)
in
match location with
| Hash addr ->
List.rev (loop addr [])
loop addr
| _ ->
failwith "can only get merkle path dependencies of a hash location"

Expand Down

0 comments on commit f8c7017

Please sign in to comment.