mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Some enhancements to this coded needed for the sync code to work.
This commit is contained in:
41
Ledger.cpp
41
Ledger.cpp
@@ -12,12 +12,14 @@
|
||||
#include "Conversion.h"
|
||||
#include "BitcoinUtil.h"
|
||||
#include "Wallet.h"
|
||||
#include "BinaryFormats.h"
|
||||
|
||||
Ledger::Ledger(const uint160& masterID, uint64 startAmount) :
|
||||
mFeeHeld(0), mTimeStamp(0), mLedgerSeq(0), mClosed(false), mValidHash(false), mAccepted(false)
|
||||
mFeeHeld(0), mTimeStamp(0), mLedgerSeq(0),
|
||||
mClosed(false), mValidHash(false), mAccepted(false), mImmutable(false)
|
||||
{
|
||||
mTransactionMap=SHAMap::pointer(new SHAMap());
|
||||
mAccountStateMap=SHAMap::pointer(new SHAMap());
|
||||
mAccountStateMap=SHAMap::pointer(new SHAMap(0));
|
||||
|
||||
AccountState::pointer startAccount=AccountState::pointer(new AccountState(masterID));
|
||||
startAccount->credit(startAmount);
|
||||
@@ -29,25 +31,48 @@ Ledger::Ledger(const uint256 &parentHash, const uint256 &transHash, const uint25
|
||||
uint64 feeHeld, uint64 timeStamp, uint32 ledgerSeq)
|
||||
: mParentHash(parentHash), mTransHash(transHash), mAccountHash(accountHash),
|
||||
mFeeHeld(feeHeld), mTimeStamp(timeStamp), mLedgerSeq(ledgerSeq),
|
||||
mClosed(false), mValidHash(false), mAccepted(false)
|
||||
mClosed(false), mValidHash(false), mAccepted(false), mImmutable(false)
|
||||
{
|
||||
updateHash();
|
||||
}
|
||||
|
||||
Ledger::Ledger(Ledger &prevLedger, uint64 ts) : mTimeStamp(ts),
|
||||
mClosed(false), mValidHash(false), mAccepted(false),
|
||||
mClosed(false), mValidHash(false), mAccepted(false), mImmutable(false),
|
||||
mTransactionMap(new SHAMap()), mAccountStateMap(prevLedger.mAccountStateMap)
|
||||
{
|
||||
mParentHash=prevLedger.getHash();
|
||||
mLedgerSeq=prevLedger.mLedgerSeq+1;
|
||||
mAccountStateMap->setSeq(mLedgerSeq);
|
||||
}
|
||||
|
||||
Ledger::Ledger(const std::vector<unsigned char>& rawLedger) : mFeeHeld(0), mTimeStamp(0),
|
||||
mLedgerSeq(0), mClosed(false), mValidHash(false), mAccepted(false), mImmutable(true)
|
||||
{
|
||||
Serializer s(rawLedger);
|
||||
// 32seq, 64fee, 256phash, 256thash, 256ahash, 64ts
|
||||
if(!s.get32(mLedgerSeq, BLgPIndex)) return;
|
||||
if(!s.get64(mFeeHeld, BLgPFeeHeld)) return;
|
||||
if(!s.get256(mParentHash, BLgPPrevLg)) return;
|
||||
if(!s.get256(mTransHash, BLgPTxT)) return;
|
||||
if(!s.get256(mAccountHash, BLgPAcT)) return;
|
||||
if(!s.get64(mTimeStamp, BLgPClTs)) return;
|
||||
updateHash();
|
||||
if(mValidHash)
|
||||
{
|
||||
mTransactionMap=SHAMap::pointer(new SHAMap());
|
||||
mAccountStateMap=SHAMap::pointer(new SHAMap(mLedgerSeq));
|
||||
}
|
||||
}
|
||||
|
||||
void Ledger::updateHash()
|
||||
{
|
||||
if(mTransactionMap) mTransHash=mTransactionMap->getHash();
|
||||
else mTransHash=0;
|
||||
if(mAccountStateMap) mAccountHash=mAccountStateMap->getHash();
|
||||
else mAccountHash=0;
|
||||
if(!mImmutable)
|
||||
{
|
||||
if(mTransactionMap) mTransHash=mTransactionMap->getHash();
|
||||
else mTransHash=0;
|
||||
if(mAccountStateMap) mAccountHash=mAccountStateMap->getHash();
|
||||
else mAccountHash=0;
|
||||
}
|
||||
|
||||
Serializer s(116);
|
||||
addRaw(s);
|
||||
|
||||
3
Ledger.h
3
Ledger.h
@@ -42,7 +42,7 @@ private:
|
||||
uint256 mHash, mParentHash, mTransHash, mAccountHash;
|
||||
uint64 mFeeHeld, mTimeStamp;
|
||||
uint32 mLedgerSeq;
|
||||
bool mClosed, mValidHash, mAccepted;
|
||||
bool mClosed, mValidHash, mAccepted, mImmutable;
|
||||
|
||||
SHAMap::pointer mTransactionMap, mAccountStateMap;
|
||||
|
||||
@@ -66,6 +66,7 @@ public:
|
||||
Ledger(const uint160& masterID, uint64 startAmount); // used for the starting bootstrap ledger
|
||||
Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash,
|
||||
uint64 feeHeld, uint64 timeStamp, uint32 ledgerSeq); // used for received ledgers
|
||||
Ledger(const std::vector<unsigned char>& rawLedger);
|
||||
|
||||
void setClosed() { mClosed=true; }
|
||||
void setAccepted() { mAccepted=true; }
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
SHAMap::SHAMap() : mSeq(0)
|
||||
SHAMap::SHAMap(uint32 seq) : mSeq(seq)
|
||||
{
|
||||
root=SHAMapInnerNode::pointer(new SHAMapInnerNode(SHAMapNode(SHAMapNode::rootDepth, uint256()), mSeq));
|
||||
mInnerNodeByID[*root]=root;
|
||||
|
||||
5
SHAMap.h
5
SHAMap.h
@@ -238,7 +238,7 @@ protected:
|
||||
public:
|
||||
|
||||
// build new map
|
||||
SHAMap();
|
||||
SHAMap(uint32 seq=0);
|
||||
|
||||
// hold the map stable across operations
|
||||
ScopedLock Lock() const { return ScopedLock(mLock); }
|
||||
@@ -294,6 +294,9 @@ public:
|
||||
|
||||
int flushDirty(int maxNodes, HashedObjectType t, uint32 seq);
|
||||
|
||||
void setSeq(uint32 seq) { mSeq=seq; }
|
||||
uint32 getSeq() { return mSeq; }
|
||||
|
||||
// overloads for backed maps
|
||||
bool fetchNode(const uint256& hash, std::vector<unsigned char>& rawNode);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user