mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-13 11:36:15 +01:00
Utils: Move parseAsHexOrBase58() to WalletTool, as it's only being used there.
This commit is contained in:
parent
e855030204
commit
84048b565b
2 changed files with 19 additions and 19 deletions
|
@ -397,23 +397,6 @@ public class Utils {
|
|||
return iso8601.format(dateTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to parse the given string as arbitrary-length hex or base58 and then return the results, or null if
|
||||
* neither parse was successful.
|
||||
*/
|
||||
public static byte[] parseAsHexOrBase58(String data) {
|
||||
try {
|
||||
return HEX.decode(data);
|
||||
} catch (Exception e) {
|
||||
// Didn't decode as hex, try base58.
|
||||
try {
|
||||
return Base58.decodeChecked(data);
|
||||
} catch (AddressFormatException e1) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isWindows() {
|
||||
return System.getProperty("os.name").toLowerCase().contains("win");
|
||||
}
|
||||
|
|
|
@ -1390,7 +1390,7 @@ public class WalletTool {
|
|||
}
|
||||
key = dpk.getKey();
|
||||
} else {
|
||||
byte[] decode = Utils.parseAsHexOrBase58(data);
|
||||
byte[] decode = parseAsHexOrBase58(data);
|
||||
if (decode == null) {
|
||||
System.err.println("Could not understand --privkey as either hex or base58: " + data);
|
||||
return;
|
||||
|
@ -1403,7 +1403,7 @@ public class WalletTool {
|
|||
}
|
||||
key.setCreationTimeSeconds(creationTimeSeconds);
|
||||
} else if (options.has("pubkey")) {
|
||||
byte[] pubkey = Utils.parseAsHexOrBase58((String) options.valueOf("pubkey"));
|
||||
byte[] pubkey = parseAsHexOrBase58((String) options.valueOf("pubkey"));
|
||||
key = ECKey.fromPublicOnly(pubkey);
|
||||
key.setCreationTimeSeconds(creationTimeSeconds);
|
||||
} else {
|
||||
|
@ -1427,6 +1427,23 @@ public class WalletTool {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to parse the given string as arbitrary-length hex or base58 and then return the results, or null if
|
||||
* neither parse was successful.
|
||||
*/
|
||||
private static byte[] parseAsHexOrBase58(String data) {
|
||||
try {
|
||||
return Utils.HEX.decode(data);
|
||||
} catch (Exception e) {
|
||||
// Didn't decode as hex, try base58.
|
||||
try {
|
||||
return Base58.decodeChecked(data);
|
||||
} catch (AddressFormatException e1) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static long getCreationTimeSeconds() {
|
||||
if (options.has(unixtimeFlag))
|
||||
return unixtimeFlag.value(options);
|
||||
|
|
Loading…
Add table
Reference in a new issue