From 9462cd6718a8fd74ec76dfc05adea0cfaf1e711a Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 23 Nov 2011 12:48:45 -0800 Subject: [PATCH] Account state conversion from ledger to structure forms. --- AccountState.cpp | 21 +++++++++++++++++++++ AccountState.h | 8 ++++++++ 2 files changed, 29 insertions(+) create mode 100644 AccountState.cpp diff --git a/AccountState.cpp b/AccountState.cpp new file mode 100644 index 0000000000..2cd851a941 --- /dev/null +++ b/AccountState.cpp @@ -0,0 +1,21 @@ +#include "AccountState.h" +#include "Serializer.h" + +AccountState::AccountState(const std::vector& v) +{ + Serializer s(v); + mValid=false; + if(!s.get160(mAccountID, 0)) return; + if(!s.get64(mBalance, 20)) return; + if(!s.get32(mAccountSeq, 28)) return; + mValid=true; +} + +std::vector AccountState::getRaw() const +{ // 20-byte acct ID, 8-byte balance, 4-byte sequence + Serializer s(32); + s.add160(mAccountID); + s.add64(mBalance); + s.add32(mAccountSeq); + return s.getData(); +} diff --git a/AccountState.h b/AccountState.h index 615fe5847f..c3958cff0e 100644 --- a/AccountState.h +++ b/AccountState.h @@ -2,6 +2,12 @@ #define __ACCOUNTSTATE__ // An account's state in one or more accepted ledgers + +#include + +#include "boost/shared_ptr.hpp" + +#include "types.h" #include "uint256.h" class AccountState @@ -26,6 +32,8 @@ public: bool charge(uint64 a) { mBalance+=a; } bool credit(uint64 a) { mBalance-=a; } void incSeq(void) { mAccountSeq++; } + + std::vector getRaw() const; }; #endif