mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-11-17 04:47:28 +00:00
Utils: Move parseAsHexOrBase58() to WalletTool, as it's only being used there.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user