mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Rework AccountState to fit new model.
This commit is contained in:
@@ -1,42 +1,32 @@
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include "AccountState.h"
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
#include "Ledger.h"
|
||||
#include "Serializer.h"
|
||||
|
||||
AccountState::AccountState(const std::vector<unsigned char>& v)
|
||||
AccountState::AccountState(const NewcoinAddress& id) : mAccountID(id), mValid(false)
|
||||
{
|
||||
Serializer s(v);
|
||||
mValid=false;
|
||||
uint160 acct160 = mAccountID.getAccountID();
|
||||
|
||||
if(!s.get160(acct160, 0)) { assert(false); return; }
|
||||
if(!s.get64(mBalance, 20)) { assert(false); return; }
|
||||
if(!s.get32(mAccountSeq, 28)) { assert(false); return; }
|
||||
mValid=true;
|
||||
if (!id.IsValid()) return;
|
||||
mLedgerEntry = boost::make_shared<SerializedLedgerEntry>(ltACCOUNT_ROOT);
|
||||
mLedgerEntry->setIndex(Ledger::getAccountRootIndex(id));
|
||||
mLedgerEntry->setIFieldAccount(sfAccount, id);
|
||||
mValid = true;
|
||||
}
|
||||
|
||||
AccountState::AccountState(const NewcoinAddress& 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);
|
||||
s.add160(mAccountID.getAccountID());
|
||||
s.add64(mBalance);
|
||||
s.add32(mAccountSeq);
|
||||
return s.getData();
|
||||
AccountState::AccountState(SerializedLedgerEntry::pointer ledgerEntry) : mLedgerEntry(ledgerEntry), mValid(false)
|
||||
{
|
||||
if (!mLedgerEntry) return;
|
||||
if (mLedgerEntry->getType()!=ltACCOUNT_ROOT) return;
|
||||
mAccountID = mLedgerEntry->getValueFieldAccount(sfAccount);
|
||||
if (mAccountID.IsValid()) mValid = true;
|
||||
}
|
||||
|
||||
void AccountState::addJson(Json::Value& val)
|
||||
{
|
||||
Json::Value as(Json::objectValue);
|
||||
|
||||
as["AccountID"]=mAccountID.humanAccountID();
|
||||
as["Balance"]=boost::lexical_cast<std::string>(mBalance);
|
||||
as["SendSequence"]=mAccountSeq;
|
||||
if(!mValid) as["Invalid"]=true;
|
||||
|
||||
val[mAccountID.humanAccountID()]=as;
|
||||
val = mLedgerEntry->getJson(0);
|
||||
if(!mValid) val["Invalid"]=true;
|
||||
}
|
||||
// vim:ts=4
|
||||
|
||||
Reference in New Issue
Block a user