int main(int argc,const char **argv) { uint8_t publicKey[65] = { 0x04,0x50,0x86,0x3A,0xD6,0x4A,0x87,0xAE,0x8A,0x2F,0xE8,0x3C,0x1A, 0xF1,0xA8,0x40,0x3C,0xB5,0x3F,0x53,0xE4,0x86,0xD8,0x51,0x1D,0xAD, 0x8A,0x04,0x88,0x7E,0x5B,0x23,0x52,0x2C,0xD4,0x70,0x24,0x34,0x53, 0xA2,0x99,0xFA,0x9E,0x77,0x23,0x77,0x16,0x10,0x3A,0xBC,0x11,0xA1, 0xDF,0x38,0x85,0x5E,0xD6,0xF2,0xEE,0x18,0x7E,0x9C,0x58,0x2B,0xA6 }; char scratch[256]; uint8_t address1[25]; uint8_t address2[25]; bitcoinPublicKeyToAddress(0,publicKey,address1); bitcoinPublicKeyToAscii(0,publicKey,scratch,256); bitcoinAsciiToAddress(scratch,address2); const char *dataPath = "..\\..\\"; if ( argc < 2 ) { printf("Using local test FILE of the first 4310 blocks in the block chain.\r\n"); } else { dataPath = argv[1]; } BlockChain *b = createBlockChain(dataPath); // Create the block-chain parser using this root path if ( b ) { const BlockChain::Block *block = b->readBlock(); // read the first block while ( block ) { if ( block->blockIndex > 171 ) // only process the first 171 blocks for the moment { break; } b->printBlock(block); block = b->readBlock(); // keep reading blocks until we are done. } b->release(); // release the block-chain parser } return 0; }
int main(int argc,const char **argv) { bool analyze = false; uint32_t maxBlocks = 10000000; uint32_t searchForTextLength = 0; const char *dataPath = "."; searchForTextLength = 0; bool rebuildPublicKeyDatabase = false; int i = 1; while ( i < argc ) { const char *option = argv[i]; if ( *option == '-' ) { if ( strcmp(option,"-max_blocks") == 0 ) { i++; if ( i < argc ) { maxBlocks = atoi(argv[i]); if ( maxBlocks < 1 ) { printf("Invalid max_blocks value '%s'\n", argv[i] ); maxBlocks = 1000000; } else { printf("Maximum blocks set to %d\r\n", maxBlocks); } } else { printf("Error parsing option '-max_blocks', missing block number.\n"); } } else if (strcmp(option, "-analyze") == 0) { analyze = true; } else if (strcmp(option, "-rebuild") == 0) { rebuildPublicKeyDatabase = true; } else if (strcmp(option, "-text") == 0) { i++; if (i < argc) { searchForTextLength = atoi(argv[i]); if (maxBlocks < 8 ) { printf("Invalid search for text value value '%s'\n", argv[i]); searchForTextLength = 0; } else { printf("Search for text length %d\r\n", maxBlocks); } } else { printf("Error parsing option '-text', missing text length.\n"); } } else { printf("Unknown option '%s'\n", option ); } } else { if ( (i+1) == argc ) { printf("Using directory: %s to locate bitcoin data blocks.\n", option ); dataPath = option; } else { printf("%s not a valid option.\n", option ); } } i++; } PublicKeyDatabase *p = PublicKeyDatabase::create(analyze); if (p) { if (analyze) { if (rebuildPublicKeyDatabase) { printf("Rebuilding the public-key database.\r\n"); p->buildPublicKeyDatabase(); } else { p->reportDailyTransactions("Transactions.csv"); p->reportTopBalances("TopBalances.csv", 50000, 0xFFFFFFFF); } } else { BlockChain *b = BlockChain::createBlockChain(dataPath, maxBlocks); if (b) { b->setSearchTextLength(searchForTextLength); printf("Scanning the blockchain for blocks.\r\n"); for (;;) { uint32_t lastBlockRead; bool finished = b->scanBlockChain(lastBlockRead); if (finished) { break; } else { if ((lastBlockRead % 1000) == 0) { printf("Scanned block header: %d\r\n", lastBlockRead); } } } printf("Finished scanning the available blocks.\r\n"); printf("Now building the blockchain\r\n"); uint32_t ret = b->buildBlockChain(); printf("Found %d blocks.\r\n", ret); for (uint32_t i = 0; i < ret; i++) { if (((i + 1) % 100) == 0) { printf("Processing block: %d\r\n", i); } const BlockChain::Block *block = b->readBlock(i); if (block == nullptr) { printf("Finished reading blocks.\r\n"); break; } else { p->addBlock(block); if (kbhit()) { int c = getch(); if (c == 27) { break; } } } } printf("Completed parsing the blockchain.\r\n"); printf("Now building the public-key records database.\r\n"); p->buildPublicKeyDatabase(); b->release(); // release the blockchain parser } } p->release(); } #ifdef WIN32 // getch(); #endif return 0; }