Client: select commands depending on the network

This commit is contained in:
Benjamin Canou 2018-06-30 14:52:20 +02:00
parent 99e5cd3186
commit 6cf03d0f6b
11 changed files with 102 additions and 94 deletions

View File

@ -75,7 +75,7 @@ let sandbox () =
\ Do @{<warning>NOT@} use your fundraiser keys on this network.@,\ \ Do @{<warning>NOT@} use your fundraiser keys on this network.@,\
You should not see this message if you are not a developer.@]@\n@." You should not see this message if you are not a developer.@]@\n@."
let check_version ctxt = let check_network ctxt =
Shell_services.P2p.versions ctxt >>= function Shell_services.P2p.versions ctxt >>= function
| Error _ -> | Error _ ->
default () ; default () ;
@ -98,12 +98,12 @@ let check_version ctxt =
default () ; default () ;
Lwt.return_none Lwt.return_none
let get_commands_for_version ctxt block protocol = let get_commands_for_version ctxt network block protocol =
Shell_services.Blocks.protocols ctxt ~block () >>= function Shell_services.Blocks.protocols ctxt ~block () >>= function
| Ok { next_protocol = version } -> begin | Ok { next_protocol = version } -> begin
match protocol with match protocol with
| None -> | None ->
return (Some version, Client_commands.commands_for_version version) return (Some version, Client_commands.commands_for_version version network)
| Some given_version -> begin | Some given_version -> begin
if not (Protocol_hash.equal version given_version) then if not (Protocol_hash.equal version given_version) then
Format.eprintf Format.eprintf
@ -112,7 +112,7 @@ let get_commands_for_version ctxt block protocol =
is not the one retrieved from the node (%a).@]@\n@." is not the one retrieved from the node (%a).@]@\n@."
Protocol_hash.pp_short given_version Protocol_hash.pp_short given_version
Protocol_hash.pp_short version ; Protocol_hash.pp_short version ;
return (Some version, Client_commands.commands_for_version given_version) return (Some version, Client_commands.commands_for_version given_version network)
end end
end end
| Error errs -> begin | Error errs -> begin
@ -125,18 +125,18 @@ let get_commands_for_version ctxt block protocol =
return (None, []) return (None, [])
end end
| Some version -> | Some version ->
return (Some version, Client_commands.commands_for_version version) return (Some version, Client_commands.commands_for_version version network)
end end
let select_commands ctxt { block ; protocol } = let select_commands ctxt { block ; protocol } =
check_version ctxt >>= fun version -> check_network ctxt >>= fun network ->
get_commands_for_version ctxt block protocol >>|? fun (_, commands_for_version) -> get_commands_for_version ctxt network block protocol >>|? fun (_, commands_for_version) ->
Client_rpc_commands.commands @ Client_rpc_commands.commands @
List.map List.map
(Clic.map_command (Clic.map_command
(fun (o : Client_context.full) -> (o :> Client_context.io_wallet))) (fun (o : Client_context.full) -> (o :> Client_context.io_wallet)))
(Tezos_signer_backends.Ledger.commands () @ (Tezos_signer_backends.Ledger.commands () @
Client_keys_commands.commands version) @ Client_keys_commands.commands network) @
Client_helpers_commands.commands () @ Client_helpers_commands.commands () @
commands_for_version commands_for_version

View File

@ -10,6 +10,7 @@
open Client_context open Client_context
type command = full Clic.command type command = full Clic.command
type network = [ `Betanet | `Alphanet | `Zeronet | `Sandbox ]
exception Version_not_found exception Version_not_found
@ -24,8 +25,9 @@ let get_versions () =
let register name commands = let register name commands =
let previous = let previous =
try Protocol_hash.Table.find versions name try Protocol_hash.Table.find versions name
with Not_found -> [] in with Not_found -> (fun (_network : network option) -> ([] : command list)) in
Protocol_hash.Table.replace versions name (commands @ previous) Protocol_hash.Table.replace versions name
(fun (network : network option) -> (commands network @ previous network))
let commands_for_version version = let commands_for_version version =
try Protocol_hash.Table.find versions version try Protocol_hash.Table.find versions version

View File

@ -10,9 +10,10 @@
open Client_context open Client_context
type command = full Clic.command type command = full Clic.command
type network = [ `Betanet | `Alphanet | `Zeronet | `Sandbox ]
exception Version_not_found exception Version_not_found
val register: Protocol_hash.t -> command list -> unit val register: Protocol_hash.t -> (network option -> command list) -> unit
val commands_for_version: Protocol_hash.t -> command list val commands_for_version: Protocol_hash.t -> network option -> command list
val get_versions: unit -> (Protocol_hash.t * (command list)) list val get_versions: unit -> (Protocol_hash.t * (network option -> command list)) list

View File

@ -279,7 +279,8 @@ let commands version : Client_context.io_wallet Clic.command list =
"Tezos address added: %a" "Tezos address added: %a"
Signature.Public_key_hash.pp pkh >>= fun () -> Signature.Public_key_hash.pp pkh >>= fun () ->
register_key cctxt ~force (pkh, pk_uri, sk_uri) ?public_key name) ; register_key cctxt ~force (pkh, pk_uri, sk_uri) ?public_key name) ;
] @
(if version <> (Some `Betanet) then [] else [
command ~group ~desc: "Add a fundraiser secret key to the wallet." command ~group ~desc: "Add a fundraiser secret key to the wallet."
(args1 (Secret_key.force_switch ())) (args1 (Secret_key.force_switch ()))
(prefix "import" (prefix "import"
@ -302,7 +303,8 @@ let commands version : Client_context.io_wallet Clic.command list =
end >>=? fun () -> end >>=? fun () ->
Client_keys.public_key_hash pk_uri >>=? fun (pkh, _public_key) -> Client_keys.public_key_hash pk_uri >>=? fun (pkh, _public_key) ->
register_key cctxt ~force (pkh, pk_uri, sk_uri) name) ; register_key cctxt ~force (pkh, pk_uri, sk_uri) name) ;
]) @
[
command ~group ~desc: "Add a public key to the wallet." command ~group ~desc: "Add a public key to the wallet."
(args1 (Public_key.force_switch ())) (args1 (Public_key.force_switch ()))
(prefix "import" (prefix "import"

View File

@ -8,7 +8,7 @@
(**************************************************************************) (**************************************************************************)
let () = let () =
Client_commands.register Proto_alpha.hash @@ Client_commands.register Proto_alpha.hash @@ fun _network ->
List.map (Clic.map_command (new Proto_alpha.wrap_full)) @@ List.map (Clic.map_command (new Proto_alpha.wrap_full)) @@
Delegate_commands.accuser_commands () Delegate_commands.accuser_commands ()

View File

@ -8,7 +8,7 @@
(**************************************************************************) (**************************************************************************)
let () = let () =
Client_commands.register Proto_alpha.hash @@ Client_commands.register Proto_alpha.hash @@ fun _network ->
List.map (Clic.map_command (new Proto_alpha.wrap_full)) @@ List.map (Clic.map_command (new Proto_alpha.wrap_full)) @@
Delegate_commands.delegate_commands () Delegate_commands.delegate_commands ()

View File

@ -8,7 +8,7 @@
(**************************************************************************) (**************************************************************************)
let () = let () =
Client_commands.register Proto_alpha.hash @@ Client_commands.register Proto_alpha.hash @@ fun _network ->
List.map (Clic.map_command (new Proto_alpha.wrap_full)) @@ List.map (Clic.map_command (new Proto_alpha.wrap_full)) @@
Delegate_commands.delegate_commands () Delegate_commands.delegate_commands ()

View File

@ -8,8 +8,8 @@
(**************************************************************************) (**************************************************************************)
let () = let () =
Client_commands.register Proto_alpha.hash @@ Client_commands.register Proto_alpha.hash @@ fun network ->
List.map (Clic.map_command (new Proto_alpha.wrap_full)) @@ List.map (Clic.map_command (new Proto_alpha.wrap_full)) @@
Client_proto_programs_commands.commands () @ Client_proto_programs_commands.commands () @
Client_proto_contracts_commands.commands () @ Client_proto_contracts_commands.commands () @
Client_proto_context_commands.commands () Client_proto_context_commands.commands network ()

View File

@ -58,7 +58,7 @@ let binary_description =
{ Clic.name = "description" ; { Clic.name = "description" ;
title = "Binary Description" } title = "Binary Description" }
let commands () = let commands version () =
let open Clic in let open Clic in
[ [
command ~group ~desc: "Access the timestamp of the block." command ~group ~desc: "Access the timestamp of the block."
@ -342,7 +342,8 @@ let commands () =
~fee ~manager_sk:src_sk src_pk >>=? fun _res -> ~fee ~manager_sk:src_sk src_pk >>=? fun _res ->
return_unit return_unit
end; end;
] @
(if version = (Some `Betanet) then [] else [
command ~group ~desc:"Register and activate an Alphanet/Zeronet faucet account." command ~group ~desc:"Register and activate an Alphanet/Zeronet faucet account."
(args2 (args2
(Secret_key.force_switch ()) (Secret_key.force_switch ())
@ -351,7 +352,7 @@ let commands () =
@@ Secret_key.fresh_alias_param @@ Secret_key.fresh_alias_param
@@ prefixes [ "with" ] @@ prefixes [ "with" ]
@@ param ~name:"activation_key" @@ param ~name:"activation_key"
~desc:"Activate an Alphanet/Zeronet faucet account from the doanloaded JSON file." ~desc:"Activate an Alphanet/Zeronet faucet account from the downloaded JSON file."
file_parameter file_parameter
@@ stop) @@ stop)
(fun (force, encrypted) name activation_key_file cctxt -> (fun (force, encrypted) name activation_key_file cctxt ->
@ -371,7 +372,8 @@ let commands () =
~encrypted ~force key name >>=? fun _res -> ~encrypted ~force key name >>=? fun _res ->
return_unit return_unit
); );
]) @
(if version <> Some `Betanet then [] else [
command ~group ~desc:"Activate a fundraiser account." command ~group ~desc:"Activate a fundraiser account."
(args1 dry_run_switch) (args1 dry_run_switch)
(prefixes [ "activate" ; "fundraiser" ; "account" ] (prefixes [ "activate" ; "fundraiser" ; "account" ]
@ -390,7 +392,8 @@ let commands () =
name code >>=? fun _res -> name code >>=? fun _res ->
return_unit return_unit
); );
]) @
[
command ~desc:"Wait until an operation is included in a block" command ~desc:"Wait until an operation is included in a block"
(let int_param = (let int_param =
parameter parameter

View File

@ -8,6 +8,6 @@
(**************************************************************************) (**************************************************************************)
let () = let () =
Client_commands.register Proto_alpha.hash @@ Client_commands.register Proto_alpha.hash @@ fun _network ->
List.map (Clic.map_command (new Proto_alpha.wrap_full)) @@ List.map (Clic.map_command (new Proto_alpha.wrap_full)) @@
Delegate_commands.delegate_commands () Delegate_commands.delegate_commands ()

View File

@ -101,5 +101,5 @@ let commands () =
] ]
let () = let () =
Client_commands.register protocol @@ Client_commands.register protocol @@ fun _network ->
commands () commands ()