From 420a29a388cda86e938eae2a224ad11f547d79b3 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Wed, 20 Feb 2013 00:05:49 +0100 Subject: [PATCH] Properly support importing dumped private keys in WalletTool. --- .../com/google/bitcoin/tools/WalletTool.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tools/src/main/java/com/google/bitcoin/tools/WalletTool.java b/tools/src/main/java/com/google/bitcoin/tools/WalletTool.java index 7b72b4d5d..130af465c 100644 --- a/tools/src/main/java/com/google/bitcoin/tools/WalletTool.java +++ b/tools/src/main/java/com/google/bitcoin/tools/WalletTool.java @@ -630,12 +630,23 @@ public class WalletTool { } if (options.has("privkey")) { String data = (String) options.valueOf("privkey"); - byte[] decode = Utils.parseAsHexOrBase58(data); - if (decode == null) { - System.err.println("Could not understand --privkey as either hex or base58: " + data); - return; + if (data.charAt(0) == 'L') { + DumpedPrivateKey dpk; + try { + dpk = new DumpedPrivateKey(params, data); + } catch (AddressFormatException e) { + System.err.println("Could not parse dumped private key " + data); + return; + } + key = dpk.getKey(); + } else { + byte[] decode = Utils.parseAsHexOrBase58(data); + if (decode == null) { + System.err.println("Could not understand --privkey as either hex or base58: " + data); + return; + } + key = new ECKey(new BigInteger(1, decode)); } - key = new ECKey(new BigInteger(1, decode)); if (options.has("pubkey")) { // Give the user a hint. System.out.println("You don't have to specify --pubkey when a private key is supplied.");