Code to boostrap the initial ledger.

This commit is contained in:
JoelKatz
2011-11-26 00:57:31 -08:00
parent 06a9bc5520
commit e87a027df2
3 changed files with 28 additions and 3 deletions

View File

@@ -11,6 +11,9 @@ AccountState::AccountState(const std::vector<unsigned char>& v)
mValid=true;
}
AccountState::AccountState(const uint160& id) : mAccountID(id), mBalance(0), mAccountSeq(0), mValid(true)
{ ; }
std::vector<unsigned char> AccountState::getRaw() const
{ // 20-byte acct ID, 8-byte balance, 4-byte sequence
Serializer s(32);
@@ -19,3 +22,4 @@ std::vector<unsigned char> AccountState::getRaw() const
s.add32(mAccountSeq);
return s.getData();
}

View File

@@ -11,8 +11,15 @@
using namespace boost;
using namespace std;
Ledger::Ledger(uint32 index) : mFeeHeld(0), mTimeStamp(0), mLedgerSeq(index), mCurrent(true)
Ledger::Ledger(const uint160& masterID, uint64 startAmount) :
mFeeHeld(0), mTimeStamp(0), mLedgerSeq(0), mCurrent(true)
{
mTransactionMap=SHAMap::pointer(new SHAMap());
mAccountStateMap=SHAMap::pointer(new SHAMap());
AccountState::pointer startAccount=AccountState::pointer(new AccountState(masterID));
startAccount->credit(startAmount);
addAccountState(startAccount);
}
Ledger::Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash,
@@ -54,6 +61,12 @@ bool Ledger::updateAccountState(AccountState::pointer state)
return mAccountStateMap->updateGiveItem(item);
}
bool Ledger::addAccountState(AccountState::pointer state)
{
SHAMapItem::pointer item(new SHAMapItem(state->getAccountID(), state->getRaw()));
return mAccountStateMap->addGiveItem(item);
}
bool Ledger::addTransaction(Transaction::pointer trans)
{ // low-level - just add to table
SHAMapItem::pointer item(new SHAMapItem(trans->getID(), trans->getSigned()->getData()));
@@ -90,6 +103,14 @@ Ledger::TransResult Ledger::applyTransaction(Transaction::pointer trans)
// accounts exist?
AccountState::pointer fromAccount=getAccountState(trans->getFromAccount());
AccountState::pointer toAccount=getAccountState(trans->getToAccount());
// temporary code -- if toAccount doesn't exist but fromAccount does, create it
if(!!fromAccount && !toAccount)
{
toAccount=AccountState::pointer(new AccountState(trans->getToAccount()));
updateAccountState(toAccount);
}
if(!fromAccount || !toAccount) return TR_BADACCT;
// pass sanity checks?

View File

@@ -56,7 +56,7 @@ protected:
bool delTransaction(const uint256& id);
public:
Ledger(uint32 index); // used for the starting bootstrap ledger
Ledger(const uint160& masterID, uint64 startAmount); // used for the starting bootstrap ledger
Ledger(const Ledger &ledger);
Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash,
uint64 feeHeld, uint64 timeStamp, uint32 ledgerSeq); // used for received ledgers