From 8ff84c66dbb8b0b6580ce750b63534599c53c93f Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Sun, 10 Mar 2024 20:52:46 +0100 Subject: [PATCH] Argument parsing and difficulty estimation --- README.md | 2 +- run.sh | 1 - .../jmaa/pbc/PbcVanityAddressSearcher.java | 82 +++++++++++++++---- 3 files changed, 65 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 1a20380..c68c712 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Tiny vanity address generator for [Partisia Blockchain](https://www.partisiabloc Usage: ```bash -./run.sh "00PREFIX" "SUFFIX" +./run.sh --prefix 00PREFIX --suffix SUFFIX ``` Prefix must include the `00` part. diff --git a/run.sh b/run.sh index 4084a29..b6ce3f4 100755 --- a/run.sh +++ b/run.sh @@ -1,3 +1,2 @@ #!/usr/bin/env bash -echo $* mvn compile exec:java -Dexec.mainClass="jmaa.pbc.PbcVanityAddressSearcher" -Dexec.args="$*" diff --git a/src/main/java/jmaa/pbc/PbcVanityAddressSearcher.java b/src/main/java/jmaa/pbc/PbcVanityAddressSearcher.java index 6f32a46..15d2f50 100644 --- a/src/main/java/jmaa/pbc/PbcVanityAddressSearcher.java +++ b/src/main/java/jmaa/pbc/PbcVanityAddressSearcher.java @@ -1,6 +1,7 @@ package jmaa.pbc; import java.util.List; +import java.math.BigInteger; import java.util.ArrayList; import com.partisiablockchain.BlockchainAddress; import com.partisiablockchain.crypto.BlockchainPublicKey; @@ -15,22 +16,17 @@ public final class PbcVanityAddressSearcher { private static final long INITIAL_PING_INTERVAL = 10_000; public static void main(String[] args) throws InterruptedException { - searchForPrivateKeyWithVanityAddress(args[0], args[1]); + final AddressRequirements requirements = parseArgumentsToRequirements(args); + searchForPrivateKeyWithVanityAddress(requirements); } - /** - * @param vanityPrefix Desired address prefix - */ - private static void searchForPrivateKeyWithVanityAddress(String vanityPrefix, String vanitySuffix) throws InterruptedException { - if (!vanityPrefix.startsWith("00")) { - throw new IllegalArgumentException("Vanity prefix must start with 00."); - } - - System.out.println("Searching for private key for address prefix \"%s\" and suffix \"%s\" ".formatted(vanityPrefix, vanitySuffix)); + private static void searchForPrivateKeyWithVanityAddress(AddressRequirements addressRequirements) throws InterruptedException { + System.out.println("Searching for private key: %s".formatted(addressRequirements)); + System.out.println("Difficulty: 1/%s".formatted(addressRequirements.difficulty())); List searchers = new ArrayList<>(); for(int threadIdx=0;threadIdx