From d761f4c4513d5b28f0bfd2a99910b87a7ad49af4 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sat, 12 May 2012 18:29:46 -0700 Subject: [PATCH] Add support for generator map ledger entries. --- src/Ledger.h | 17 ++++++++++++++++- src/LedgerFormats.cpp | 31 ++++++++++++++++--------------- src/LedgerIndex.cpp | 7 ------- src/LedgerNode.cpp | 22 ++++++++++++++++++++++ 4 files changed, 54 insertions(+), 23 deletions(-) diff --git a/src/Ledger.h b/src/Ledger.h index d64577a64..4d9b5fb61 100644 --- a/src/Ledger.h +++ b/src/Ledger.h @@ -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()); } diff --git a/src/LedgerFormats.cpp b/src/LedgerFormats.cpp index bdb3c9893..9dad266a6 100644 --- a/src/LedgerFormats.cpp +++ b/src/LedgerFormats.cpp @@ -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 diff --git a/src/LedgerIndex.cpp b/src/LedgerIndex.cpp index 9bd356531..97d74a230 100644 --- a/src/LedgerIndex.cpp +++ b/src/LedgerIndex.cpp @@ -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); diff --git a/src/LedgerNode.cpp b/src/LedgerNode.cpp index 77d4ed43a..29b659649 100644 --- a/src/LedgerNode.cpp +++ b/src/LedgerNode.cpp @@ -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