forked from Qortal/qortal
Add threading to VanityGen
This commit is contained in:
parent
4330782bb7
commit
f7c6978151
@ -4,6 +4,8 @@ import java.io.IOException;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.Security;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
|
||||
@ -16,16 +18,19 @@ import com.google.common.primitives.Bytes;
|
||||
|
||||
public class VanityGen {
|
||||
|
||||
public static void main(String argv[]) throws IOException {
|
||||
if (argv.length != 1) {
|
||||
System.err.println("Usage: Vanitygen <leading-chars>");
|
||||
// From utils.Base58:
|
||||
private static final String ALPHABET_STR = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||
|
||||
private static String prefix = null;
|
||||
|
||||
private static void usage() {
|
||||
System.err.println("Usage: Vanitygen [-t threads] <leading-chars>");
|
||||
System.err.println("Example: VanityGen Qcat");
|
||||
return;
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
Security.insertProviderAt(new BouncyCastleProvider(), 0);
|
||||
Security.insertProviderAt(new BouncyCastleJsseProvider(), 1);
|
||||
|
||||
private static class Generator implements Runnable {
|
||||
public void run() {
|
||||
Random random = new SecureRandom();
|
||||
byte[] entropy = new byte[16];
|
||||
|
||||
@ -44,9 +49,56 @@ public class VanityGen {
|
||||
|
||||
PrivateKeyAccount account = new PrivateKeyAccount(null, hash);
|
||||
|
||||
if (account.getAddress().startsWith(argv[0]))
|
||||
System.out.println(String.format("Address: %s, public key: %s, private key: %s, mnemonic: %s", account.getAddress(), Base58.encode(account.getPublicKey()), Base58.encode(hash), mnemonic));
|
||||
if (!account.getAddress().startsWith(prefix))
|
||||
continue;
|
||||
|
||||
System.out.println(String.format("Address: %s, public key: %s, private key: %s, mnemonic: %s",
|
||||
account.getAddress(), Base58.encode(account.getPublicKey()), Base58.encode(hash), mnemonic));
|
||||
System.out.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) throws IOException {
|
||||
if (argv.length == 0)
|
||||
usage();
|
||||
|
||||
int threadCount = 1;
|
||||
|
||||
int argIndex = 0;
|
||||
while (argIndex < argv.length) {
|
||||
String arg = argv[argIndex++];
|
||||
|
||||
if (arg.equals("-t")) {
|
||||
if (argIndex >= argv.length)
|
||||
usage();
|
||||
|
||||
try {
|
||||
threadCount = Integer.parseInt(argv[argIndex++]);
|
||||
} catch (NumberFormatException e) {
|
||||
usage();
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (prefix != null)
|
||||
usage();
|
||||
|
||||
prefix = arg;
|
||||
if (!prefix.matches("[" + ALPHABET_STR + "]+")) {
|
||||
System.err.println("Only the following characters are allowed:\n" + ALPHABET_STR);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
Security.insertProviderAt(new BouncyCastleProvider(), 0);
|
||||
Security.insertProviderAt(new BouncyCastleJsseProvider(), 1);
|
||||
|
||||
ExecutorService executor = Executors.newFixedThreadPool(threadCount);
|
||||
|
||||
for (int ti = 0; ti < threadCount; ++ti)
|
||||
executor.execute(new Generator());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user