Client: don't try to generate vanity keys with wrong first letter

This commit is contained in:
Fabrice Le Fessant 2018-06-20 16:46:32 +02:00 committed by Benjamin Canou
parent 7e4a0f3368
commit 89c018f31b

View File

@ -38,15 +38,36 @@ let gen_keys_containing
~containing ~name (cctxt : #Client_context.io_wallet) =
let unrepresentable =
List.filter (fun s -> not @@ Base58.Alphabet.all_in_alphabet Base58.Alphabet.bitcoin s) containing in
let good_initial_char = "KLMNPQRSTUVWXYZabcdefghi" in
let bad_initial_char = "123456789ABCDEFGHJjkmnopqrstuvwxyz" in
match unrepresentable with
| _ :: _ ->
cctxt#warning
"The following can't be written in the key alphabet (%a): %a"
Base58.Alphabet.pp Base58.Alphabet.bitcoin
cctxt#error
"@[<v 0>The following words can't be written in the key alphabet: %a.@,\
Valid characters: %a@,\
Extra restriction for the first character: %s@]"
(Format.pp_print_list
~pp_sep:(fun ppf () -> Format.fprintf ppf ", ")
(fun ppf s -> Format.fprintf ppf "'%s'" s))
unrepresentable >>= return
unrepresentable
Base58.Alphabet.pp Base58.Alphabet.bitcoin
good_initial_char
| [] ->
let unrepresentable =
List.filter (fun s -> prefix &&
String.contains bad_initial_char s.[0]) containing in
match unrepresentable with
| _ :: _ ->
cctxt#error
"@[<v 0>The following words don't respect the first character restriction: %a.@,\
Valid characters: %a@,\
Extra restriction for the first character: %s@]"
(Format.pp_print_list
~pp_sep:(fun ppf () -> Format.fprintf ppf ", ")
(fun ppf s -> Format.fprintf ppf "'%s'" s))
unrepresentable
Base58.Alphabet.pp Base58.Alphabet.bitcoin
good_initial_char
| [] ->
Public_key_hash.mem cctxt name >>=? fun name_exists ->
if name_exists && not force
@ -86,7 +107,8 @@ let gen_keys_containing
(public_key_hash, pk_uri, sk_uri) name >>=? fun () ->
return hash
else begin if attempts mod 25_000 = 0
then cctxt#message "Tried %d keys without finding a match" attempts
then
cctxt#message "Tried %d keys without finding a match" attempts
else Lwt.return () end >>= fun () ->
loop (attempts + 1) in
loop 1 >>=? fun key_hash ->