This commit is contained in:
swrup 2026-02-11 00:31:03 +01:00
parent 2dda037001
commit 76e020e131
3 changed files with 13 additions and 13 deletions

View file

@ -34,7 +34,6 @@
fmt fmt
bin bin
angstrom angstrom
zarith
mirage-crypto mirage-crypto
digestif digestif
duration duration

View file

@ -21,7 +21,6 @@ depends: [
"fmt" "fmt"
"bin" "bin"
"angstrom" "angstrom"
"zarith"
"mirage-crypto" "mirage-crypto"
"digestif" "digestif"
"duration" "duration"

View file

@ -14,8 +14,7 @@ type t = {
fraction: Int32.t; fraction: Int32.t;
} }
(* rm Zarith *) let value_upper_bound = Int64.of_float @@ Float.pow 2. 52.
let value_upper_bound = Z.(pow (of_int 2) 52) |> Z.to_int64
(* TODO (* TODO
the constraint is on the number of digits, 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 *) (* byte length of currency string *)
let currency_len = 12 let currency_len = 12
(* TODO error *) let pad_currency_string s =
let pad_currency s =
let len = String.length s in let len = String.length s in
assert (len <= 11); assert (len < currency_len);
let b = Bytes.make 12 '\x00' in let b = Bytes.make 12 '\x00' in
Bytes.blit_string s 0 b 0 len; Bytes.blit_string s 0 b 0 len;
Bytes.to_string b 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 bin =
let open Bin in let open Bin in
record (fun _value _fraction _currency -> record make_exn
(* no need to decode amount? *)
assert false)
|+ field neint64 (fun t -> t.value) |+ field neint64 (fun t -> t.value)
|+ field neint32 (fun t -> t.fraction) |+ 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 |> sealr
let bin_nbo = let bin_nbo =
let open Bin in let open Bin in
record (fun _value _fraction _currency -> assert false) record make_exn
|+ field beint64 (fun t -> t.value) |+ field beint64 (fun t -> t.value)
|+ field beint32 (fun t -> t.fraction) |+ 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 |> sealr