mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Account state conversion from ledger to structure forms.
This commit is contained in:
21
AccountState.cpp
Normal file
21
AccountState.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "AccountState.h"
|
||||
#include "Serializer.h"
|
||||
|
||||
AccountState::AccountState(const std::vector<unsigned char>& 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<unsigned char> 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();
|
||||
}
|
||||
@@ -2,6 +2,12 @@
|
||||
#define __ACCOUNTSTATE__
|
||||
|
||||
// An account's state in one or more accepted ledgers
|
||||
|
||||
#include <vector>
|
||||
|
||||
#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<unsigned char> getRaw() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user