mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 11:35:53 +00:00
Code to boostrap the initial ledger.
This commit is contained in:
@@ -11,6 +11,9 @@ AccountState::AccountState(const std::vector<unsigned char>& v)
|
|||||||
mValid=true;
|
mValid=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AccountState::AccountState(const uint160& id) : mAccountID(id), mBalance(0), mAccountSeq(0), mValid(true)
|
||||||
|
{ ; }
|
||||||
|
|
||||||
std::vector<unsigned char> AccountState::getRaw() const
|
std::vector<unsigned char> AccountState::getRaw() const
|
||||||
{ // 20-byte acct ID, 8-byte balance, 4-byte sequence
|
{ // 20-byte acct ID, 8-byte balance, 4-byte sequence
|
||||||
Serializer s(32);
|
Serializer s(32);
|
||||||
@@ -19,3 +22,4 @@ std::vector<unsigned char> AccountState::getRaw() const
|
|||||||
s.add32(mAccountSeq);
|
s.add32(mAccountSeq);
|
||||||
return s.getData();
|
return s.getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
23
Ledger.cpp
23
Ledger.cpp
@@ -11,8 +11,15 @@
|
|||||||
using namespace boost;
|
using namespace boost;
|
||||||
using namespace std;
|
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,
|
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);
|
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)
|
bool Ledger::addTransaction(Transaction::pointer trans)
|
||||||
{ // low-level - just add to table
|
{ // low-level - just add to table
|
||||||
SHAMapItem::pointer item(new SHAMapItem(trans->getID(), trans->getSigned()->getData()));
|
SHAMapItem::pointer item(new SHAMapItem(trans->getID(), trans->getSigned()->getData()));
|
||||||
@@ -90,6 +103,14 @@ Ledger::TransResult Ledger::applyTransaction(Transaction::pointer trans)
|
|||||||
// accounts exist?
|
// accounts exist?
|
||||||
AccountState::pointer fromAccount=getAccountState(trans->getFromAccount());
|
AccountState::pointer fromAccount=getAccountState(trans->getFromAccount());
|
||||||
AccountState::pointer toAccount=getAccountState(trans->getToAccount());
|
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;
|
if(!fromAccount || !toAccount) return TR_BADACCT;
|
||||||
|
|
||||||
// pass sanity checks?
|
// pass sanity checks?
|
||||||
|
|||||||
2
Ledger.h
2
Ledger.h
@@ -56,7 +56,7 @@ protected:
|
|||||||
bool delTransaction(const uint256& id);
|
bool delTransaction(const uint256& id);
|
||||||
|
|
||||||
public:
|
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 Ledger &ledger);
|
||||||
Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash,
|
Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash,
|
||||||
uint64 feeHeld, uint64 timeStamp, uint32 ledgerSeq); // used for received ledgers
|
uint64 feeHeld, uint64 timeStamp, uint32 ledgerSeq); // used for received ledgers
|
||||||
|
|||||||
Reference in New Issue
Block a user