From da921a8f56c29ff3ee76d50dca72a4b3e6883ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Sat, 26 May 2018 13:41:51 +0200 Subject: [PATCH] Client: allow `tz1...` as the source of a transfer This is only useful when a 'remote signer' is available. --- src/lib_client_base/client_keys.ml | 48 ++++++++++++------- .../client_proto_context_commands.ml | 2 +- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/lib_client_base/client_keys.ml b/src/lib_client_base/client_keys.ml index 766d8f701..4d9fe3605 100644 --- a/src/lib_client_base/client_keys.ml +++ b/src/lib_client_base/client_keys.ml @@ -141,23 +141,39 @@ let register_key cctxt ?(force=false) (public_key_hash, pk_uri, sk_uri) name = return () let raw_get_key (cctxt : #Client_context.wallet) pkh = - Public_key_hash.rev_find cctxt pkh >>=? function - | None -> failwith "no keys for the source contract manager" - | Some n -> - Public_key.find_opt cctxt n >>=? fun pk_uri -> - Secret_key.find_opt cctxt n >>=? fun sk_uri -> + begin + Public_key_hash.rev_find cctxt pkh >>=? function + | None -> failwith "no keys for the source contract manager" + | Some n -> + Public_key.find_opt cctxt n >>=? fun pk_uri -> + Secret_key.find_opt cctxt n >>=? fun sk_uri -> + begin + Option.unopt_map + ~default:Lwt.return_none + ~f:(fun pkh -> + public_key pkh >>= function + | Error e -> + Format.eprintf "PLOP: %a@." pp_print_error e ; + Lwt.return_none + | Ok pk -> Lwt.return_some pk) + pk_uri + end >>= fun pk -> + return (n, pk, sk_uri) + end >>= function + | (Ok (_, None, None) | Error _) as initial_result -> begin begin - Option.unopt_map - ~default:Lwt.return_none - ~f:(fun pkh -> - public_key pkh >>= function - | Error e -> - Format.eprintf "PLOP: %a@." pp_print_error e ; - Lwt.return_none - | Ok pk -> Lwt.return_some pk) - pk_uri - end >>= fun pk -> - return (n, pk, sk_uri) + (* try to lookup for a remote key *) + find_signer_for_key ~scheme:"remote" >>=? fun signer -> + let module Signer = (val signer : SIGNER) in + let path = Signature.Public_key_hash.to_b58check pkh in + let uri = Uri.make ~scheme:Signer.scheme ~path () in + Signer.public_key uri >>=? fun pk -> + return (path, Some pk, Some uri) + end >>= function + | Error _ -> Lwt.return initial_result + | Ok _ as success -> Lwt.return success + end + | Ok _ as success -> Lwt.return success let get_key cctxt pkh = raw_get_key cctxt pkh >>=? function 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 021bcffdc..c93ae28df 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 @@ -222,7 +222,7 @@ let commands () = @@ tez_param ~name: "qty" ~desc: "amount taken from source" @@ prefix "from" - @@ ContractAlias.alias_param + @@ ContractAlias.destination_param ~name: "src" ~desc: "name of the source contract" @@ prefix "to" @@ ContractAlias.destination_param