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.@,\
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
| Error _ ->
default () ;
@ -98,12 +98,12 @@ let check_version ctxt =
default () ;
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
| Ok { next_protocol = version } -> begin
match protocol with
| None ->
return (Some version, Client_commands.commands_for_version version)
return (Some version, Client_commands.commands_for_version version network)
| Some given_version -> begin
if not (Protocol_hash.equal version given_version) then
Format.eprintf
@ -112,7 +112,7 @@ let get_commands_for_version ctxt block protocol =
is not the one retrieved from the node (%a).@]@\n@."
Protocol_hash.pp_short given_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
| Error errs -> begin
@ -125,18 +125,18 @@ let get_commands_for_version ctxt block protocol =
return (None, [])
end
| Some version ->
return (Some version, Client_commands.commands_for_version version)
return (Some version, Client_commands.commands_for_version version network)
end
let select_commands ctxt { block ; protocol } =
check_version ctxt >>= fun version ->
get_commands_for_version ctxt block protocol >>|? fun (_, commands_for_version) ->
check_network ctxt >>= fun network ->
get_commands_for_version ctxt network block protocol >>|? fun (_, commands_for_version) ->
Client_rpc_commands.commands @
List.map
(Clic.map_command
(fun (o : Client_context.full) -> (o :> Client_context.io_wallet)))
(Tezos_signer_backends.Ledger.commands () @
Client_keys_commands.commands version) @
Client_keys_commands.commands network) @
Client_helpers_commands.commands () @
commands_for_version

View File

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

View File

@ -10,9 +10,10 @@
open Client_context
type command = full Clic.command
type network = [ `Betanet | `Alphanet | `Zeronet | `Sandbox ]
exception Version_not_found
val register: Protocol_hash.t -> command list -> unit
val commands_for_version: Protocol_hash.t -> command list
val get_versions: unit -> (Protocol_hash.t * (command list)) list
val register: Protocol_hash.t -> (network option -> command list) -> unit
val commands_for_version: Protocol_hash.t -> network option -> command 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"
Signature.Public_key_hash.pp pkh >>= fun () ->
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."
(args1 (Secret_key.force_switch ()))
(prefix "import"
@ -302,7 +303,8 @@ let commands version : Client_context.io_wallet Clic.command list =
end >>=? fun () ->
Client_keys.public_key_hash pk_uri >>=? fun (pkh, _public_key) ->
register_key cctxt ~force (pkh, pk_uri, sk_uri) name) ;
]) @
[
command ~group ~desc: "Add a public key to the wallet."
(args1 (Public_key.force_switch ()))
(prefix "import"

View File

@ -8,7 +8,7 @@
(**************************************************************************)
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)) @@
Delegate_commands.accuser_commands ()

View File

@ -8,7 +8,7 @@
(**************************************************************************)
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)) @@
Delegate_commands.delegate_commands ()

View File

@ -8,7 +8,7 @@
(**************************************************************************)
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)) @@
Delegate_commands.delegate_commands ()

View File

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

View File

@ -8,6 +8,6 @@
(**************************************************************************)
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)) @@
Delegate_commands.delegate_commands ()

View File

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