diff --git a/dune-project b/dune-project index 5bd4e1f1..1aadd32c 100644 --- a/dune-project +++ b/dune-project @@ -34,7 +34,6 @@ fmt bin angstrom - zarith mirage-crypto digestif duration diff --git a/mte.opam b/mte.opam index 8bdbc121..53820528 100644 --- a/mte.opam +++ b/mte.opam @@ -21,7 +21,6 @@ depends: [ "fmt" "bin" "angstrom" - "zarith" "mirage-crypto" "digestif" "duration" diff --git a/src/amount.ml b/src/amount.ml index f5017805..9c10437c 100644 --- a/src/amount.ml +++ b/src/amount.ml @@ -14,8 +14,7 @@ type t = { fraction: Int32.t; } -(* rm Zarith *) -let value_upper_bound = Z.(pow (of_int 2) 52) |> Z.to_int64 +let value_upper_bound = Int64.of_float @@ Float.pow 2. 52. (* TODO the constraint is on the number of digits, @@ -97,28 +96,31 @@ let jsont = Jsont.of_of_string ~kind:"Amount" of_string ~enc:to_string (* byte length of currency string *) let currency_len = 12 -(* TODO error *) -let pad_currency s = +let pad_currency_string s = let len = String.length s in - assert (len <= 11); + assert (len < currency_len); let b = Bytes.make 12 '\x00' in Bytes.blit_string s 0 b 0 len; Bytes.to_string b +(* binary decoding unused? *) +let make_exn value fraction currency = + match make ~sign:None ~currency ~value ~fraction with + | Error _ -> Fmt.failwith "Amount of binary data failure" + | Ok v -> v + let bin = let open Bin in - record (fun _value _fraction _currency -> - (* no need to decode amount? *) - assert false) + record make_exn |+ field neint64 (fun t -> t.value) |+ field neint32 (fun t -> t.fraction) - |+ field (bytes currency_len) (fun t -> pad_currency t.currency) + |+ field (bytes currency_len) (fun t -> pad_currency_string t.currency) |> sealr let bin_nbo = let open Bin in - record (fun _value _fraction _currency -> assert false) + record make_exn |+ field beint64 (fun t -> t.value) |+ field beint32 (fun t -> t.fraction) - |+ field (bytes currency_len) (fun t -> pad_currency t.currency) + |+ field (bytes currency_len) (fun t -> pad_currency_string t.currency) |> sealr