Client: allow tz1... as the source of a transfer

This is only useful when a 'remote signer' is available.
This commit is contained in:
Grégoire Henry 2018-05-26 13:41:51 +02:00
parent fb85568d98
commit da921a8f56
2 changed files with 33 additions and 17 deletions

View File

@ -141,23 +141,39 @@ let register_key cctxt ?(force=false) (public_key_hash, pk_uri, sk_uri) name =
return () return ()
let raw_get_key (cctxt : #Client_context.wallet) pkh = let raw_get_key (cctxt : #Client_context.wallet) pkh =
Public_key_hash.rev_find cctxt pkh >>=? function begin
| None -> failwith "no keys for the source contract manager" Public_key_hash.rev_find cctxt pkh >>=? function
| Some n -> | None -> failwith "no keys for the source contract manager"
Public_key.find_opt cctxt n >>=? fun pk_uri -> | Some n ->
Secret_key.find_opt cctxt n >>=? fun sk_uri -> 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 begin
Option.unopt_map (* try to lookup for a remote key *)
~default:Lwt.return_none find_signer_for_key ~scheme:"remote" >>=? fun signer ->
~f:(fun pkh -> let module Signer = (val signer : SIGNER) in
public_key pkh >>= function let path = Signature.Public_key_hash.to_b58check pkh in
| Error e -> let uri = Uri.make ~scheme:Signer.scheme ~path () in
Format.eprintf "PLOP: %a@." pp_print_error e ; Signer.public_key uri >>=? fun pk ->
Lwt.return_none return (path, Some pk, Some uri)
| Ok pk -> Lwt.return_some pk) end >>= function
pk_uri | Error _ -> Lwt.return initial_result
end >>= fun pk -> | Ok _ as success -> Lwt.return success
return (n, pk, sk_uri) end
| Ok _ as success -> Lwt.return success
let get_key cctxt pkh = let get_key cctxt pkh =
raw_get_key cctxt pkh >>=? function raw_get_key cctxt pkh >>=? function

View File

@ -222,7 +222,7 @@ let commands () =
@@ tez_param @@ tez_param
~name: "qty" ~desc: "amount taken from source" ~name: "qty" ~desc: "amount taken from source"
@@ prefix "from" @@ prefix "from"
@@ ContractAlias.alias_param @@ ContractAlias.destination_param
~name: "src" ~desc: "name of the source contract" ~name: "src" ~desc: "name of the source contract"
@@ prefix "to" @@ prefix "to"
@@ ContractAlias.destination_param @@ ContractAlias.destination_param