mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add ledger fuctionality for NicknameState.
This commit is contained in:
@@ -153,6 +153,21 @@ AccountState::pointer Ledger::getAccountState(const NewcoinAddress& accountID)
|
||||
return boost::make_shared<AccountState>(sle);
|
||||
}
|
||||
|
||||
NicknameState::pointer Ledger::getNicknameState(const uint256& uNickname)
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
SHAMapItem::pointer item = mAccountStateMap->peekItem(Ledger::getNicknameIndex(uNickname));
|
||||
if (!item)
|
||||
{
|
||||
return NicknameState::pointer();
|
||||
}
|
||||
|
||||
SerializedLedgerEntry::pointer sle =
|
||||
boost::make_shared<SerializedLedgerEntry>(item->peekSerializer(), item->getTag());
|
||||
if (sle->getType() != ltNICKNAME) return NicknameState::pointer();
|
||||
return boost::make_shared<NicknameState>(sle);
|
||||
}
|
||||
|
||||
RippleState::pointer Ledger::getRippleState(const uint256& uNode)
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
|
||||
48
src/Ledger.h
48
src/Ledger.h
@@ -13,6 +13,7 @@
|
||||
#include "Transaction.h"
|
||||
#include "AccountState.h"
|
||||
#include "RippleState.h"
|
||||
#include "NicknameState.h"
|
||||
#include "types.h"
|
||||
#include "BitcoinUtil.h"
|
||||
#include "SHAMap.h"
|
||||
@@ -137,8 +138,6 @@ public:
|
||||
LedgerStateParms writeBack(LedgerStateParms parms, SLE::pointer);
|
||||
SLE::pointer getAccountRoot(LedgerStateParms& parms, const uint160& accountID);
|
||||
SLE::pointer getAccountRoot(LedgerStateParms& parms, const NewcoinAddress& naAccountID);
|
||||
SLE::pointer getNickname(LedgerStateParms& parms, const std::string& nickname);
|
||||
SLE::pointer getNickname(LedgerStateParms& parms, const uint256& nickHash);
|
||||
|
||||
// database functions
|
||||
static void saveAcceptedLedger(Ledger::pointer);
|
||||
@@ -160,25 +159,21 @@ public:
|
||||
static uint256 getGeneratorIndex(const uint160& uGeneratorID);
|
||||
|
||||
//
|
||||
// Ripple functions
|
||||
// Nickname functions
|
||||
//
|
||||
|
||||
static uint256 getRippleStateIndex(const NewcoinAddress& naA, const NewcoinAddress& naB, const uint160& uCurrency);
|
||||
static uint256 getRippleStateIndex(const uint160& uiA, const uint160& uiB, const uint160& uCurrency)
|
||||
{ return getRippleStateIndex(NewcoinAddress::createAccountID(uiA), NewcoinAddress::createAccountID(uiB), uCurrency); }
|
||||
uint256 getNicknameHash(const std::string& strNickname)
|
||||
{ Serializer s(strNickname); return s.getSHA256(); }
|
||||
|
||||
static uint256 getRippleStateIndex(const NewcoinAddress& naA, const NewcoinAddress& naB)
|
||||
{ return getRippleStateIndex(naA, naB, uint160()); }
|
||||
static uint256 getRippleDirIndex(const uint160& uAccountID);
|
||||
NicknameState::pointer getNicknameState(const uint256& uNickname);
|
||||
NicknameState::pointer getNicknameState(const std::string& strNickname)
|
||||
{ return getNicknameState(getNicknameHash(strNickname)); }
|
||||
|
||||
RippleState::pointer getRippleState(const uint256& uNode);
|
||||
SLE::pointer getRippleState(LedgerStateParms& parms, const uint256& uNode);
|
||||
SLE::pointer getNickname(LedgerStateParms& parms, const uint256& uNickname);
|
||||
SLE::pointer getNickname(LedgerStateParms& parms, const std::string& strNickname)
|
||||
{ return getNickname(parms, getNicknameHash(strNickname)); }
|
||||
|
||||
SLE::pointer getRippleState(LedgerStateParms& parms, const NewcoinAddress& naA, const NewcoinAddress& naB, const uint160& uCurrency)
|
||||
{ return getRippleState(parms, getRippleStateIndex(naA, naB, uCurrency)); }
|
||||
|
||||
SLE::pointer getRippleState(LedgerStateParms& parms, const uint160& uiA, const uint160& uiB, const uint160& uCurrency)
|
||||
{ return getRippleState(parms, getRippleStateIndex(NewcoinAddress::createAccountID(uiA), NewcoinAddress::createAccountID(uiB), uCurrency)); }
|
||||
static uint256 getNicknameIndex(const uint256& uNickname);
|
||||
|
||||
//
|
||||
// Offer functions
|
||||
@@ -200,6 +195,27 @@ public:
|
||||
SLE::pointer getDirRoot(LedgerStateParms& parms, const uint256& uRootIndex);
|
||||
SLE::pointer getDirNode(LedgerStateParms& parms, const uint256& uNodeIndex);
|
||||
|
||||
//
|
||||
// Ripple functions
|
||||
//
|
||||
|
||||
static uint256 getRippleStateIndex(const NewcoinAddress& naA, const NewcoinAddress& naB, const uint160& uCurrency);
|
||||
static uint256 getRippleStateIndex(const uint160& uiA, const uint160& uiB, const uint160& uCurrency)
|
||||
{ return getRippleStateIndex(NewcoinAddress::createAccountID(uiA), NewcoinAddress::createAccountID(uiB), uCurrency); }
|
||||
|
||||
static uint256 getRippleStateIndex(const NewcoinAddress& naA, const NewcoinAddress& naB)
|
||||
{ return getRippleStateIndex(naA, naB, uint160()); }
|
||||
static uint256 getRippleDirIndex(const uint160& uAccountID);
|
||||
|
||||
RippleState::pointer getRippleState(const uint256& uNode);
|
||||
SLE::pointer getRippleState(LedgerStateParms& parms, const uint256& uNode);
|
||||
|
||||
SLE::pointer getRippleState(LedgerStateParms& parms, const NewcoinAddress& naA, const NewcoinAddress& naB, const uint160& uCurrency)
|
||||
{ return getRippleState(parms, getRippleStateIndex(naA, naB, uCurrency)); }
|
||||
|
||||
SLE::pointer getRippleState(LedgerStateParms& parms, const uint160& uiA, const uint160& uiB, const uint160& uCurrency)
|
||||
{ return getRippleState(parms, getRippleStateIndex(NewcoinAddress::createAccountID(uiA), NewcoinAddress::createAccountID(uiB), uCurrency)); }
|
||||
|
||||
//
|
||||
// Misc
|
||||
//
|
||||
|
||||
@@ -11,6 +11,29 @@ uint256 Ledger::getAccountRootIndex(const uint160& uAccountID)
|
||||
return s.getSHA512Half();
|
||||
}
|
||||
|
||||
// What is important:
|
||||
// --> uNickname: is a Sha256
|
||||
// <-- SHA512/2: for consistency and speed in generating indexes.
|
||||
uint256 Ledger::getNicknameIndex(const uint256& uNickname)
|
||||
{
|
||||
Serializer s;
|
||||
|
||||
s.add16(spaceNickname);
|
||||
s.add256(uNickname);
|
||||
|
||||
return s.getSHA512Half();
|
||||
}
|
||||
|
||||
uint256 Ledger::getGeneratorIndex(const uint160& uGeneratorID)
|
||||
{
|
||||
Serializer s;
|
||||
|
||||
s.add16(spaceGenerator);
|
||||
s.add160(uGeneratorID);
|
||||
|
||||
return s.getSHA512Half();
|
||||
}
|
||||
|
||||
uint256 Ledger::getRippleStateIndex(const NewcoinAddress& naA, const NewcoinAddress& naB, const uint160& uCurrency)
|
||||
{
|
||||
uint160 uAID = naA.getAccountID();
|
||||
@@ -36,16 +59,6 @@ uint256 Ledger::getRippleDirIndex(const uint160& uAccountID)
|
||||
return s.getSHA512Half();
|
||||
}
|
||||
|
||||
uint256 Ledger::getGeneratorIndex(const uint160& uGeneratorID)
|
||||
{
|
||||
Serializer s;
|
||||
|
||||
s.add16(spaceGenerator);
|
||||
s.add160(uGeneratorID);
|
||||
|
||||
return s.getSHA512Half();
|
||||
}
|
||||
|
||||
uint160 Ledger::getOfferBase(const uint160& currencyIn, const uint160& accountIn,
|
||||
const uint160& currencyOut, const uint160& accountOut)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "utils.h"
|
||||
#include "Log.h"
|
||||
|
||||
LedgerStateParms Ledger::writeBack(LedgerStateParms parms, SerializedLedgerEntry::pointer entry)
|
||||
LedgerStateParms Ledger::writeBack(LedgerStateParms parms, SLE::pointer entry)
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
bool create = false;
|
||||
@@ -43,7 +43,7 @@ LedgerStateParms Ledger::writeBack(LedgerStateParms parms, SerializedLedgerEntry
|
||||
return lepOKAY;
|
||||
}
|
||||
|
||||
SerializedLedgerEntry::pointer Ledger::getASNode(LedgerStateParms& parms, const uint256& nodeID,
|
||||
SLE::pointer Ledger::getASNode(LedgerStateParms& parms, const uint256& nodeID,
|
||||
LedgerEntryType let )
|
||||
{
|
||||
SHAMapItem::pointer account = mAccountStateMap->peekItem(nodeID);
|
||||
@@ -53,23 +53,23 @@ SerializedLedgerEntry::pointer Ledger::getASNode(LedgerStateParms& parms, const
|
||||
if ( (parms & lepCREATE) == 0 )
|
||||
{
|
||||
parms = lepMISSING;
|
||||
return SerializedLedgerEntry::pointer();
|
||||
return SLE::pointer();
|
||||
}
|
||||
|
||||
parms = parms | lepCREATED | lepOKAY;
|
||||
SerializedLedgerEntry::pointer sle=boost::make_shared<SerializedLedgerEntry>(let);
|
||||
SLE::pointer sle=boost::make_shared<SLE>(let);
|
||||
sle->setIndex(nodeID);
|
||||
|
||||
return sle;
|
||||
}
|
||||
|
||||
SerializedLedgerEntry::pointer sle =
|
||||
boost::make_shared<SerializedLedgerEntry>(account->peekSerializer(), nodeID);
|
||||
SLE::pointer sle =
|
||||
boost::make_shared<SLE>(account->peekSerializer(), nodeID);
|
||||
|
||||
if(sle->getType() != let)
|
||||
{ // maybe it's a currency or something
|
||||
parms = parms | lepWRONGTYPE;
|
||||
return SerializedLedgerEntry::pointer();
|
||||
return SLE::pointer();
|
||||
}
|
||||
|
||||
parms = parms | lepOKAY;
|
||||
@@ -78,56 +78,45 @@ SerializedLedgerEntry::pointer Ledger::getASNode(LedgerStateParms& parms, const
|
||||
|
||||
}
|
||||
|
||||
SerializedLedgerEntry::pointer Ledger::getAccountRoot(LedgerStateParms& parms, const uint160& accountID)
|
||||
SLE::pointer Ledger::getAccountRoot(LedgerStateParms& parms, const uint160& accountID)
|
||||
{
|
||||
uint256 nodeID=getAccountRootIndex(accountID);
|
||||
|
||||
return getASNode(parms, nodeID, ltACCOUNT_ROOT);
|
||||
}
|
||||
|
||||
SerializedLedgerEntry::pointer Ledger::getAccountRoot(LedgerStateParms& parms, const NewcoinAddress& naAccountID)
|
||||
SLE::pointer Ledger::getAccountRoot(LedgerStateParms& parms, const NewcoinAddress& naAccountID)
|
||||
{
|
||||
return getAccountRoot(parms, naAccountID.getAccountID());
|
||||
}
|
||||
|
||||
SerializedLedgerEntry::pointer Ledger::getNickname(LedgerStateParms& parms, const std::string& nickname)
|
||||
{
|
||||
return getNickname(parms, Serializer::getSHA512Half(nickname));
|
||||
}
|
||||
|
||||
SerializedLedgerEntry::pointer Ledger::getNickname(LedgerStateParms& parms, const uint256& nickHash)
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
|
||||
return getASNode(parms, nickHash, ltNICKNAME);
|
||||
}
|
||||
|
||||
//
|
||||
// Generator Map
|
||||
//
|
||||
|
||||
SerializedLedgerEntry::pointer Ledger::getGenerator(LedgerStateParms& parms, const uint160& uGeneratorID)
|
||||
SLE::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();
|
||||
}
|
||||
return getASNode(parms, getGeneratorIndex(uGeneratorID), ltGENERATOR_MAP);
|
||||
}
|
||||
|
||||
//
|
||||
// Nickname
|
||||
//
|
||||
|
||||
SLE::pointer Ledger::getNickname(LedgerStateParms& parms, const uint256& uNickname)
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
|
||||
return getASNode(parms, uNickname, ltNICKNAME);
|
||||
}
|
||||
|
||||
//
|
||||
// Ripple State
|
||||
//
|
||||
|
||||
SerializedLedgerEntry::pointer Ledger::getRippleState(LedgerStateParms& parms, const uint256& uNode)
|
||||
SLE::pointer Ledger::getRippleState(LedgerStateParms& parms, const uint256& uNode)
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
|
||||
@@ -152,14 +141,14 @@ uint256 Ledger::getDirIndex(const uint256& uBase, const uint64 uNodeDir)
|
||||
return uNode;
|
||||
}
|
||||
|
||||
SerializedLedgerEntry::pointer Ledger::getDirRoot(LedgerStateParms& parms, const uint256& uRootIndex)
|
||||
SLE::pointer Ledger::getDirRoot(LedgerStateParms& parms, const uint256& uRootIndex)
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
|
||||
return getASNode(parms, uRootIndex, ltDIR_ROOT);
|
||||
}
|
||||
|
||||
SerializedLedgerEntry::pointer Ledger::getDirNode(LedgerStateParms& parms, const uint256& uNodeIndex)
|
||||
SLE::pointer Ledger::getDirNode(LedgerStateParms& parms, const uint256& uNodeIndex)
|
||||
{
|
||||
ScopedLock l(mAccountStateMap->Lock());
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
//
|
||||
// A ripple line's state.
|
||||
// - Isolate ledger entry format.
|
||||
//
|
||||
|
||||
#include "SerializedLedger.h"
|
||||
|
||||
Reference in New Issue
Block a user