Browse Source

Require prime number to start eth.

cl-refactor
Gav Wood 10 years ago
parent
commit
a9b26e141e
  1. 40
      eth/main.cpp

40
eth/main.cpp

@ -241,6 +241,16 @@ string pretty(h160 _a, dev::eth::State const& _st)
bool g_exit = false; bool g_exit = false;
inline bool isPrime(unsigned _number)
{
if (((!(_number & 1)) && _number != 2 ) || (_number < 2) || (_number % 3 == 0 && _number != 3))
return false;
for(unsigned k = 1; 36 * k * k - 12 * k < _number; ++k)
if ((_number % (6 * k + 1) == 0) || (_number % (6 * k - 1) == 0))
return false;
return true;
}
void sighandler(int) void sighandler(int)
{ {
g_exit = true; g_exit = true;
@ -281,6 +291,7 @@ int main(int argc, char** argv)
/// Operating mode. /// Operating mode.
OperationMode mode = OperationMode::Node; OperationMode mode = OperationMode::Node;
string dbPath; string dbPath;
unsigned prime = 0;
/// File name for import/export. /// File name for import/export.
string filename; string filename;
@ -404,6 +415,16 @@ int main(int argc, char** argv)
mode = OperationMode::Export; mode = OperationMode::Export;
filename = argv[++i]; filename = argv[++i];
} }
else if (arg == "--prime" && i + 1 < argc)
try
{
prime = stoi(argv[++i]);
}
catch (...)
{
cerr << "Bad " << arg << " option: " << argv[i] << endl;
return -1;
}
else if (arg == "--sentinel" && i + 1 < argc) else if (arg == "--sentinel" && i + 1 < argc)
sentinel = argv[++i]; sentinel = argv[++i];
else if (arg == "--mine-on-wrong-chain") else if (arg == "--mine-on-wrong-chain")
@ -803,6 +824,25 @@ int main(int argc, char** argv)
return 0; return 0;
} }
{
auto pd = contents(getDataDir() + "primes");
unordered_set<unsigned> primes = RLP(pd).toUnorderedSet<unsigned>();
while (true)
{
if (!prime)
try
{
prime = stoi(getPassword("To enter the Frontier, enter a 6 digit prime that you have not entered before: "));
}
catch (...) {}
if (isPrime(prime) && !primes.count(prime))
break;
prime = 0;
}
primes.insert(prime);
writeFile(getDataDir() + "primes", rlp(primes));
}
if (keyManager.exists()) if (keyManager.exists())
{ {
if (masterPassword.empty() || !keyManager.load(masterPassword)) if (masterPassword.empty() || !keyManager.load(masterPassword))

Loading…
Cancel
Save