From 6e68fb425a34cfaf4e974731041e7e3e4869561b Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Mon, 27 Nov 2017 17:23:21 +0100 Subject: [PATCH] Fix #66 and #59 --- .../embedded/alpha/client_proto_contracts.ml | 5 +++-- src/utils/base58.ml | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/client/embedded/alpha/client_proto_contracts.ml b/src/client/embedded/alpha/client_proto_contracts.ml index 29f57837e..8024e1a5c 100644 --- a/src/client/embedded/alpha/client_proto_contracts.ml +++ b/src/client/embedded/alpha/client_proto_contracts.ml @@ -63,7 +63,7 @@ module ContractAlias = struct let alias_param ?(name = "name") ?(desc = "existing contract alias") next = let desc = desc ^ "\n" - ^ "can be an contract alias or a key alias (autodetected in this order)\n\ + ^ "can be a contract alias or a key alias (autodetected in this order)\n\ use 'key:name' to force the later" in Cli_entries.( param ~name ~desc @@ -97,7 +97,8 @@ module ContractAlias = struct | Error k_errs -> ContractEntity.of_source cctxt s >>= function | Ok v -> return (s, v) - | Error c_errs -> Lwt.return (Error (k_errs @ c_errs)) + | Error c_errs -> + Lwt.return (Error (k_errs @ c_errs)) end))) next diff --git a/src/utils/base58.ml b/src/utils/base58.ml index fa61578e2..df3fca9ef 100644 --- a/src/utils/base58.ml +++ b/src/utils/base58.ml @@ -214,14 +214,16 @@ module MakeEncodings(E: sig l p enc.encoded_length let decode ?alphabet s = - let rec find s = function - | [] -> None - | Encoding { prefix ; of_raw ; wrap } :: encodings -> - match remove_prefix ~prefix s with - | None -> find s encodings - | Some msg -> of_raw msg |> Utils.map_option ~f:wrap in - let s = safe_decode ?alphabet s in - find s !encodings + try + let rec find s = function + | [] -> None + | Encoding { prefix ; of_raw ; wrap } :: encodings -> + match remove_prefix ~prefix s with + | None -> find s encodings + | Some msg -> of_raw msg |> Utils.map_option ~f:wrap in + let s = safe_decode ?alphabet s in + find s !encodings + with Invalid_argument _ -> None end