#include #include /* * This program expects the hexadecimal block hash of a Bitcoin * block as a argument. This information is seen with bitcoind. * * bitcoind getblockhash */ #define HEXDIGITS 5 #define LOWVAL 1 #define HIGHVAL 429535 int main(int argc, char *argv[]) { unsigned long val; char *p; if (argc != 2) { fprintf(stderr, "usage: %s \n", argv[0]); return 1; } /* start with trailing hex digits of block-hash */ p = argv[1] + strlen(argv[1]) - HEXDIGITS; while (1) { if (p < argv[1]) { fprintf(stderr, "error: no value found\n"); return 1; } if (sscanf(p, "%lx", &val) != 1) { fprintf(stderr, "error: invalid block-hash\n"); return 1; } /* check value is acceptable */ if (val >= LOWVAL && val <= HIGHVAL) break; /* move back 1 hex digit and try again */ p--; *(p + HEXDIGITS) = 0; } printf("value: %lu (0x%lx)\n", val, val); return 0; }