.
This commit is contained in:
parent
2dda037001
commit
76e020e131
3 changed files with 13 additions and 13 deletions
|
|
@ -34,7 +34,6 @@
|
|||
fmt
|
||||
bin
|
||||
angstrom
|
||||
zarith
|
||||
mirage-crypto
|
||||
digestif
|
||||
duration
|
||||
|
|
|
|||
1
mte.opam
1
mte.opam
|
|
@ -21,7 +21,6 @@ depends: [
|
|||
"fmt"
|
||||
"bin"
|
||||
"angstrom"
|
||||
"zarith"
|
||||
"mirage-crypto"
|
||||
"digestif"
|
||||
"duration"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue