Skip to content

Commit

Permalink
added simulate (-n) and stop_after_first_match (-1) options
Browse files Browse the repository at this point in the history
  • Loading branch information
FiloSottile committed Sep 24, 2012
1 parent 7c1f495 commit d25c8a4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
10 changes: 8 additions & 2 deletions oclvanitygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ usage(const char *name)
{
fprintf(stderr,
"oclVanitygen %s (" OPENSSL_VERSION_TEXT ")\n"
"Usage: %s [-vqrikNTS] [-d <device>] [-f <filename>|-] [<pattern>...]\n"
"Usage: %s [-vqrik1NTS] [-d <device>] [-f <filename>|-] [<pattern>...]\n"
"Generates a bitcoin receiving address matching <pattern>, and outputs the\n"
"address and associated private key. The private key may be stored in a safe\n"
"location or imported into a bitcoin client to spend any balance received on\n"
Expand All @@ -56,6 +56,7 @@ usage(const char *name)
"-q Quiet output\n"
"-i Case-insensitive prefix search\n"
"-k Keep pattern and continue search after finding a match\n"
"-1 Stop after first match\n"
"-N Generate namecoin address\n"
"-T Generate bitcoin testnet address\n"
"-X <version> Generate address with the given version\n"
Expand Down Expand Up @@ -102,6 +103,7 @@ main(int argc, char **argv)
int nrows = 0, ncols = 0;
int invsize = 0;
int remove_on_match = 1;
int only_one = 0;
int verify_mode = 0;
int safe_mode = 0;
vg_context_t *vcp = NULL;
Expand All @@ -121,7 +123,7 @@ main(int argc, char **argv)
int i;

while ((opt = getopt(argc, argv,
"vqikNTX:eE:p:P:d:w:t:g:b:VSh?f:o:s:D:")) != -1) {
"vqik1NTX:eE:p:P:d:w:t:g:b:VSh?f:o:s:D:")) != -1) {
switch (opt) {
case 'v':
verbose = 2;
Expand All @@ -135,6 +137,9 @@ main(int argc, char **argv)
case 'k':
remove_on_match = 0;
break;
case '1':
only_one = 1;
break;
case 'N':
addrtype = 52;
privtype = 180;
Expand Down Expand Up @@ -328,6 +333,7 @@ main(int argc, char **argv)
vcp->vc_verbose = verbose;
vcp->vc_result_file = result_file;
vcp->vc_remove_on_match = remove_on_match;
vcp->vc_only_one = only_one;
vcp->vc_pubkeytype = addrtype;
vcp->vc_pubkey_base = pubkey_base;

Expand Down
9 changes: 9 additions & 0 deletions pattern.c
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,10 @@ vg_prefix_test(vg_exec_context_t *vxcp)

vcpp->base.vc_found++;

if (vcpp->base.vc_only_one) {
return 2;
}

if (vcpp->base.vc_remove_on_match) {
/* Subtract the range from the difficulty */
vg_prefix_range_sum(vp,
Expand Down Expand Up @@ -1784,6 +1788,11 @@ vg_regex_test(vg_exec_context_t *vxcp)
vcrp->vcr_regex_pat[i]);
vcrp->base.vc_found++;

if (vcrp->base.vc_only_one) {
res = 2;
goto out;
}

if (vcrp->base.vc_remove_on_match) {
pcre_free(vcrp->vcr_regex[i]);
if (vcrp->vcr_regex_extra[i])
Expand Down
1 change: 1 addition & 0 deletions pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ struct _vg_context_s {
const char *vc_result_file;
const char *vc_key_protect_pass;
int vc_remove_on_match;
int vc_only_one;
int vc_verbose;
enum vg_format vc_format;
int vc_pubkeytype;
Expand Down
18 changes: 16 additions & 2 deletions vanitygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ usage(const char *name)
{
fprintf(stderr,
"Vanitygen %s (" OPENSSL_VERSION_TEXT ")\n"
"Usage: %s [-vqrikNT] [-t <threads>] [-f <filename>|-] [<pattern>...]\n"
"Usage: %s [-vqnrik1NT] [-t <threads>] [-f <filename>|-] [<pattern>...]\n"
"Generates a bitcoin receiving address matching <pattern>, and outputs the\n"
"address and associated private key. The private key may be stored in a safe\n"
"location or imported into a bitcoin client to spend any balance received on\n"
Expand All @@ -305,10 +305,12 @@ usage(const char *name)
"Options:\n"
"-v Verbose output\n"
"-q Quiet output\n"
"-n Simulate\n"
"-r Use regular expression match instead of prefix\n"
" (Feasibility of expression is not checked)\n"
"-i Case-insensitive prefix search\n"
"-k Keep pattern and continue search after finding a match\n"
"-1 Stop after first match\n"
"-N Generate namecoin address\n"
"-T Generate bitcoin testnet address\n"
"-X <version> Generate address with the given version\n"
Expand Down Expand Up @@ -337,7 +339,9 @@ main(int argc, char **argv)
int regex = 0;
int caseinsensitive = 0;
int verbose = 1;
int simulate = 0;
int remove_on_match = 1;
int only_one = 0;
int prompt_password = 0;
int opt;
char *seedfile = NULL;
Expand All @@ -357,14 +361,17 @@ main(int argc, char **argv)

int i;

while ((opt = getopt(argc, argv, "vqrikeE:P:NTX:F:t:h?f:o:s:")) != -1) {
while ((opt = getopt(argc, argv, "vqnrik1eE:P:NTX:F:t:h?f:o:s:")) != -1) {
switch (opt) {
case 'v':
verbose = 2;
break;
case 'q':
verbose = 0;
break;
case 'n':
simulate = 1;
break;
case 'r':
regex = 1;
break;
Expand All @@ -374,6 +381,9 @@ main(int argc, char **argv)
case 'k':
remove_on_match = 0;
break;
case '1':
only_one = 1;
break;
case 'N':
addrtype = 52;
privtype = 180;
Expand Down Expand Up @@ -537,6 +547,7 @@ main(int argc, char **argv)
vcp->vc_verbose = verbose;
vcp->vc_result_file = result_file;
vcp->vc_remove_on_match = remove_on_match;
vcp->vc_only_one = only_one;
vcp->vc_format = format;
vcp->vc_pubkeytype = pubkeytype;
vcp->vc_pubkey_base = pubkey_base;
Expand Down Expand Up @@ -598,6 +609,9 @@ main(int argc, char **argv)
fprintf(stderr,
"Regular expressions: %ld\n", vcp->vc_npatterns);

if (simulate)
return 0;

if (!start_threads(vcp, nthreads))
return 1;
return 0;
Expand Down

0 comments on commit d25c8a4

Please sign in to comment.