offline tool: add drain cmd

This commit is contained in:
swrup 2026-02-03 22:29:29 +01:00
parent 17be86bfd4
commit cdfae5347f
2 changed files with 66 additions and 2 deletions

View file

@ -13,6 +13,11 @@ module Arg = struct
Arg.Conv.make ~docv:"relative time argument" Arg.Conv.make ~docv:"relative time argument"
~parser:Timestamp.Span.of_string ~pp:Timestamp.Span.pp () ~parser:Timestamp.Span.of_string ~pp:Timestamp.Span.pp ()
let b32 =
let pp fmt v = Fmt.pf fmt "%s" (B32.encode v) in
Arg.Conv.make ~docv:"Crockford's Base32 encoded argument" ~parser:B32.decode
~pp ()
let amount = let amount =
Arg.Conv.make ~docv:"amount argument" ~parser:Amount.of_string ~pp:Amount.pp Arg.Conv.make ~docv:"amount argument" ~parser:Amount.of_string ~pp:Amount.pp
() ()
@ -224,6 +229,32 @@ let global_fees_cmd =
~account_fee ~purse_fee ~history_expiration ~purse_account_limit ~account_fee ~purse_fee ~history_expiration ~purse_account_limit
~purse_timeout ~purse_timeout
let drain_cmd =
let doc =
"Drain profits from the exchange. The actual drain requires running the \
taler-exchange-drain tool."
in
let debit_account_section =
Arg.(required & opt (some string) None & info [ "debit_account_section" ])
in
let credit_payto_uri =
Arg.(required & opt (some string) None & info [ "credit_payto_uri" ])
in
let wtid = Arg.(required & opt (some b32) None & info [ "wtid" ]) in
let date = Arg.(required & opt (some timestamp) None & info [ "date" ]) in
let amount = Arg.(required & opt (some amount) None & info [ "amount" ]) in
Cmd.make (Cmd.info "drain" ~doc)
@@
let+ output = output
and+ master_key = master_key
and+ debit_account_section = debit_account_section
and+ credit_payto_uri = credit_payto_uri
and+ wtid = wtid
and+ date = date
and+ amount = amount in
drain ~output ~master_key ~debit_account_section ~credit_payto_uri ~wtid ~date
~amount
let cli = let cli =
let info = let info =
let doc = "MTE Offline CLI tool" in let doc = "MTE Offline CLI tool" in
@ -241,6 +272,7 @@ let cli =
disable_auditor_cmd; disable_auditor_cmd;
wire_fee_cmd; wire_fee_cmd;
global_fees_cmd; global_fees_cmd;
drain_cmd;
] ]
let main () = Cmd.eval_result cli let main () = Cmd.eval_result cli
@ -253,6 +285,8 @@ let () = if !Sys.interactive then () else exit (main ())
-> how to build WireSetupMessage? -> how to build WireSetupMessage?
we need additional data to craft master_sig we need additional data to craft master_sig
maybe supposed to be found in the full payto-uri? maybe supposed to be found in the full payto-uri?
/management/drain
/management/aml-officers /management/aml-officers
/management/partners *) -> /aml
/management/partners
-> /wads *)

View file

@ -197,3 +197,33 @@ let wire_fee ~output ~master_key ~wire_method ~fee_start ~fee_end ~closing_fee
let* s = Api.encode Api.WireFeeSetupMessage.jsont v in let* s = Api.encode Api.WireFeeSetupMessage.jsont v in
let* () = write_file output s in let* () = write_file output s in
Ok () Ok ()
let drain ~output ~master_key ~debit_account_section ~credit_payto_uri ~wtid
~date ~amount =
let open Crypto in
let* key = read_master_key_file master_key in
let master_sig =
let open Bin_sig.MasterDrainProfit in
sign_f ~f:(EddsaSignature.sign ~key)
{
wtid;
date;
amount;
h_section= Bin_type.Hash_64_cstr.hash debit_account_section;
h_payto= Bin_type.FullPaytoHash.hash credit_payto_uri;
}
in
let v =
Api.DrainProfitsMessage.
{
debit_account_section;
credit_payto_uri;
wtid;
master_sig;
date;
amount;
}
in
let* s = Api.encode Api.DrainProfitsMessage.jsont v in
let* () = write_file output s in
Ok ()