mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 03:26:01 +00:00
Fix some small bugs in the Ledger code. Add a unit test. (Needs more tests.)
This commit is contained in:
37
Ledger.cpp
37
Ledger.cpp
@@ -4,6 +4,7 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Conversion.h"
|
#include "Conversion.h"
|
||||||
#include "BitcoinUtil.h"
|
#include "BitcoinUtil.h"
|
||||||
|
#include "Wallet.h"
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@@ -19,7 +20,8 @@ Ledger::Ledger(const uint160& masterID, uint64 startAmount) :
|
|||||||
|
|
||||||
AccountState::pointer startAccount=AccountState::pointer(new AccountState(masterID));
|
AccountState::pointer startAccount=AccountState::pointer(new AccountState(masterID));
|
||||||
startAccount->credit(startAmount);
|
startAccount->credit(startAmount);
|
||||||
addAccountState(startAccount);
|
if(!addAccountState(startAccount))
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ledger::Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash,
|
Ledger::Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash,
|
||||||
@@ -56,9 +58,18 @@ void Ledger::addRaw(Serializer &s)
|
|||||||
|
|
||||||
AccountState::pointer Ledger::getAccountState(const uint160& accountID)
|
AccountState::pointer Ledger::getAccountState(const uint160& accountID)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
std::cerr << "Ledger:getAccountState(" << accountID.GetHex() << ")" << std::endl;
|
||||||
|
#endif
|
||||||
ScopedLock l(mTransactionMap->Lock());
|
ScopedLock l(mTransactionMap->Lock());
|
||||||
SHAMapItem::pointer item=mTransactionMap->peekItem(uint160to256(accountID));
|
SHAMapItem::pointer item=mAccountStateMap->peekItem(uint160to256(accountID));
|
||||||
if(!item) return AccountState::pointer();
|
if(!item)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
std::cerr << " notfound" << std::endl;
|
||||||
|
#endif
|
||||||
|
return AccountState::pointer();
|
||||||
|
}
|
||||||
return AccountState::pointer(new AccountState(item->getData()));
|
return AccountState::pointer(new AccountState(item->getData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,6 +217,26 @@ Ledger::pointer Ledger::closeLedger(uint64 timeStamp)
|
|||||||
return Ledger::pointer(new Ledger(*this, timeStamp));
|
return Ledger::pointer(new Ledger(*this, timeStamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Ledger::unitTest(void)
|
||||||
|
{
|
||||||
|
LocalAccount l1(true), l2(true);
|
||||||
|
uint160 la1(l1.getAddress()), la2(l2.getAddress());
|
||||||
|
#ifdef DEBUG
|
||||||
|
std::cerr << "Account1: " << la1.GetHex() << std::endl;
|
||||||
|
std::cerr << "Account2: " << la2.GetHex() << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Ledger newLedger(la1, 10000);
|
||||||
|
|
||||||
|
AccountState::pointer as=newLedger.getAccountState(la1);
|
||||||
|
assert(as);
|
||||||
|
as=newLedger.getAccountState(la2);
|
||||||
|
assert(!as);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// TODO: we should probably make a shared pointer type for each of these PB types
|
// TODO: we should probably make a shared pointer type for each of these PB types
|
||||||
newcoin::FullLedger* Ledger::createFullLedger()
|
newcoin::FullLedger* Ledger::createFullLedger()
|
||||||
|
|||||||
2
Ledger.h
2
Ledger.h
@@ -94,6 +94,8 @@ public:
|
|||||||
Ledger::pointer closeLedger(uint64 timestamp);
|
Ledger::pointer closeLedger(uint64 timestamp);
|
||||||
bool isCompatible(boost::shared_ptr<Ledger> other);
|
bool isCompatible(boost::shared_ptr<Ledger> other);
|
||||||
bool signLedger(std::vector<unsigned char> &signature, const LocalHanko &hanko, int32 confidence);
|
bool signLedger(std::vector<unsigned char> &signature, const LocalHanko &hanko, int32 confidence);
|
||||||
|
|
||||||
|
static bool unitTest(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user