| 439 | } |
| 440 | |
| 441 | KeyPair KeyManager::newKeyPair(KeyManager::NewKeyType _type) |
| 442 | { |
| 443 | KeyPair p; |
| 444 | bool keepGoing = true; |
| 445 | unsigned done = 0; |
| 446 | function<void()> f = [&]() { |
| 447 | KeyPair lp; |
| 448 | while (keepGoing) |
| 449 | { |
| 450 | done++; |
| 451 | if (done % 1000 == 0) |
| 452 | cnote << "Tried" << done << "keys"; |
| 453 | lp = KeyPair::create(); |
| 454 | auto a = lp.address(); |
| 455 | if (_type == NewKeyType::NoVanity || |
| 456 | (_type == NewKeyType::DirectICAP && !a[0]) || |
| 457 | (_type == NewKeyType::FirstTwo && a[0] == a[1]) || |
| 458 | (_type == NewKeyType::FirstTwoNextTwo && a[0] == a[1] && a[2] == a[3]) || |
| 459 | (_type == NewKeyType::FirstThree && a[0] == a[1] && a[1] == a[2]) || |
| 460 | (_type == NewKeyType::FirstFour && a[0] == a[1] && a[1] == a[2] && a[2] == a[3]) |
| 461 | ) |
| 462 | break; |
| 463 | } |
| 464 | if (keepGoing) |
| 465 | p = lp; |
| 466 | keepGoing = false; |
| 467 | }; |
| 468 | |
| 469 | vector<std::thread*> ts; |
| 470 | for (unsigned t = 0; t < std::thread::hardware_concurrency() - 1; ++t) |
| 471 | ts.push_back(new std::thread(f)); |
| 472 | f(); |
| 473 | |
| 474 | for (std::thread* t: ts) |
| 475 | { |
| 476 | t->join(); |
| 477 | delete t; |
| 478 | } |
| 479 | return p; |
| 480 | } |