/**
* 生成地址
* @return
*/
public static Map<String, String> createAddress() {
KeyPair keyPair = KeyPair.generate();
String privateKey = keyPair.toPrivateKey();
String base58CheckAddress = keyPair.toBase58CheckAddress();
Map<String, String> stringMap = new HashMap<>();
stringMap.put("address", base58CheckAddress);
stringMap.put("privateKey", privateKey);
return stringMap;
启动看了下大概一秒能生成几百个,速度太慢,写多线程来增加速度。
/**
* 新建一个线程生成地址
* @param minLength
*/
public static void runGenerate(int minLength ) {
new Thread(()->{
while (true){
Map<String, String> address = createAddress();
if ( isPrettyAddress(address.get("address"), minLength) ){
writeText(address.toString());
System.out.println("address = " + address);
}
}
}).start();
}
/**
* start
* @param num
* @param minLength
*/
public static void start(int num, int minLength) {
for (int i = 1; i <= num; i++) {
System.out.println("启动第"+i+"个线程");
runGenerate(minLength);
}
}