Add support for generator map ledger entries.

This commit is contained in:
Arthur Britto
2012-05-12 18:29:46 -07:00
parent 0e898e3d6a
commit d761f4c451
4 changed files with 54 additions and 23 deletions

View File

@@ -140,10 +140,25 @@ public:
static Ledger::pointer loadByHash(const uint256& ledgerHash);
// index calculation functions
static uint256 getAccountRootIndex(const uint160& account);
static uint256 getAccountRootIndex(const uint160& account)
{ return uint160extend256(account); } // Index is accountID extended to 256 bits
static uint256 getAccountRootIndex(const NewcoinAddress& account)
{ return getAccountRootIndex(account.getAccountID()); }
//
// Generator Map functions
//
SerializedLedgerEntry::pointer getGenerator(LedgerStateParms& parms, const uint160& uGeneratorID);
static uint256 getGeneratorIndex(const uint160& uGeneratorID)
{ return uint160extend256(uGeneratorID); } // Index is the generator ID extended to 256 bits
//
// Ripple functions
//
static uint256 getRippleIndex(const uint160& account, const uint160& extendTo, const uint160& currency);
static uint256 getRippleIndex(const uint160& account, const uint160& extendTo)
{ return getRippleIndex(account, extendTo, uint160()); }

View File

@@ -19,21 +19,6 @@ LedgerEntryFormat LedgerFormats[]=
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x01000000 },
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
},
{ "RippleState", ltRIPPLE_STATE, {
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
{ S_FIELD(Borrower), STI_ACCOUNT, SOE_REQUIRED, 0 },
{ S_FIELD(Lender), STI_ACCOUNT, SOE_REQUIRED, 0 },
{ S_FIELD(Currency), STI_HASH160, SOE_IFFLAG, 1 },
{ S_FIELD(Limit), STI_AMOUNT, SOE_REQUIRED, 0 },
{ S_FIELD(Balance), STI_AMOUNT, SOE_REQUIRED, 0 },
{ S_FIELD(CurrentRate), STI_UINT32, SOE_IFFLAG, 2 },
{ S_FIELD(RateLock), STI_UINT32, SOE_IFFLAG, 4 },
{ S_FIELD(NextRate), STI_UINT32, SOE_IFFLAG, 8 },
{ S_FIELD(NextRateLgr), STI_UINT32, SOE_IFFLAG, 8 },
{ S_FIELD(NextRateExp), STI_UINT32, SOE_IFFLAG, 16 },
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x01000000 },
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
},
{ "GeneratorMap", ltGENERATOR_MAP, {
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
{ S_FIELD(GeneratorID), STI_ACCOUNT, SOE_REQUIRED, 0 },
@@ -50,6 +35,21 @@ LedgerEntryFormat LedgerFormats[]=
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x01000000 },
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
},
{ "RippleState", ltRIPPLE_STATE, {
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
{ S_FIELD(Borrower), STI_ACCOUNT, SOE_REQUIRED, 0 },
{ S_FIELD(Lender), STI_ACCOUNT, SOE_REQUIRED, 0 },
{ S_FIELD(Currency), STI_HASH160, SOE_IFFLAG, 1 },
{ S_FIELD(Limit), STI_AMOUNT, SOE_REQUIRED, 0 },
{ S_FIELD(Balance), STI_AMOUNT, SOE_REQUIRED, 0 },
{ S_FIELD(CurrentRate), STI_UINT32, SOE_IFFLAG, 2 },
{ S_FIELD(RateLock), STI_UINT32, SOE_IFFLAG, 4 },
{ S_FIELD(NextRate), STI_UINT32, SOE_IFFLAG, 8 },
{ S_FIELD(NextRateLgr), STI_UINT32, SOE_IFFLAG, 8 },
{ S_FIELD(NextRateExp), STI_UINT32, SOE_IFFLAG, 16 },
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x01000000 },
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
},
{ NULL, ltINVALID }
};
@@ -63,3 +63,4 @@ LedgerEntryFormat* getLgrFormat(LedgerEntryType t)
}
return NULL;
}
// vim:ts=4

View File

@@ -1,13 +1,6 @@
#include "Ledger.h"
uint256 Ledger::getAccountRootIndex(const uint160& accountID)
{ // Index is accountID extended to 256 bits
uint256 index;
memcpy(index.begin() + (index.size() - accountID.size()), accountID.begin(), accountID.size());
return index;
}
uint256 Ledger::getRippleIndex(const uint160& accountID, const uint160& extendTo, const uint160& currency)
{ // Index is 160-bit account credit extended to, 96-bit XOR of extending account and currency
uint256 base=getAccountRootIndex(extendTo);

View File

@@ -109,4 +109,26 @@ SerializedLedgerEntry::pointer Ledger::getNickname(LedgerStateParms& parms, cons
return SerializedLedgerEntry::pointer();
}
}
//
// Generator Map
//
SerializedLedgerEntry::pointer Ledger::getGenerator(LedgerStateParms& parms, const uint160& uGeneratorID)
{
uint256 nodeID=getGeneratorIndex(uGeneratorID);
ScopedLock l(mAccountStateMap->Lock());
try
{
return getASNode(parms, nodeID, ltGENERATOR_MAP);
}
catch (...)
{
parms = lepERROR;
return SerializedLedgerEntry::pointer();
}
}
// vim:ts=4