Client: select commands depending on the network
This commit is contained in:
parent
99e5cd3186
commit
6cf03d0f6b
@ -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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -279,30 +279,32 @@ 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) ;
|
||||||
|
] @
|
||||||
command ~group ~desc: "Add a fundraiser secret key to the wallet."
|
(if version <> (Some `Betanet) then [] else [
|
||||||
(args1 (Secret_key.force_switch ()))
|
command ~group ~desc: "Add a fundraiser secret key to the wallet."
|
||||||
(prefix "import"
|
(args1 (Secret_key.force_switch ()))
|
||||||
@@ prefixes [ "fundraiser" ; "secret" ; "key" ]
|
(prefix "import"
|
||||||
@@ Secret_key.fresh_alias_param
|
@@ prefixes [ "fundraiser" ; "secret" ; "key" ]
|
||||||
@@ stop)
|
@@ Secret_key.fresh_alias_param
|
||||||
(fun force name (cctxt : Client_context.io_wallet) ->
|
@@ stop)
|
||||||
Secret_key.of_fresh cctxt force name >>=? fun name ->
|
(fun force name (cctxt : Client_context.io_wallet) ->
|
||||||
input_fundraiser_params cctxt >>=? fun sk ->
|
Secret_key.of_fresh cctxt force name >>=? fun name ->
|
||||||
Tezos_signer_backends.Encrypted.encrypt cctxt sk >>=? fun sk_uri ->
|
input_fundraiser_params cctxt >>=? fun sk ->
|
||||||
Client_keys.neuterize sk_uri >>=? fun pk_uri ->
|
Tezos_signer_backends.Encrypted.encrypt cctxt sk >>=? fun sk_uri ->
|
||||||
begin
|
Client_keys.neuterize sk_uri >>=? fun pk_uri ->
|
||||||
Public_key.find_opt cctxt name >>=? function
|
begin
|
||||||
| None -> return_unit
|
Public_key.find_opt cctxt name >>=? function
|
||||||
| Some (pk_uri_found, _) ->
|
| None -> return_unit
|
||||||
fail_unless (pk_uri = pk_uri_found || force)
|
| Some (pk_uri_found, _) ->
|
||||||
(failure
|
fail_unless (pk_uri = pk_uri_found || force)
|
||||||
"public and secret keys '%s' don't correspond, \
|
(failure
|
||||||
please don't use --force" name)
|
"public and secret keys '%s' don't correspond, \
|
||||||
end >>=? fun () ->
|
please don't use --force" name)
|
||||||
Client_keys.public_key_hash pk_uri >>=? fun (pkh, _public_key) ->
|
end >>=? fun () ->
|
||||||
register_key cctxt ~force (pkh, pk_uri, sk_uri) name) ;
|
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."
|
command ~group ~desc: "Add a public key to the wallet."
|
||||||
(args1 (Public_key.force_switch ()))
|
(args1 (Public_key.force_switch ()))
|
||||||
(prefix "import"
|
(prefix "import"
|
||||||
|
@ -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 ()
|
||||||
|
|
||||||
|
@ -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 ()
|
||||||
|
|
||||||
|
@ -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 ()
|
||||||
|
|
||||||
|
@ -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 ()
|
||||||
|
@ -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,55 +342,58 @@ 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;
|
||||||
|
] @
|
||||||
command ~group ~desc:"Register and activate an Alphanet/Zeronet faucet account."
|
(if version = (Some `Betanet) then [] else [
|
||||||
(args2
|
command ~group ~desc:"Register and activate an Alphanet/Zeronet faucet account."
|
||||||
(Secret_key.force_switch ())
|
(args2
|
||||||
encrypted_switch)
|
(Secret_key.force_switch ())
|
||||||
(prefixes [ "activate" ; "account" ]
|
encrypted_switch)
|
||||||
@@ Secret_key.fresh_alias_param
|
(prefixes [ "activate" ; "account" ]
|
||||||
@@ prefixes [ "with" ]
|
@@ Secret_key.fresh_alias_param
|
||||||
@@ param ~name:"activation_key"
|
@@ prefixes [ "with" ]
|
||||||
~desc:"Activate an Alphanet/Zeronet faucet account from the doanloaded JSON file."
|
@@ param ~name:"activation_key"
|
||||||
file_parameter
|
~desc:"Activate an Alphanet/Zeronet faucet account from the downloaded JSON file."
|
||||||
@@ stop)
|
file_parameter
|
||||||
(fun (force, encrypted) name activation_key_file cctxt ->
|
@@ stop)
|
||||||
Secret_key.of_fresh cctxt force name >>=? fun name ->
|
(fun (force, encrypted) name activation_key_file cctxt ->
|
||||||
Lwt_utils_unix.Json.read_file activation_key_file >>=? fun json ->
|
Secret_key.of_fresh cctxt force name >>=? fun name ->
|
||||||
match Data_encoding.Json.destruct
|
Lwt_utils_unix.Json.read_file activation_key_file >>=? fun json ->
|
||||||
Client_proto_context.activation_key_encoding
|
match Data_encoding.Json.destruct
|
||||||
json with
|
Client_proto_context.activation_key_encoding
|
||||||
| exception (Data_encoding.Json.Cannot_destruct _ as exn) ->
|
json with
|
||||||
Format.kasprintf (fun s -> failwith "%s" s)
|
| exception (Data_encoding.Json.Cannot_destruct _ as exn) ->
|
||||||
"Invalid activation file: %a %a"
|
Format.kasprintf (fun s -> failwith "%s" s)
|
||||||
(fun ppf -> Data_encoding.Json.print_error ppf) exn
|
"Invalid activation file: %a %a"
|
||||||
Data_encoding.Json.pp json
|
(fun ppf -> Data_encoding.Json.print_error ppf) exn
|
||||||
| key ->
|
Data_encoding.Json.pp json
|
||||||
activate_account cctxt
|
| key ->
|
||||||
~chain:`Main ~block:cctxt#block ?confirmations:cctxt#confirmations
|
activate_account cctxt
|
||||||
~encrypted ~force key name >>=? fun _res ->
|
~chain:`Main ~block:cctxt#block ?confirmations:cctxt#confirmations
|
||||||
return_unit
|
~encrypted ~force key name >>=? fun _res ->
|
||||||
);
|
return_unit
|
||||||
|
);
|
||||||
command ~group ~desc:"Activate a fundraiser account."
|
]) @
|
||||||
(args1 dry_run_switch)
|
(if version <> Some `Betanet then [] else [
|
||||||
(prefixes [ "activate" ; "fundraiser" ; "account" ]
|
command ~group ~desc:"Activate a fundraiser account."
|
||||||
@@ Public_key_hash.alias_param
|
(args1 dry_run_switch)
|
||||||
@@ prefixes [ "with" ]
|
(prefixes [ "activate" ; "fundraiser" ; "account" ]
|
||||||
@@ param ~name:"code"
|
@@ Public_key_hash.alias_param
|
||||||
(Clic.parameter (fun _ctx code ->
|
@@ prefixes [ "with" ]
|
||||||
protect (fun () ->
|
@@ param ~name:"code"
|
||||||
return (Blinded_public_key_hash.activation_code_of_hex code))))
|
(Clic.parameter (fun _ctx code ->
|
||||||
~desc:"Activation code obtained from the Tezos foundation."
|
protect (fun () ->
|
||||||
@@ stop)
|
return (Blinded_public_key_hash.activation_code_of_hex code))))
|
||||||
(fun dry_run (name, _pkh) code cctxt ->
|
~desc:"Activation code obtained from the Tezos foundation."
|
||||||
activate_existing_account cctxt ~chain:`Main
|
@@ stop)
|
||||||
~block:cctxt#block ?confirmations:cctxt#confirmations
|
(fun dry_run (name, _pkh) code cctxt ->
|
||||||
~dry_run
|
activate_existing_account cctxt ~chain:`Main
|
||||||
name code >>=? fun _res ->
|
~block:cctxt#block ?confirmations:cctxt#confirmations
|
||||||
return_unit
|
~dry_run
|
||||||
);
|
name code >>=? fun _res ->
|
||||||
|
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
|
||||||
|
@ -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 ()
|
||||||
|
@ -101,5 +101,5 @@ let commands () =
|
|||||||
]
|
]
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
Client_commands.register protocol @@
|
Client_commands.register protocol @@ fun _network ->
|
||||||
commands ()
|
commands ()
|
||||||
|
Loading…
Reference in New Issue
Block a user