MCPcopy Create free account
hub / github.com/JeanLucPons/VanitySearch / initPrefix

Method initPrefix

Vanity.cpp:338–526  ·  view source on GitHub ↗

----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

336
337// ----------------------------------------------------------------------------
338bool VanitySearch::initPrefix(std::string &prefix,PREFIX_ITEM *it) {
339
340 std::vector<unsigned char> result;
341 string dummy1 = prefix;
342 int nbDigit = 0;
343 bool wrong = false;
344
345 if (prefix.length() < 2) {
346 printf("Ignoring prefix \"%s\" (too short)\n",prefix.c_str());
347 return false;
348 }
349
350 int aType = -1;
351
352
353 switch (prefix.data()[0]) {
354 case '1':
355 aType = P2PKH;
356 break;
357 case '3':
358 aType = P2SH;
359 break;
360 case 'b':
361 case 'B':
362 std::transform(prefix.begin(), prefix.end(), prefix.begin(), ::tolower);
363 if(strncmp(prefix.c_str(), "bc1q", 4) == 0)
364 aType = BECH32;
365 break;
366 }
367
368 if (aType==-1) {
369 printf("Ignoring prefix \"%s\" (must start with 1 or 3 or bc1q)\n", prefix.c_str());
370 return false;
371 }
372
373 if (searchType == -1) searchType = aType;
374 if (aType != searchType) {
375 printf("Ignoring prefix \"%s\" (P2PKH, P2SH or BECH32 allowed at once)\n", prefix.c_str());
376 return false;
377 }
378
379 if (aType == BECH32) {
380
381 // BECH32
382 uint8_t witprog[40];
383 size_t witprog_len;
384 int witver;
385 const char* hrp = "bc";
386
387 int ret = segwit_addr_decode(&witver, witprog, &witprog_len, hrp, prefix.c_str());
388
389 // Try to attack a full address ?
390 if (ret && witprog_len==20) {
391
392 // mamma mia !
393 it->difficulty = pow(2, 160);
394 it->isFull = true;
395 memcpy(it->hash160, witprog, 20);

Callers

nothing calls this directly

Calls 3

segwit_addr_decodeFunction · 0.85
bech32_decode_nocheckFunction · 0.85
DecodeBase58Function · 0.85

Tested by

no test coverage detected