176 lines
4.7 KiB
OCaml
176 lines
4.7 KiB
OCaml
open Cmdliner
|
|
open Cmdliner.Term.Syntax
|
|
open Offline_impl
|
|
|
|
module Arg = struct
|
|
include Arg
|
|
|
|
let timestamp =
|
|
Arg.Conv.make ~docv:"timestamp argument" ~parser:Timestamp.of_string
|
|
~pp:Timestamp.pp ()
|
|
|
|
let relative_time =
|
|
Arg.Conv.make ~docv:"relative time argument"
|
|
~parser:Timestamp.Span.of_string ~pp:Timestamp.Span.pp ()
|
|
|
|
let amount =
|
|
Arg.Conv.make ~docv:"amount argument" ~parser:Amount.of_string ~pp:Amount.pp
|
|
()
|
|
end
|
|
|
|
let default_master_offline_key_file = "data/master_offline_private_key"
|
|
(*
|
|
let default_response_file = "response.json"
|
|
let default_request_file = "request.json"
|
|
*)
|
|
|
|
let master_key =
|
|
let doc = "Master offline Eddsa private key file." in
|
|
Arg.(
|
|
value
|
|
& opt file default_master_offline_key_file
|
|
& info [ "master_key_file" ] ~doc)
|
|
|
|
let input =
|
|
let doc = "input file" in
|
|
Arg.(required & opt (some file) None & info [ "i"; "input" ] ~doc)
|
|
|
|
let output =
|
|
let doc = "output file" in
|
|
Arg.(required & opt (some filepath) None & info [ "o"; "output" ] ~doc)
|
|
|
|
let url =
|
|
let doc = "url" in
|
|
Arg.(required & opt (some string) None & info [ "url" ] ~doc)
|
|
|
|
let setup_cmd =
|
|
let doc = "Generate offline master keys" in
|
|
let output =
|
|
let doc = "output file" in
|
|
Arg.(
|
|
value
|
|
& opt filepath default_master_offline_key_file
|
|
& info [ "o"; "output" ] ~doc)
|
|
in
|
|
Cmd.make (Cmd.info "setup" ~doc)
|
|
@@
|
|
let+ output = output in
|
|
setup ~output
|
|
|
|
let download_cmd =
|
|
let doc = "GET /management/keys/" in
|
|
let man =
|
|
[ `S Manpage.s_description; `P "$(cmd) download /management/keys." ]
|
|
in
|
|
Cmd.make (Cmd.info "download" ~doc ~man)
|
|
@@
|
|
let+ output = output in
|
|
download ~output
|
|
|
|
let upload_cmd =
|
|
let doc = "POST input.json data to url (default /management/keys)" in
|
|
Cmd.make (Cmd.info "upload" ~doc)
|
|
@@
|
|
let+ input = input and+ url = url in
|
|
upload ~input ~url
|
|
|
|
let sign_cmd =
|
|
let doc = "Sign FutureKeysResponse." in
|
|
Cmd.make (Cmd.info "sign" ~doc)
|
|
@@
|
|
let+ input = input and+ output = output and+ master_key = master_key in
|
|
sign ~input ~output ~master_key
|
|
|
|
let revoke_denom_cmd =
|
|
let doc = "Revoke denomination." in
|
|
let h_denom =
|
|
let doc = "hash of denomination public key" in
|
|
Arg.(required & pos 0 (some string) None & info [] ~doc)
|
|
in
|
|
Cmd.make (Cmd.info "revoke-denom" ~doc)
|
|
@@
|
|
let+ output = output and+ master_key = master_key and+ h_denom = h_denom in
|
|
revoke_denom ~output ~master_key ~h_denom
|
|
|
|
let revoke_signkey_cmd =
|
|
let doc = "Revoke signkey." in
|
|
let signkey =
|
|
let doc = "public signing key" in
|
|
Arg.(required & pos 0 (some string) None & info [] ~doc)
|
|
in
|
|
Cmd.make (Cmd.info "revoke-signkey" ~doc)
|
|
@@
|
|
let+ output = output and+ master_key = master_key and+ signkey = signkey in
|
|
revoke_signkey ~output ~master_key ~signkey
|
|
|
|
let global_fees_cmd =
|
|
let doc = "Provides global fee configuration." in
|
|
let start_date =
|
|
Arg.(required & opt (some timestamp) None & info [ "start_date" ])
|
|
in
|
|
let end_date =
|
|
Arg.(required & opt (some timestamp) None & info [ "end_date" ])
|
|
in
|
|
let history_fee =
|
|
Arg.(required & opt (some amount) None & info [ "history_fee" ])
|
|
in
|
|
let account_fee =
|
|
Arg.(required & opt (some amount) None & info [ "account_fee" ])
|
|
in
|
|
let purse_fee =
|
|
Arg.(required & opt (some amount) None & info [ "purse_fee" ])
|
|
in
|
|
let history_expiration =
|
|
Arg.(
|
|
required & opt (some relative_time) None & info [ "history_expiration" ])
|
|
in
|
|
let purse_account_limit =
|
|
Arg.(required & opt (some int) None & info [ "purse_account_limit" ])
|
|
in
|
|
let purse_timeout =
|
|
Arg.(required & opt (some relative_time) None & info [ "purse_timeout" ])
|
|
in
|
|
Cmd.make (Cmd.info "global-fees" ~doc)
|
|
@@
|
|
let+ output = output
|
|
and+ master_key = master_key
|
|
and+ start_date = start_date
|
|
and+ end_date = end_date
|
|
and+ history_fee = history_fee
|
|
and+ account_fee = account_fee
|
|
and+ purse_fee = purse_fee
|
|
and+ history_expiration = history_expiration
|
|
and+ purse_account_limit = purse_account_limit
|
|
and+ purse_timeout = purse_timeout in
|
|
global_fees ~output ~master_key ~start_date ~end_date ~history_fee
|
|
~account_fee ~purse_fee ~history_expiration ~purse_account_limit
|
|
~purse_timeout
|
|
|
|
let cli =
|
|
let info =
|
|
let doc = "MTE Offline CLI tool" in
|
|
Cmd.info "mte-offline" ~doc
|
|
in
|
|
Cmd.group info
|
|
[
|
|
setup_cmd;
|
|
download_cmd;
|
|
sign_cmd;
|
|
upload_cmd;
|
|
revoke_denom_cmd;
|
|
revoke_signkey_cmd;
|
|
global_fees_cmd;
|
|
]
|
|
|
|
let main () = Cmd.eval_result cli
|
|
let () = if !Sys.interactive then () else exit (main ())
|
|
|
|
(* TODO all management operations:
|
|
/management/auditors
|
|
/management/auditors/$AUDITOR_PUB/disable
|
|
/management/wire-fee
|
|
/management/wire
|
|
/management/wire/disable
|
|
/management/drain
|
|
/management/aml-officers
|
|
/management/partners *)
|