Rework addresses.

This commit is contained in:
Arthur Britto
2012-03-17 20:19:09 -07:00
parent 6e8421dd99
commit 73ff9b95ad
33 changed files with 1287 additions and 708 deletions

View File

@@ -15,13 +15,13 @@
#include "Wallet.h"
#include "BinaryFormats.h"
Ledger::Ledger(const uint160& masterID, uint64 startAmount) :
Ledger::Ledger(const NewcoinAddress& masterID, uint64 startAmount) :
mFeeHeld(0), mTimeStamp(0), mLedgerSeq(0),
mClosed(false), mValidHash(false), mAccepted(false), mImmutable(false)
{
mTransactionMap=boost::make_shared<SHAMap>();
mAccountStateMap=boost::make_shared<SHAMap>();
AccountState::pointer startAccount=boost::make_shared<AccountState>(masterID);
startAccount->credit(startAmount);
if(!addAccountState(startAccount))
@@ -110,13 +110,13 @@ void Ledger::addRaw(Serializer &s)
s.add64(mTimeStamp);
}
AccountState::pointer Ledger::getAccountState(const uint160& accountID)
AccountState::pointer Ledger::getAccountState(const NewcoinAddress& accountID)
{
#ifdef DEBUG
std::cerr << "Ledger:getAccountState(" << accountID.GetHex() << ")" << std::endl;
std::cerr << "Ledger:getAccountState(" << accountID.humanAccountID() << ")" << std::endl;
#endif
ScopedLock l(mTransactionMap->Lock());
SHAMapItem::pointer item=mAccountStateMap->peekItem(accountID.to256());
SHAMapItem::pointer item=mAccountStateMap->peekItem(accountID.getAccountID().to256());
if(!item)
{
#ifdef DEBUG
@@ -127,10 +127,10 @@ AccountState::pointer Ledger::getAccountState(const uint160& accountID)
return boost::make_shared<AccountState>(item->getData());
}
uint64 Ledger::getBalance(const uint160& accountID) const
uint64 Ledger::getBalance(const NewcoinAddress& accountID) const
{
ScopedLock l(mTransactionMap->Lock());
SHAMapItem::pointer item=mAccountStateMap->peekItem(accountID.to256());
SHAMapItem::pointer item=mAccountStateMap->peekItem(accountID.getAccountID().to256());
if(!item) return 0;
return AccountState(item->getData()).getBalance();
}
@@ -138,7 +138,7 @@ uint64 Ledger::getBalance(const uint160& accountID) const
bool Ledger::updateAccountState(AccountState::pointer state)
{
assert(!mAccepted);
SHAMapItem::pointer item=boost::make_shared<SHAMapItem>(state->getAccountID(), state->getRaw());
SHAMapItem::pointer item=boost::make_shared<SHAMapItem>(state->getAccountID().getAccountID(), state->getRaw());
return mAccountStateMap->updateGiveItem(item, false);
}
@@ -146,7 +146,7 @@ bool Ledger::addAccountState(AccountState::pointer state)
{
assert(!mAccepted);
assert( (state->getBalance()==0) || (state->getSeq()>0) );
SHAMapItem::pointer item=boost::make_shared<SHAMapItem>(state->getAccountID(), state->getRaw());
SHAMapItem::pointer item=boost::make_shared<SHAMapItem>(state->getAccountID().getAccountID(), state->getRaw());
return mAccountStateMap->addGiveItem(item, false);
}
@@ -345,6 +345,7 @@ void LocalAccount::syncLedger()
bool Ledger::unitTest()
{
#if 0
uint160 la1=theApp->getWallet().addFamily(CKey::PassPhraseToKey("This is my payphrase!"), false);
uint160 la2=theApp->getWallet().addFamily(CKey::PassPhraseToKey("Another payphrase"), false);
@@ -354,12 +355,12 @@ bool Ledger::unitTest()
assert(l1->getAddress()==la1);
#ifdef DEBUG
std::cerr << "Account1: " << la1.GetHex() << std::endl;
std::cerr << "Account2: " << la2.GetHex() << std::endl;
std::cerr << "Account1: " << la1.humanAccountID() << std::endl;
std::cerr << "Account2: " << la2.humanAccountID() << std::endl;
#endif
Ledger::pointer ledger=boost::make_shared<Ledger>(la1, 100000);
ledger=Ledger::pointer(new Ledger(*ledger, 0)); // can't use make_shared
AccountState::pointer as=ledger->getAccountState(la1);
@@ -367,7 +368,7 @@ bool Ledger::unitTest()
assert(as->getBalance()==100000);
assert(as->getSeq()==0);
as=ledger->getAccountState(la2);
assert(!as);
assert(!as);
Transaction::pointer t=boost::make_shared<Transaction>(l1, l2->getAddress(), 2500, 0, 1);
assert(!!t->getID());
@@ -377,7 +378,7 @@ bool Ledger::unitTest()
std::cerr << "Transaction: " << tr << std::endl;
#endif
assert(tr==TR_SUCCESS);
#endif
return true;
}