diff --git a/src/lib_client_commands/client_keys_commands.ml b/src/lib_client_commands/client_keys_commands.ml index 5110f0dbb..f936ec038 100644 --- a/src/lib_client_commands/client_keys_commands.ml +++ b/src/lib_client_commands/client_keys_commands.ml @@ -265,7 +265,7 @@ let commands () : Client_context.io_wallet Clic.command list = fail_unless (pk_uri = pk_uri_found || force) (failure "public and secret keys '%s' don't correspond, \ - please don't use -force" name) + please don't use --force" name) end >>=? fun () -> Client_keys.public_key_hash pk_uri >>=? fun (pkh, _public_key) -> register_key cctxt ~force (pkh, pk_uri, sk_uri) name) ; diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index 219e418e6..2cd0e2008 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -67,7 +67,6 @@ let reveal cctxt | Apply_operation_result.Single_and_result (Manager_operation _ as op, result) -> return (oph, op, result) - | _ -> . end let originate @@ -275,6 +274,33 @@ let read_key key = let pkh = Signature.Public_key.hash pk in return (pkh, pk, sk) +let inject_activate_operation + cctxt ~chain ~block ?confirmations alias pkh activation_code = + let contents = + Single ( Activate_account { id = pkh ; activation_code } ) in + Injection.inject_operation + cctxt ?confirmations ~chain ~block + contents >>=? fun (oph, op, result) -> + begin + match confirmations with + | None -> + return () + | Some _confirmations -> + Alpha_services.Contract.balance + cctxt (`Main, `Head 0) + (Contract.implicit_contract (Ed25519 pkh)) >>=? fun balance -> + cctxt#message "Account %s (%a) activated with %s%a." + alias + Ed25519.Public_key_hash.pp pkh + Client_proto_args.tez_sym + Tez.pp balance >>= fun () -> + return () + end >>=? fun () -> + match Apply_operation_result.pack_contents_list op result with + | Apply_operation_result.Single_and_result + (Activate_account _ as op, result) -> + return (oph, op, result) + let activate_account (cctxt : #Proto_alpha.full) ~chain ~block ?confirmations @@ -286,11 +312,6 @@ let activate_account Embedded pkh: %a @]" Signature.Public_key_hash.pp pkh Ed25519.Public_key_hash.pp key.pkh) >>=? fun () -> - let contents = - Single ( Activate_account { id = key.pkh ; activation_code = key.activation_code } ) in - Injection.inject_operation - cctxt ?confirmations ~chain ~block - contents >>=? fun (oph, op, result) -> let pk_uri = Tezos_signer_backends.Unencrypted.make_pk pk in begin if encrypted then @@ -299,23 +320,16 @@ let activate_account return (Tezos_signer_backends.Unencrypted.make_sk sk) end >>=? fun sk_uri -> Client_keys.register_key cctxt ?force (pkh, pk_uri, sk_uri) name >>=? fun () -> - begin - match confirmations with - | None -> - return () - | Some _confirmations -> - Alpha_services.Contract.balance - cctxt (`Main, `Head 0) - (Contract.implicit_contract pkh) >>=? fun balance -> - cctxt#message "Account %s (%a) created with %s%a." - name - Signature.Public_key_hash.pp pkh - Client_proto_args.tez_sym - Tez.pp balance >>= fun () -> - return () - end >>=? fun () -> - match Apply_operation_result.pack_contents_list op result with - | Apply_operation_result.Single_and_result - (Activate_account _ as op, result) -> - return (oph, op, result) - | _ -> . + inject_activate_operation cctxt + ~chain ~block ?confirmations name key.pkh key.activation_code + +let activate_existing_account + (cctxt : #Proto_alpha.full) + ~chain ~block ?confirmations + alias activation_code = + Client_keys.alias_keys cctxt alias >>=? function + | Some (Ed25519 pkh, _, _) -> + inject_activate_operation + cctxt ~chain ~block ?confirmations alias pkh activation_code + | Some _ -> failwith "Only Ed25519 accounts can be activated" + | None -> failwith "Unknown account" diff --git a/src/proto_alpha/lib_client/client_proto_context.mli b/src/proto_alpha/lib_client/client_proto_context.mli index 739143a43..a7f17da19 100644 --- a/src/proto_alpha/lib_client/client_proto_context.mli +++ b/src/proto_alpha/lib_client/client_proto_context.mli @@ -162,3 +162,12 @@ val activate_account: activation_key -> string -> Kind.activate_account Injection.result tzresult Lwt.t + +val activate_existing_account: + #Proto_alpha.full -> + chain:Shell_services.chain -> + block:Shell_services.block -> + ?confirmations:int -> + string -> + Blinded_public_key_hash.activation_code -> + Kind.activate_account Injection.result tzresult Lwt.t diff --git a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml index a3d70f957..5e26e8226 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml @@ -304,7 +304,7 @@ let commands () = return () end; - command ~group ~desc:"Register and activate a predefined account using the provided activation key." + command ~group ~desc:"Register and activate an Alphanet/Zeronet faucet account." (args2 (Secret_key.force_switch ()) encrypted_switch) @@ -312,7 +312,7 @@ let commands () = @@ Secret_key.fresh_alias_param @@ prefixes [ "with" ] @@ param ~name:"activation_key" - ~desc:"Activation key (as JSON file) obtained from the Tezos foundation (or the Alphanet faucet)." + ~desc:"Activate an Alphanet/Zeronet faucet account from the doanloaded JSON file." file_parameter @@ stop) (fun (force, encrypted) name activation_key_file cctxt -> @@ -333,6 +333,24 @@ let commands () = return () ); + command ~group ~desc:"Activate a fundraiser account." + no_options + (prefixes [ "activate" ; "fundraiser" ; "account" ] + @@ Public_key_hash.alias_param + @@ prefixes [ "with" ] + @@ param ~name:"code" + (Clic.parameter (fun _ctx code -> + protect (fun () -> + return (Blinded_public_key_hash.activation_code_of_hex code)))) + ~desc:"Activation code obtained from the Tezos foundation." + @@ stop) + (fun () (name, _pkh) code cctxt -> + activate_existing_account cctxt ~chain:`Main + ~block:cctxt#block ?confirmations:cctxt#confirmations + name code >>=? fun _res -> + return () + ); + command ~desc:"Wait until an operation is included in a block" (let int_param = parameter