rm HashCode, use DenominationHash directly

This commit is contained in:
swrup 2025-12-21 22:13:35 +01:00
parent dfb0b476c0
commit 99d2ee6194
6 changed files with 77 additions and 39 deletions

View file

@ -97,17 +97,23 @@ module Hash_32 = struct
| true -> Digestif.SHA256.of_raw_string s
let to_octets = Digestif.SHA256.to_raw_string
let of_b32 s = Result.map of_octets (B32.decode s)
let bin =
let open Bin in
map (bytes 32) of_octets to_octets
(* hashes are not b32 encoded in the database *)
let caqti : t Caqti_type.t =
let open Caqti_type in
custom
~encode:(fun v -> Ok (to_octets v))
~decode:(fun v -> Ok (of_octets v))
octets
let jsont =
let enc v = B32.encode (to_octets v) in
Jsont.of_of_string ~kind:"Hash 32" of_b32 ~enc
end
module Hash_64 = struct
@ -126,16 +132,23 @@ module Hash_64 = struct
| false -> Fmt.failwith "Hash.to_octets failure: data is not 64 bytes"
| true -> s
let of_b32 s = Result.map of_octets (B32.decode s)
let bin =
let open Bin in
map (bytes 64) of_octets to_octets
(* hashes are not b32 encoded in the database *)
let caqti : t Caqti_type.t =
let open Caqti_type in
custom
~encode:(fun v -> Ok (to_octets v))
~decode:(fun v -> Ok (of_octets v))
octets
let jsont =
let enc v = B32.encode (to_octets v) in
Jsont.of_of_string ~kind:"Hash 64" of_b32 ~enc
end
(* Hash over string + '\0' *)
@ -160,9 +173,11 @@ module type Hash_S = sig
val bin : t Bin.t
val caqti : t Caqti_type.t
val jsont : t Jsont.t
val hash : string -> t
val of_octets : string -> t
val to_octets : t -> string
val of_b32 : B32.t -> (t, string) result
end
module FullPaytoHash : Hash_S = Hash_32