add result.ml; polymorphic variant errors + refacto

This commit is contained in:
swrup 2026-03-26 06:23:42 +01:00 committed by Swrup
parent 9fd3b5a3cc
commit 42b0ec1445
36 changed files with 949 additions and 954 deletions

View file

@ -1,7 +1,6 @@
open Syntax
open Hash
let keys content =
let open Syntax in
let open Hash in
let open Api in
let open ExchangeKeysResponse in
let* v = Api.decode jsont content in
@ -10,7 +9,7 @@ let keys content =
Libtool_version.is_compatible
~implementation:Libtool_version.mte_protocol_version v.version
then Ok ()
else Fmt.error "version incompatible"
else Fmt.error_msg "incompatible version"
in
(* TODO json hash
@ -51,7 +50,7 @@ let keys content =
let* () =
let opt = List.find_opt (fun sk -> sk.Signkey.pub = v.exchange_pub) sk_l in
match opt with
| None -> Fmt.error "exchange_pub is not in signkeys list"
| None -> Fmt.error_msg "exchange_pub is not in signkeys list"
| Some _sk ->
(* todo add a --now option if we want to validate timestamps
let now = Timestamp.of_ptime (Ptime_clock.now ()) in
@ -95,7 +94,7 @@ let keys content =
let open Denomination in
denom_l |> List.find_opt (fun dn -> dn.h_pub = denom_pub_h)
|> function
| None -> Fmt.error "auditor denomination key not found"
| None -> Fmt.error_msg "auditor denomination key not found"
| Some dn ->
let open Signatures.ExchangeKeyValidity in
verify auditor_pub auditor_sig
@ -129,9 +128,10 @@ let keys_cmd =
Cmd.make (Cmd.info "keys" ~doc)
@@
let+ file = file in
let* content =
Result.bind (Fpath.of_string file) Bos.OS.File.read |> unwrap_msg
in
let open Syntax in
Result.unwrap_err
@@
let* content = Bos.OS.File.read (Fpath.v file) in
keys content
let cli =