allow you to load old ledger

This commit is contained in:
jed
2012-10-09 03:01:32 -07:00
parent 720178cc0d
commit 573865cb23
10 changed files with 92 additions and 37 deletions

View File

@@ -73,6 +73,7 @@ void Application::run()
boost::thread auxThread(boost::bind(&boost::asio::io_service::run, &mAuxService));
auxThread.detach();
if (!theConfig.RUN_STANDALONE)
mSNTPClient.init(theConfig.SNTP_SERVERS);
@@ -87,9 +88,24 @@ void Application::run()
boost::thread t6(boost::bind(&InitDB, &mNetNodeDB, "netnode.db", NetNodeDBInit, NetNodeDBCount));
t1.join(); t2.join(); t3.join(); t4.join(); t5.join(); t6.join();
if(theConfig.START_UP==Config::FRESH)
{
Log(lsINFO) << "Starting new Ledger";
startNewLedger();
}else if(theConfig.START_UP==Config::LOAD)
{
Log(lsINFO) << "Loading Old Ledger";
loadOldLedger();
}else
{ // TODO: This should really not validate a ledger until it gets the current one from our peers
// but I'll let david make this change since a lot of code assumes we have a ledger
// for now just do what we always were doing
startNewLedger();
}
//
// Begin validation and ip maintenance.
// - Wallet maintains local information: including identity and network connection persistency information.
// - Wallet maintains local information: including identity and network connection persistence information.
//
mWallet.start();
@@ -132,32 +148,8 @@ void Application::run()
if (!theConfig.RUN_STANDALONE)
mConnectionPool.start();
// New stuff.
NewcoinAddress rootSeedMaster = NewcoinAddress::createSeedGeneric("masterpassphrase");
NewcoinAddress rootGeneratorMaster = NewcoinAddress::createGeneratorPublic(rootSeedMaster);
NewcoinAddress rootAddress = NewcoinAddress::createAccountPublic(rootGeneratorMaster, 0);
// Print enough information to be able to claim root account.
Log(lsINFO) << "Root master seed: " << rootSeedMaster.humanSeed();
Log(lsINFO) << "Root account: " << rootAddress.humanAccountID();
{
Ledger::pointer firstLedger = boost::make_shared<Ledger>(rootAddress, SYSTEM_CURRENCY_START);
assert(!!firstLedger->getAccountState(rootAddress));
firstLedger->updateHash();
firstLedger->setClosed();
firstLedger->setAccepted();
mMasterLedger.pushLedger(firstLedger);
Ledger::pointer secondLedger = boost::make_shared<Ledger>(true, boost::ref(*firstLedger));
secondLedger->setClosed();
secondLedger->setAccepted();
mMasterLedger.pushLedger(secondLedger, boost::make_shared<Ledger>(true, boost::ref(*secondLedger)));
assert(!!secondLedger->getAccountState(rootAddress));
mNetOps.setLastCloseTime(secondLedger->getCloseTimeNC());
}
if (theConfig.RUN_STANDALONE)
{
Log(lsWARNING) << "Running in standalone mode";
@@ -182,4 +174,44 @@ Application::~Application()
delete mHashNodeDB;
delete mNetNodeDB;
}
void Application::startNewLedger()
{
// New stuff.
NewcoinAddress rootSeedMaster = NewcoinAddress::createSeedGeneric("masterpassphrase");
NewcoinAddress rootGeneratorMaster = NewcoinAddress::createGeneratorPublic(rootSeedMaster);
NewcoinAddress rootAddress = NewcoinAddress::createAccountPublic(rootGeneratorMaster, 0);
// Print enough information to be able to claim root account.
Log(lsINFO) << "Root master seed: " << rootSeedMaster.humanSeed();
Log(lsINFO) << "Root account: " << rootAddress.humanAccountID();
{
Ledger::pointer firstLedger = boost::make_shared<Ledger>(rootAddress, SYSTEM_CURRENCY_START);
assert(!!firstLedger->getAccountState(rootAddress));
firstLedger->updateHash();
firstLedger->setClosed();
firstLedger->setAccepted();
mMasterLedger.pushLedger(firstLedger);
Ledger::pointer secondLedger = boost::make_shared<Ledger>(true, boost::ref(*firstLedger));
secondLedger->setClosed();
secondLedger->setAccepted();
mMasterLedger.pushLedger(secondLedger, boost::make_shared<Ledger>(true, boost::ref(*secondLedger)));
assert(!!secondLedger->getAccountState(rootAddress));
mNetOps.setLastCloseTime(secondLedger->getCloseTimeNC());
}
}
void Application::loadOldLedger()
{
Ledger::pointer lastLedger = Ledger::getSQL("SELECT * from Ledgers order by LedgerSeq desc limit 1;",true);
if(!lastLedger)
{
std::cout << "No Ledger found?" << std::endl;
exit(-1);
}
mMasterLedger.pushLedger(lastLedger);
mNetOps.setLastCloseTime(lastLedger->getCloseTimeNC());
}
// vim:ts=4