From 2f14e2aa2c61975cb4a8da2139eba436cfd63afb Mon Sep 17 00:00:00 2001 From: swrup Date: Sat, 18 Oct 2025 20:28:38 +0200 Subject: [PATCH] --- src/amount.ml | 6 ++++-- src/binary_formats.ml | 8 +++++--- src/config.ml | 2 +- src/types.ml | 15 ++++++++++----- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/amount.ml b/src/amount.ml index 5401b27e..8692e015 100644 --- a/src/amount.ml +++ b/src/amount.ml @@ -46,8 +46,10 @@ let to_string = in let pp_currency ppf = function `Eur -> string ppf "EUR" in fun ppf { sign; currency; value; fraction } -> - pf ppf "%a%a:%Ld.%Ld" (Fmt.option pp_sign) sign pp_currency currency value - fraction + (* TODO amount + use config *) + pf ppf "%a%a:%Ld.%02Ld" (Fmt.option pp_sign) sign pp_currency currency + value fraction in Fmt.str "%a" pp diff --git a/src/binary_formats.ml b/src/binary_formats.ml index ad3f594e..4ddcc135 100644 --- a/src/binary_formats.ml +++ b/src/binary_formats.ml @@ -188,7 +188,9 @@ module UTIL = struct let hash s = match String.length s = 32 with - | false -> Fmt.failwith "SHA256 failure: data is not 32 bytes" + | false -> + Fmt.failwith "SHA256 failure: data is not 32 bytes, instead is %d" + (String.length s) | true -> hash s end @@ -218,7 +220,7 @@ module UTIL = struct val bin : t Bin.t val hash : M.src -> t end = struct - include Hash_64 + include HHH_64 let hash src = hash (M.to_octets src) end @@ -233,7 +235,7 @@ module UTIL = struct val bin : t Bin.t val hash : M.src -> t end = struct - include Hash_32 + include HHH_32 let hash src = hash (M.to_octets src) end diff --git a/src/config.ml b/src/config.ml index 5e6a6cc0..0ebe218b 100644 --- a/src/config.ml +++ b/src/config.ml @@ -1,7 +1,7 @@ (* hardcoded config for now *) let amount s = Amount.of_string s |> Result.get_ok -let zero_eur = amount "EUR:0.01" +let zero_eur = amount "EUR:0.00" let dummy_duration = Ptime.Span.of_int_s 99999999 module Exchange = struct diff --git a/src/types.ml b/src/types.ml index 7cf6b6ff..a376a10c 100644 --- a/src/types.ml +++ b/src/types.ml @@ -84,13 +84,18 @@ end = struct (* mirage_crypto: "The result is the concatenation of r and s, as specified in RFC 8032." *) Mirage_crypto_ec.Ed25519.sign ~key s - let of_b32 s = B32.decode s + let check_size t = + match String.length t = 64 with + | false -> Error "EddsaSignature: invalid string length" + | true -> Ok () - let to_b32 t = - let s = B32.encode t in - assert (String.length s = 64); - s + let of_b32 s = + let open Syntax in + let* t = B32.decode s in + let+ () = check_size t in + t + let to_b32 = B32.encode let jsont = Jsont.of_of_string ~kind:"EddsaSignature" of_b32 ~enc:to_b32 end