Properly support importing dumped private keys in WalletTool.

This commit is contained in:
Mike Hearn 2013-02-20 00:05:49 +01:00
parent 32cc7b4880
commit 420a29a388

View File

@ -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.");