mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 22:45:52 +00:00
Refactor Serializer and SerializerIterator interfaces:
* Remove unused members * SerialIter holds only a pointer and offset now * Use free functions for some Serializer members * Use SerialIter in some places instead of Serializer
This commit is contained in:
committed by
Nik Bougalis
parent
a691632995
commit
bb4127a6fb
@@ -1775,8 +1775,6 @@
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\basics\ByteOrder.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\basics\byte_view.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\basics\CheckLibraryVersions.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\basics\CountedObject.h">
|
||||
|
||||
@@ -2652,9 +2652,6 @@
|
||||
<ClInclude Include="..\..\src\ripple\basics\ByteOrder.h">
|
||||
<Filter>ripple\basics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\basics\byte_view.h">
|
||||
<Filter>ripple\basics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\basics\CheckLibraryVersions.h">
|
||||
<Filter>ripple\basics</Filter>
|
||||
</ClInclude>
|
||||
|
||||
@@ -1145,7 +1145,7 @@ private:
|
||||
WriteLog (lsDEBUG, LedgerConsensus)
|
||||
<< "Test applying disputed transaction that did"
|
||||
<< " not get in";
|
||||
SerializerIterator sit (it.second->peekTransaction ());
|
||||
SerialIter sit (it.second->peekTransaction ());
|
||||
STTx::pointer txn
|
||||
= std::make_shared<STTx>(sit);
|
||||
|
||||
@@ -2091,7 +2091,7 @@ void applyTransactions (SHAMap::ref set, Ledger::ref applyLedger,
|
||||
"Processing candidate transaction: " << item->getTag ();
|
||||
try
|
||||
{
|
||||
SerializerIterator sit (item->peekSerializer ());
|
||||
SerialIter sit (item->peekSerializer ());
|
||||
STTx::pointer txn
|
||||
= std::make_shared<STTx>(sit);
|
||||
if (applyTransaction (engine, txn,
|
||||
|
||||
@@ -38,7 +38,7 @@ AcceptedLedger::AcceptedLedger (Ledger::ref ledger) : mLedger (ledger)
|
||||
for (SHAMapItem::pointer item = txSet.peekFirstItem (); item;
|
||||
item = txSet.peekNextItem (item->getTag ()))
|
||||
{
|
||||
SerializerIterator sit (item->peekSerializer ());
|
||||
SerialIter sit (item->peekSerializer ());
|
||||
insert (std::make_shared<AcceptedLedgerTx> (ledger, std::ref (sit)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
AcceptedLedgerTx::AcceptedLedgerTx (Ledger::ref ledger, SerializerIterator& sit)
|
||||
AcceptedLedgerTx::AcceptedLedgerTx (Ledger::ref ledger, SerialIter& sit)
|
||||
: mLedger (ledger)
|
||||
{
|
||||
Serializer txnSer (sit.getVL ());
|
||||
SerializerIterator txnIt (txnSer);
|
||||
SerialIter txnIt (txnSer);
|
||||
|
||||
mTxn = std::make_shared<STTx> (std::ref (txnIt));
|
||||
mRawMeta = sit.getVL ();
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
typedef const pointer& ref;
|
||||
|
||||
public:
|
||||
AcceptedLedgerTx (Ledger::ref ledger, SerializerIterator& sit);
|
||||
AcceptedLedgerTx (Ledger::ref ledger, SerialIter& sit);
|
||||
AcceptedLedgerTx (Ledger::ref ledger, STTx::ref,
|
||||
TransactionMetaSet::ref);
|
||||
AcceptedLedgerTx (Ledger::ref ledger, STTx::ref, TER result);
|
||||
|
||||
@@ -50,7 +50,7 @@ void ConsensusTransSetSF::gotNode (bool fromFilter, const SHAMapNodeID& id, uint
|
||||
try
|
||||
{
|
||||
Serializer s (nodeData.begin () + 4, nodeData.end ()); // skip prefix
|
||||
SerializerIterator sit (s);
|
||||
SerialIter sit (s);
|
||||
STTx::pointer stx = std::make_shared<STTx> (std::ref (sit));
|
||||
assert (stx->getTransactionID () == nodeHash);
|
||||
getApp().getJobQueue ().addJob (
|
||||
|
||||
@@ -334,7 +334,7 @@ void Ledger::updateHash ()
|
||||
|
||||
void Ledger::setRaw (Serializer& s, bool hasPrefix)
|
||||
{
|
||||
SerializerIterator sit (s);
|
||||
SerialIter sit (s);
|
||||
|
||||
if (hasPrefix)
|
||||
sit.get32 ();
|
||||
@@ -509,7 +509,7 @@ Transaction::pointer Ledger::getTransaction (uint256 const& transID) const
|
||||
STTx::pointer Ledger::getSTransaction (
|
||||
SHAMapItem::ref item, SHAMapTreeNode::TNType type)
|
||||
{
|
||||
SerializerIterator sit (item->peekSerializer ());
|
||||
SerialIter sit (item->peekSerializer ());
|
||||
|
||||
if (type == SHAMapTreeNode::tnTRANSACTION_NM)
|
||||
return std::make_shared<STTx> (sit);
|
||||
@@ -517,7 +517,7 @@ STTx::pointer Ledger::getSTransaction (
|
||||
if (type == SHAMapTreeNode::tnTRANSACTION_MD)
|
||||
{
|
||||
Serializer sTxn (sit.getVL ());
|
||||
SerializerIterator tSit (sTxn);
|
||||
SerialIter tSit (sTxn);
|
||||
return std::make_shared<STTx> (tSit);
|
||||
}
|
||||
|
||||
@@ -528,7 +528,7 @@ STTx::pointer Ledger::getSMTransaction (
|
||||
SHAMapItem::ref item, SHAMapTreeNode::TNType type,
|
||||
TransactionMetaSet::pointer& txMeta) const
|
||||
{
|
||||
SerializerIterator sit (item->peekSerializer ());
|
||||
SerialIter sit (item->peekSerializer ());
|
||||
|
||||
if (type == SHAMapTreeNode::tnTRANSACTION_NM)
|
||||
{
|
||||
@@ -538,7 +538,7 @@ STTx::pointer Ledger::getSMTransaction (
|
||||
else if (type == SHAMapTreeNode::tnTRANSACTION_MD)
|
||||
{
|
||||
Serializer sTxn (sit.getVL ());
|
||||
SerializerIterator tSit (sTxn);
|
||||
SerialIter tSit (sTxn);
|
||||
|
||||
txMeta = std::make_shared<TransactionMetaSet> (
|
||||
item->getTag (), mLedgerSeq, sit.getVL ());
|
||||
@@ -574,7 +574,7 @@ bool Ledger::getTransaction (
|
||||
else if (type == SHAMapTreeNode::tnTRANSACTION_MD)
|
||||
{
|
||||
// in tree with metadata
|
||||
SerializerIterator it (item->peekSerializer ());
|
||||
SerialIter it (item->peekSerializer ());
|
||||
txn = getApp().getMasterTransaction ().fetch (txID, false);
|
||||
|
||||
if (!txn)
|
||||
@@ -607,7 +607,7 @@ bool Ledger::getTransactionMeta (
|
||||
if (type != SHAMapTreeNode::tnTRANSACTION_MD)
|
||||
return false;
|
||||
|
||||
SerializerIterator it (item->peekSerializer ());
|
||||
SerialIter it (item->peekSerializer ());
|
||||
it.getVL (); // skip transaction
|
||||
meta = std::make_shared<TransactionMetaSet> (txID, mLedgerSeq, it.getVL ());
|
||||
|
||||
@@ -625,7 +625,7 @@ bool Ledger::getMetaHex (uint256 const& transID, std::string& hex) const
|
||||
if (type != SHAMapTreeNode::tnTRANSACTION_MD)
|
||||
return false;
|
||||
|
||||
SerializerIterator it (item->peekSerializer ());
|
||||
SerialIter it (item->peekSerializer ());
|
||||
it.getVL (); // skip transaction
|
||||
hex = strHex (it.getVL ());
|
||||
return true;
|
||||
|
||||
@@ -129,16 +129,16 @@ void fillJson (Object& json, LedgerFill const& fill)
|
||||
{
|
||||
if (type == SHAMapTreeNode::tnTRANSACTION_NM)
|
||||
{
|
||||
SerializerIterator sit (item->peekSerializer ());
|
||||
SerialIter sit (item->peekSerializer ());
|
||||
STTx txn (sit);
|
||||
txns.append (txn.getJson (0));
|
||||
}
|
||||
else if (type == SHAMapTreeNode::tnTRANSACTION_MD)
|
||||
{
|
||||
SerializerIterator sit (item->peekSerializer ());
|
||||
SerialIter sit (item->peekSerializer ());
|
||||
Serializer sTxn (sit.getVL ());
|
||||
|
||||
SerializerIterator tsit (sTxn);
|
||||
SerialIter tsit (sTxn);
|
||||
STTx txn (tsit);
|
||||
|
||||
TransactionMetaSet meta (
|
||||
|
||||
@@ -887,7 +887,7 @@ void NetworkOPsImp::submitTransaction (
|
||||
Serializer s;
|
||||
iTrans->add (s);
|
||||
|
||||
SerializerIterator sit (s);
|
||||
SerialIter sit (s);
|
||||
auto trans = std::make_shared<STTx> (std::ref (sit));
|
||||
|
||||
uint256 suppress = trans->getTransactionID ();
|
||||
@@ -3546,7 +3546,7 @@ bool NetworkOPsImp::getFetchPack (uint256 const& hash, Blob& data)
|
||||
|
||||
mFetchPack.del (hash, false);
|
||||
|
||||
if (hash != Serializer::getSHA512Half (data))
|
||||
if (hash != getSHA512Half (data))
|
||||
{
|
||||
m_journal.warning << "Bad entry in fetch pack";
|
||||
return false;
|
||||
|
||||
@@ -1244,7 +1244,7 @@ private:
|
||||
assert (bFound);
|
||||
(void) bFound;
|
||||
|
||||
uint256 iSha256 = Serializer::getSHA512Half (strSiteFile);
|
||||
uint256 iSha256 = getSHA512Half (strSiteFile);
|
||||
bool bChangedB = sdCurrent.iSha256 != iSha256;
|
||||
|
||||
sdCurrent.strDomain = strDomain;
|
||||
|
||||
134
src/ripple/app/transactors/AddWallet.cpp
Normal file
134
src/ripple/app/transactors/AddWallet.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/app/transactors/Transactor.h>
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <ripple/protocol/Indexes.h>
|
||||
#include <ripple/protocol/TxFlags.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
class AddWallet
|
||||
: public Transactor
|
||||
{
|
||||
public:
|
||||
AddWallet (
|
||||
STTx const& txn,
|
||||
TransactionEngineParams params,
|
||||
TransactionEngine* engine)
|
||||
: Transactor (
|
||||
txn,
|
||||
params,
|
||||
engine,
|
||||
deprecatedLogs().journal("AddWallet"))
|
||||
{
|
||||
}
|
||||
|
||||
TER doApply () override
|
||||
{
|
||||
std::uint32_t const uTxFlags = mTxn.getFlags ();
|
||||
|
||||
if (uTxFlags & tfUniversalMask)
|
||||
{
|
||||
m_journal.trace <<
|
||||
"Malformed transaction: Invalid flags set.";
|
||||
|
||||
return temINVALID_FLAG;
|
||||
}
|
||||
|
||||
Blob const vucPubKey = mTxn.getFieldVL (sfPublicKey);
|
||||
Blob const vucSignature = mTxn.getFieldVL (sfSignature);
|
||||
|
||||
auto const uAuthKeyID = mTxn.getFieldAccount160 (sfRegularKey);
|
||||
auto const naMasterPubKey =
|
||||
RippleAddress::createAccountPublic (vucPubKey);
|
||||
auto const uDstAccountID = naMasterPubKey.getAccountID ();
|
||||
|
||||
// FIXME: This should be moved to the transaction's signature check logic
|
||||
// and cached.
|
||||
if (!naMasterPubKey.accountPublicVerify (
|
||||
getSHA512Half (uAuthKeyID.begin (), uAuthKeyID.size ()),
|
||||
vucSignature, ECDSA::not_strict))
|
||||
{
|
||||
m_journal.trace <<
|
||||
"Unauthorized: bad signature ";
|
||||
return tefBAD_ADD_AUTH;
|
||||
}
|
||||
|
||||
SLE::pointer sleDst (mEngine->entryCache (
|
||||
ltACCOUNT_ROOT, getAccountRootIndex (uDstAccountID)));
|
||||
|
||||
if (sleDst)
|
||||
{
|
||||
m_journal.trace <<
|
||||
"account already created";
|
||||
return tefCREATED;
|
||||
}
|
||||
|
||||
// Direct XRP payment.
|
||||
|
||||
STAmount saDstAmount = mTxn.getFieldAmount (sfAmount);
|
||||
STAmount saPaid = mTxn.getTransactionFee ();
|
||||
STAmount const saSrcBalance = mTxnAccount->getFieldAmount (sfBalance);
|
||||
std::uint32_t const uOwnerCount = mTxnAccount->getFieldU32 (sfOwnerCount);
|
||||
std::uint64_t const uReserve = mEngine->getLedger ()->getReserve (uOwnerCount);
|
||||
|
||||
|
||||
// Make sure have enough reserve to send. Allow final spend to use reserve
|
||||
// for fee.
|
||||
// Note: Reserve is not scaled by fee.
|
||||
if (saSrcBalance + saPaid < saDstAmount + uReserve)
|
||||
{
|
||||
// Vote no. However, transaction might succeed, if applied in a
|
||||
// different order.
|
||||
m_journal.trace <<
|
||||
"Delay transaction: Insufficient funds: %s / %s (%d)" <<
|
||||
saSrcBalance.getText () << " / " <<
|
||||
(saDstAmount + uReserve).getText () << " with reserve = " <<
|
||||
uReserve;
|
||||
return tecUNFUNDED_ADD;
|
||||
}
|
||||
|
||||
// Deduct initial balance from source account.
|
||||
mTxnAccount->setFieldAmount (sfBalance, saSrcBalance - saDstAmount);
|
||||
|
||||
// Create the account.
|
||||
sleDst = mEngine->entryCreate (ltACCOUNT_ROOT,
|
||||
getAccountRootIndex (uDstAccountID));
|
||||
|
||||
sleDst->setFieldAccount (sfAccount, uDstAccountID);
|
||||
sleDst->setFieldU32 (sfSequence, 1);
|
||||
sleDst->setFieldAmount (sfBalance, saDstAmount);
|
||||
sleDst->setFieldAccount (sfRegularKey, uAuthKeyID);
|
||||
|
||||
return tesSUCCESS;
|
||||
}
|
||||
};
|
||||
|
||||
TER
|
||||
transact_AddWallet (
|
||||
STTx const& txn,
|
||||
TransactionEngineParams params,
|
||||
TransactionEngine* engine)
|
||||
{
|
||||
return AddWallet (txn, params, engine).apply ();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -56,7 +56,7 @@ Transaction::pointer Transaction::sharedTransaction (
|
||||
try
|
||||
{
|
||||
Serializer s (vucTransaction);
|
||||
SerializerIterator sit (s);
|
||||
SerialIter sit (s);
|
||||
|
||||
return std::make_shared<Transaction> (
|
||||
std::make_shared<STTx> (sit),
|
||||
@@ -111,7 +111,7 @@ Transaction::pointer Transaction::transactionFromSQL (
|
||||
|
||||
rawTxn.resize (txSize);
|
||||
|
||||
SerializerIterator it (rawTxn);
|
||||
SerialIter it (rawTxn);
|
||||
auto txn = std::make_shared<STTx> (it);
|
||||
auto tr = std::make_shared<Transaction> (txn, validate);
|
||||
|
||||
@@ -183,7 +183,7 @@ Transaction::pointer Transaction::transactionFromSQL (std::string const& sql)
|
||||
}
|
||||
rawTxn.resize (txSize);
|
||||
|
||||
SerializerIterator it (rawTxn);
|
||||
SerialIter it (rawTxn);
|
||||
auto txn = std::make_shared<STTx> (it);
|
||||
auto tr = std::make_shared<Transaction> (txn, Validate::YES);
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ TER TransactionEngine::applyTransaction (
|
||||
{
|
||||
Serializer ser;
|
||||
txn.add (ser);
|
||||
SerializerIterator sit (ser);
|
||||
SerialIter sit (ser);
|
||||
STTx s2 (sit);
|
||||
|
||||
if (!s2.isEquivalent (txn))
|
||||
|
||||
@@ -71,7 +71,7 @@ STTx::pointer TransactionMaster::fetch (SHAMapItem::ref item,
|
||||
|
||||
if (type == SHAMapTreeNode::tnTRANSACTION_NM)
|
||||
{
|
||||
SerializerIterator sit (item->peekSerializer ());
|
||||
SerialIter sit (item->peekSerializer ());
|
||||
txn = std::make_shared<STTx> (std::ref (sit));
|
||||
}
|
||||
else if (type == SHAMapTreeNode::tnTRANSACTION_MD)
|
||||
@@ -79,7 +79,7 @@ STTx::pointer TransactionMaster::fetch (SHAMapItem::ref item,
|
||||
Serializer s;
|
||||
int length;
|
||||
item->peekSerializer ().getVL (s.modData (), 0, length);
|
||||
SerializerIterator sit (s);
|
||||
SerialIter sit (s);
|
||||
|
||||
txn = std::make_shared<STTx> (std::ref (sit));
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ TransactionMetaSet::TransactionMetaSet (uint256 const& txid, std::uint32_t ledge
|
||||
mTransactionID (txid), mLedger (ledger), mNodes (sfAffectedNodes, 32)
|
||||
{
|
||||
Serializer s (vec);
|
||||
SerializerIterator sit (s);
|
||||
SerialIter sit (s);
|
||||
|
||||
std::unique_ptr<STBase> pobj = STObject::deserialize (sit, sfMetadata);
|
||||
STObject* obj = static_cast<STObject*> (pobj.get ());
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_BASICS_BYTE_VIEW_H_INCLUDED
|
||||
#define RIPPLE_BASICS_BYTE_VIEW_H_INCLUDED
|
||||
|
||||
#include <beast/container/buffer_view.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
// VFALCO DEPRECATED
|
||||
typedef beast::buffer_view <std::uint8_t> byte_view;
|
||||
typedef beast::buffer_view <std::uint8_t const> const_byte_view;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -326,7 +326,7 @@ public:
|
||||
std::move(data), hash);
|
||||
|
||||
#if RIPPLE_VERIFY_NODEOBJECT_KEYS
|
||||
assert (hash == Serializer::getSHA512Half (data));
|
||||
assert (hash == getSHA512Half (data));
|
||||
#endif
|
||||
|
||||
m_cache.canonicalize (hash, object, true);
|
||||
|
||||
@@ -991,11 +991,10 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMTransaction> const& m)
|
||||
return;
|
||||
}
|
||||
|
||||
Serializer s (m->rawtransaction ());
|
||||
SerialIter sit (m->rawtransaction ());
|
||||
|
||||
try
|
||||
{
|
||||
SerializerIterator sit (s);
|
||||
STTx::pointer stx = std::make_shared <
|
||||
STTx> (std::ref (sit));
|
||||
uint256 txID = stx->getTransactionID ();
|
||||
@@ -1049,7 +1048,7 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMTransaction> const& m)
|
||||
catch (...)
|
||||
{
|
||||
p_journal_.warning << "Transaction invalid: " <<
|
||||
s.getHex();
|
||||
strHex(m->rawtransaction ());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1314,7 +1313,7 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMValidation> const& m)
|
||||
try
|
||||
{
|
||||
Serializer s (m->validation ());
|
||||
SerializerIterator sit (s);
|
||||
SerialIter sit (s);
|
||||
STValidation::pointer val = std::make_shared <
|
||||
STValidation> (std::ref (sit), false);
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ makeSharedValue (SSL* ssl, beast::Journal journal)
|
||||
|
||||
// Finally, derive the actual cookie for the values that
|
||||
// we have calculated.
|
||||
result.first = Serializer::getSHA512Half (sha1, sizeof(sha1));
|
||||
result.first = getSHA512Half (sha1, sizeof(sha1));
|
||||
result.second = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
{
|
||||
;
|
||||
}
|
||||
static std::unique_ptr<STBase> deserialize (SerializerIterator& sit, SField::ref name)
|
||||
static std::unique_ptr<STBase> deserialize (SerialIter& sit, SField::ref name)
|
||||
{
|
||||
return std::unique_ptr<STBase> (construct (sit, name));
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
static STAccount* construct (SerializerIterator&, SField::ref);
|
||||
static STAccount* construct (SerialIter&, SField::ref);
|
||||
};
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -109,7 +109,7 @@ public:
|
||||
private:
|
||||
static
|
||||
std::unique_ptr<STAmount>
|
||||
construct (SerializerIterator&, SField::ref name);
|
||||
construct (SerialIter&, SField::ref name);
|
||||
|
||||
void
|
||||
setSNValue (std::int64_t);
|
||||
@@ -122,14 +122,14 @@ public:
|
||||
static
|
||||
std::unique_ptr <STBase>
|
||||
deserialize (
|
||||
SerializerIterator& sit, SField::ref name)
|
||||
SerialIter& sit, SField::ref name)
|
||||
{
|
||||
return construct (sit, name);
|
||||
}
|
||||
|
||||
static
|
||||
STAmount
|
||||
deserialize (SerializerIterator&);
|
||||
deserialize (SerialIter&);
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
@@ -74,7 +74,7 @@ public:
|
||||
|
||||
static
|
||||
std::unique_ptr<STBase>
|
||||
deserialize (SerializerIterator & sit, SField::ref name);
|
||||
deserialize (SerialIter & sit, SField::ref name);
|
||||
|
||||
const vector& getValue () const
|
||||
{
|
||||
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
|
||||
static
|
||||
std::unique_ptr<STBase>
|
||||
deserialize (SerializerIterator& sit, SField::ref name)
|
||||
deserialize (SerialIter& sit, SField::ref name)
|
||||
{
|
||||
return std::make_unique<STBitString> (name, sit.getBitString<Bits> ());
|
||||
}
|
||||
|
||||
@@ -44,11 +44,11 @@ public:
|
||||
: STBase (n)
|
||||
{ }
|
||||
|
||||
STBlob (SerializerIterator&, SField::ref name = sfGeneric);
|
||||
STBlob (SerialIter&, SField::ref name = sfGeneric);
|
||||
|
||||
static
|
||||
std::unique_ptr<STBase>
|
||||
deserialize (SerializerIterator& sit, SField::ref name)
|
||||
deserialize (SerialIter& sit, SField::ref name)
|
||||
{
|
||||
return std::make_unique<STBlob> (name, sit.getVL ());
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
|
||||
static
|
||||
std::unique_ptr<STBase>
|
||||
deserialize (SerializerIterator& sit, SField::ref name);
|
||||
deserialize (SerialIter& sit, SField::ref name);
|
||||
|
||||
SerializedTypeID
|
||||
getSType () const override;
|
||||
@@ -100,7 +100,7 @@ private:
|
||||
Integer value_;
|
||||
};
|
||||
|
||||
using STUInt8 = STInteger<unsigned char>;
|
||||
using STUInt8 = STInteger<unsigned char>;
|
||||
using STUInt16 = STInteger<std::uint16_t>;
|
||||
using STUInt32 = STInteger<std::uint32_t>;
|
||||
using STUInt64 = STInteger<std::uint64_t>;
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
|
||||
public:
|
||||
STLedgerEntry (const Serializer & s, uint256 const& index);
|
||||
STLedgerEntry (SerializerIterator & sit, uint256 const& index);
|
||||
STLedgerEntry (SerialIter & sit, uint256 const& index);
|
||||
STLedgerEntry (LedgerEntryType type, uint256 const& index);
|
||||
STLedgerEntry (const STObject & object, uint256 const& index);
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
}
|
||||
|
||||
STObject (
|
||||
const SOTemplate & type, SerializerIterator & sit, SField::ref name)
|
||||
const SOTemplate & type, SerialIter & sit, SField::ref name)
|
||||
: STBase (name)
|
||||
{
|
||||
set (sit);
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
virtual ~STObject () { }
|
||||
|
||||
static std::unique_ptr<STBase>
|
||||
deserialize (SerializerIterator & sit, SField::ref name);
|
||||
deserialize (SerialIter & sit, SField::ref name);
|
||||
|
||||
bool setType (const SOTemplate & type);
|
||||
bool isValidForType ();
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
}
|
||||
|
||||
void set (const SOTemplate&);
|
||||
bool set (SerializerIterator & u, int depth = 0);
|
||||
bool set (SerialIter& u, int depth = 0);
|
||||
|
||||
virtual SerializedTypeID getSType () const override
|
||||
{
|
||||
@@ -271,7 +271,7 @@ public:
|
||||
static std::unique_ptr<STBase> makeDeserializedObject (
|
||||
SerializedTypeID id,
|
||||
SField::ref name,
|
||||
SerializerIterator&,
|
||||
SerialIter&,
|
||||
int depth);
|
||||
|
||||
static std::unique_ptr<STBase>
|
||||
|
||||
@@ -239,7 +239,7 @@ public:
|
||||
|
||||
static
|
||||
std::unique_ptr<STBase>
|
||||
deserialize (SerializerIterator& sit, SField::ref name);
|
||||
deserialize (SerialIter& sit, SField::ref name);
|
||||
|
||||
std::unique_ptr<STBase>
|
||||
duplicate () const override
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
|
||||
STTx (STTx const& other) = default;
|
||||
|
||||
explicit STTx (SerializerIterator& sit);
|
||||
explicit STTx (SerialIter& sit);
|
||||
explicit STTx (TxType type);
|
||||
|
||||
// Only called from ripple::RPC::transactionSign - can we eliminate this?
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
};
|
||||
|
||||
// These throw if the object is not valid
|
||||
STValidation (SerializerIterator & sit, bool checkSignature = true);
|
||||
STValidation (SerialIter & sit, bool checkSignature = true);
|
||||
|
||||
// Does not sign the validation
|
||||
STValidation (uint256 const& ledgerHash, std::uint32_t signTime,
|
||||
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
|
||||
static
|
||||
std::unique_ptr<STBase>
|
||||
deserialize (SerializerIterator& sit, SField::ref name);
|
||||
deserialize (SerialIter& sit, SField::ref name);
|
||||
|
||||
Json::Value
|
||||
getJson (int) const override;
|
||||
@@ -159,7 +159,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<uint256> mValue;
|
||||
std::vector<uint256> mValue;
|
||||
};
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -20,11 +20,14 @@
|
||||
#ifndef RIPPLE_PROTOCOL_SERIALIZER_H_INCLUDED
|
||||
#define RIPPLE_PROTOCOL_SERIALIZER_H_INCLUDED
|
||||
|
||||
#include <ripple/basics/byte_view.h>
|
||||
#include <ripple/protocol/SField.h>
|
||||
#include <ripple/basics/base_uint.h>
|
||||
#include <beast/utility/noexcept.h>
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <beast/cxx14/type_traits.h> // <type_traits>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -32,10 +35,8 @@ class CKey; // forward declaration
|
||||
|
||||
class Serializer
|
||||
{
|
||||
public:
|
||||
typedef std::shared_ptr<Serializer> pointer;
|
||||
|
||||
protected:
|
||||
private:
|
||||
// DEPRECATED
|
||||
Blob mData;
|
||||
|
||||
public:
|
||||
@@ -156,9 +157,6 @@ public:
|
||||
uint160 getRIPEMD160 (int size = -1) const;
|
||||
uint256 getSHA256 (int size = -1) const;
|
||||
uint256 getSHA512Half (int size = -1) const;
|
||||
static uint256 getSHA512Half (const_byte_view v);
|
||||
|
||||
static uint256 getSHA512Half (const unsigned char* data, int len);
|
||||
|
||||
// prefix hash functions
|
||||
static uint256 getPrefixHash (std::uint32_t prefix, const unsigned char* data, int len);
|
||||
@@ -301,79 +299,146 @@ public:
|
||||
static int decodeVLLength (int b1);
|
||||
static int decodeVLLength (int b1, int b2);
|
||||
static int decodeVLLength (int b1, int b2, int b3);
|
||||
|
||||
static void TestSerializer ();
|
||||
};
|
||||
|
||||
class SerializerIterator
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// DEPRECATED
|
||||
// Transitional adapter to new serialization interfaces
|
||||
class SerialIter
|
||||
{
|
||||
protected:
|
||||
const Serializer& mSerializer;
|
||||
int mPos;
|
||||
private:
|
||||
std::uint8_t const* p_;
|
||||
std::size_t remain_;
|
||||
std::size_t used_ = 0;
|
||||
|
||||
public:
|
||||
SerialIter (void const* data,
|
||||
std::size_t size) noexcept;
|
||||
|
||||
// Reference is not const because we don't want to bind to a temporary
|
||||
SerializerIterator (Serializer& s) : mSerializer (s), mPos (0)
|
||||
explicit
|
||||
SerialIter (std::string const& s) noexcept
|
||||
: SerialIter(s.data(), s.size())
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
const Serializer& operator* (void)
|
||||
template <class T,
|
||||
std::enable_if_t<std::is_integral<T>::value &&
|
||||
sizeof(T) == 1>* = nullptr>
|
||||
explicit
|
||||
SerialIter (std::vector<T> const& v) noexcept
|
||||
: SerialIter (v.data(), v.size())
|
||||
{
|
||||
return mSerializer;
|
||||
}
|
||||
void reset (void)
|
||||
{
|
||||
mPos = 0;
|
||||
}
|
||||
void setPos (int p)
|
||||
{
|
||||
mPos = p;
|
||||
}
|
||||
|
||||
int getPos (void)
|
||||
// DEPRECATED
|
||||
SerialIter (Serializer const& s) noexcept
|
||||
: SerialIter(s.peekData())
|
||||
{
|
||||
return mPos;
|
||||
}
|
||||
bool empty ()
|
||||
|
||||
std::size_t
|
||||
empty() const noexcept
|
||||
{
|
||||
return mPos == mSerializer.getLength ();
|
||||
return remain_ == 0;
|
||||
}
|
||||
|
||||
void
|
||||
reset() noexcept;
|
||||
|
||||
int
|
||||
getBytesLeft() const noexcept
|
||||
{
|
||||
return static_cast<int>(remain_);
|
||||
}
|
||||
int getBytesLeft ();
|
||||
|
||||
// get functions throw on error
|
||||
unsigned char get8 ();
|
||||
std::uint16_t get16 ();
|
||||
std::uint32_t get32 ();
|
||||
std::uint64_t get64 ();
|
||||
unsigned char
|
||||
get8();
|
||||
|
||||
uint128 get128 () { return getBitString<128>(); }
|
||||
uint160 get160 () { return getBitString<160>(); }
|
||||
uint256 get256 () { return getBitString<256>(); }
|
||||
std::uint16_t
|
||||
get16();
|
||||
|
||||
template <std::size_t Bits, typename Tag = void>
|
||||
void getBitString (base_uint<Bits, Tag>& bits) {
|
||||
if (!mSerializer.getBitString<Bits> (bits, mPos))
|
||||
throw std::runtime_error ("invalid serializer getBitString");
|
||||
std::uint32_t
|
||||
get32();
|
||||
|
||||
mPos += Bits / 8;
|
||||
std::uint64_t
|
||||
get64();
|
||||
|
||||
template <int Bits, class Tag = void>
|
||||
base_uint<Bits, Tag>
|
||||
getBitString();
|
||||
|
||||
uint128
|
||||
get128()
|
||||
{
|
||||
return getBitString<128>();
|
||||
}
|
||||
|
||||
template <std::size_t Bits, typename Tag = void>
|
||||
base_uint<Bits, Tag> getBitString () {
|
||||
base_uint<Bits, Tag> bits;
|
||||
getBitString(bits);
|
||||
return bits;
|
||||
uint160
|
||||
get160()
|
||||
{
|
||||
return getBitString<160>();
|
||||
}
|
||||
|
||||
void getFieldID (int& type, int& field);
|
||||
uint256
|
||||
get256()
|
||||
{
|
||||
return getBitString<256>();
|
||||
}
|
||||
|
||||
Blob getRaw (int iLength);
|
||||
void
|
||||
getFieldID (int& type, int& name);
|
||||
|
||||
Blob getVL ();
|
||||
// VFALCO DEPRECATED Returns a copy
|
||||
Blob
|
||||
getRaw (int size);
|
||||
|
||||
// VFALCO DEPRECATED Returns a copy
|
||||
Blob
|
||||
getVL();
|
||||
};
|
||||
|
||||
template <int Bits, class Tag>
|
||||
base_uint<Bits, Tag>
|
||||
SerialIter::getBitString()
|
||||
{
|
||||
base_uint<Bits, Tag> u;
|
||||
auto const n = Bits/8;
|
||||
if (remain_ < n)
|
||||
throw std::runtime_error(
|
||||
"invalid SerialIter getBitString");
|
||||
std::memcpy (u.begin(), p_, n);
|
||||
p_ += n;
|
||||
used_ += n;
|
||||
remain_ -= n;
|
||||
return u;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
uint256
|
||||
getSHA512Half (void const* data, int len);
|
||||
|
||||
// DEPRECATED
|
||||
inline
|
||||
uint256
|
||||
getSHA512Half (std::string const& s)
|
||||
{
|
||||
return getSHA512Half(s.data(), s.size());
|
||||
}
|
||||
|
||||
// DEPRECATED
|
||||
template <class T,
|
||||
std::enable_if_t<std::is_integral<T>::value &&
|
||||
sizeof(T) == 1>* = nullptr>
|
||||
inline
|
||||
uint256
|
||||
getSHA512Half (std::vector<T> const& v)
|
||||
{
|
||||
return getSHA512Half(v.data(), v.size());
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
#endif
|
||||
|
||||
@@ -35,7 +35,7 @@ std::string STAccount::getText () const
|
||||
}
|
||||
|
||||
STAccount*
|
||||
STAccount::construct (SerializerIterator& u, SField::ref name)
|
||||
STAccount::construct (SerialIter& u, SField::ref name)
|
||||
{
|
||||
return new STAccount (name, u.getVL ());
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ STAmount::STAmount (Issue const& issue,
|
||||
}
|
||||
|
||||
std::unique_ptr<STAmount>
|
||||
STAmount::construct (SerializerIterator& sit, SField::ref name)
|
||||
STAmount::construct (SerialIter& sit, SField::ref name)
|
||||
{
|
||||
std::uint64_t value = sit.get64 ();
|
||||
|
||||
@@ -202,7 +202,7 @@ STAmount::createFromInt64 (SField::ref name, std::int64_t value)
|
||||
: STAmount (name, static_cast<std::uint64_t> (-value), true);
|
||||
}
|
||||
|
||||
STAmount STAmount::deserialize (SerializerIterator& it)
|
||||
STAmount STAmount::deserialize (SerialIter& it)
|
||||
{
|
||||
auto s = construct (it, sfGeneric);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace ripple {
|
||||
|
||||
std::unique_ptr<STBase>
|
||||
STArray::deserialize (SerializerIterator& sit, SField::ref field)
|
||||
STArray::deserialize (SerialIter& sit, SField::ref field)
|
||||
{
|
||||
std::unique_ptr <STArray> ret (std::make_unique <STArray> (field));
|
||||
vector& value (ret->getValue ());
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
STBlob::STBlob (SerializerIterator& st, SField::ref name)
|
||||
STBlob::STBlob (SerialIter& st, SField::ref name)
|
||||
: STBase (name)
|
||||
{
|
||||
value = st.getVL ();
|
||||
|
||||
@@ -37,7 +37,7 @@ STUInt8::getSType () const
|
||||
|
||||
template <>
|
||||
std::unique_ptr<STBase>
|
||||
STUInt8::deserialize (SerializerIterator& sit, SField::ref name)
|
||||
STUInt8::deserialize (SerialIter& sit, SField::ref name)
|
||||
{
|
||||
return std::make_unique <STUInt8> (name, sit.get8 ());
|
||||
}
|
||||
@@ -86,7 +86,7 @@ STUInt16::getSType () const
|
||||
|
||||
template <>
|
||||
std::unique_ptr<STBase>
|
||||
STUInt16::deserialize (SerializerIterator& sit, SField::ref name)
|
||||
STUInt16::deserialize (SerialIter& sit, SField::ref name)
|
||||
{
|
||||
return std::make_unique <STUInt16> (name, sit.get16 ());
|
||||
}
|
||||
@@ -152,7 +152,7 @@ STUInt32::getSType () const
|
||||
|
||||
template <>
|
||||
std::unique_ptr<STBase>
|
||||
STUInt32::deserialize (SerializerIterator& sit, SField::ref name)
|
||||
STUInt32::deserialize (SerialIter& sit, SField::ref name)
|
||||
{
|
||||
return std::make_unique <STUInt32> (name, sit.get32 ());
|
||||
}
|
||||
@@ -182,7 +182,7 @@ STUInt64::getSType () const
|
||||
|
||||
template <>
|
||||
std::unique_ptr<STBase>
|
||||
STUInt64::deserialize (SerializerIterator& sit, SField::ref name)
|
||||
STUInt64::deserialize (SerialIter& sit, SField::ref name)
|
||||
{
|
||||
return std::make_unique <STUInt64> (name, sit.get64 ());
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
namespace ripple {
|
||||
|
||||
STLedgerEntry::STLedgerEntry (
|
||||
SerializerIterator& sit, uint256 const& index)
|
||||
SerialIter& sit, uint256 const& index)
|
||||
: STObject (sfLedgerEntry), mIndex (index), mMutable (true)
|
||||
{
|
||||
set (sit);
|
||||
@@ -40,7 +40,7 @@ STLedgerEntry::STLedgerEntry (
|
||||
: STObject (sfLedgerEntry), mIndex (index), mMutable (true)
|
||||
{
|
||||
// we know 's' isn't going away
|
||||
SerializerIterator sit (const_cast<Serializer&> (s));
|
||||
SerialIter sit (const_cast<Serializer&> (s));
|
||||
set (sit);
|
||||
setSLEType ();
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ STObject::makeDefaultObject (SerializedTypeID id, SField::ref name)
|
||||
// VFALCO TODO Remove the 'depth' parameter
|
||||
std::unique_ptr<STBase>
|
||||
STObject::makeDeserializedObject (SerializedTypeID id, SField::ref name,
|
||||
SerializerIterator& sit, int depth)
|
||||
SerialIter& sit, int depth)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
@@ -259,7 +259,7 @@ bool STObject::isFieldAllowed (SField::ref field)
|
||||
}
|
||||
|
||||
// return true = terminated with end-of-object
|
||||
bool STObject::set (SerializerIterator& sit, int depth)
|
||||
bool STObject::set (SerialIter& sit, int depth)
|
||||
{
|
||||
bool reachedEndOfObject = false;
|
||||
|
||||
@@ -313,7 +313,7 @@ bool STObject::set (SerializerIterator& sit, int depth)
|
||||
|
||||
|
||||
std::unique_ptr<STBase>
|
||||
STObject::deserialize (SerializerIterator& sit, SField::ref name)
|
||||
STObject::deserialize (SerialIter& sit, SField::ref name)
|
||||
{
|
||||
std::unique_ptr <STObject> object (std::make_unique <STObject> (name));
|
||||
object->set (sit, 1);
|
||||
|
||||
@@ -51,7 +51,7 @@ STPathElement::get_hash (STPathElement const& element)
|
||||
}
|
||||
|
||||
std::unique_ptr<STBase>
|
||||
STPathSet::deserialize (SerializerIterator& sit, SField::ref name)
|
||||
STPathSet::deserialize (SerialIter& sit, SField::ref name)
|
||||
{
|
||||
std::vector<STPathElement> path;
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ STTx::STTx (STObject const& object)
|
||||
}
|
||||
}
|
||||
|
||||
STTx::STTx (SerializerIterator& sit)
|
||||
STTx::STTx (SerialIter& sit)
|
||||
: STObject (sfTransaction)
|
||||
, sig_state_ (boost::indeterminate)
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
STValidation::STValidation (SerializerIterator& sit, bool checkSignature)
|
||||
STValidation::STValidation (SerialIter& sit, bool checkSignature)
|
||||
: STObject (getFormat (), sit, sfValidation)
|
||||
, mTrusted (false)
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
namespace ripple {
|
||||
|
||||
std::unique_ptr<STBase>
|
||||
STVector256::deserialize (SerializerIterator& sit, SField::ref name)
|
||||
STVector256::deserialize (SerialIter& sit, SField::ref name)
|
||||
{
|
||||
auto vec = std::make_unique<STVector256> (name);
|
||||
|
||||
|
||||
@@ -337,25 +337,10 @@ uint256 Serializer::getSHA512Half (int size) const
|
||||
if (size == 0)
|
||||
return uint256();
|
||||
if (size < 0 || size > mData.size())
|
||||
return getSHA512Half (mData);
|
||||
return ripple::getSHA512Half (mData);
|
||||
|
||||
return getSHA512Half (const_byte_view (
|
||||
mData.data(), mData.data() + size));
|
||||
}
|
||||
|
||||
uint256 Serializer::getSHA512Half (const_byte_view v)
|
||||
{
|
||||
uint256 j[2];
|
||||
SHA512 (v.data(), v.size(),
|
||||
reinterpret_cast<unsigned char*> (j));
|
||||
return j[0];
|
||||
}
|
||||
|
||||
uint256 Serializer::getSHA512Half (const unsigned char* data, int len)
|
||||
{
|
||||
uint256 j[2];
|
||||
SHA512 (data, len, (unsigned char*) j);
|
||||
return j[0];
|
||||
return ripple::getSHA512Half (
|
||||
mData.data(), size);
|
||||
}
|
||||
|
||||
uint256 Serializer::getPrefixHash (std::uint32_t prefix, const unsigned char* data, int len)
|
||||
@@ -565,87 +550,170 @@ int Serializer::decodeVLLength (int b1, int b2, int b3)
|
||||
return 12481 + (b1 - 241) * 65536 + b2 * 256 + b3;
|
||||
}
|
||||
|
||||
void Serializer::TestSerializer ()
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
SerialIter::SerialIter (void const* data,
|
||||
std::size_t size) noexcept
|
||||
: p_ (reinterpret_cast<
|
||||
std::uint8_t const*>(data))
|
||||
, remain_ (size)
|
||||
{
|
||||
Serializer s (64);
|
||||
}
|
||||
|
||||
int SerializerIterator::getBytesLeft ()
|
||||
void
|
||||
SerialIter::reset() noexcept
|
||||
{
|
||||
return mSerializer.size () - mPos;
|
||||
p_ -= used_;
|
||||
remain_ += used_;
|
||||
used_ = 0;
|
||||
}
|
||||
|
||||
void SerializerIterator::getFieldID (int& type, int& field)
|
||||
unsigned char
|
||||
SerialIter::get8()
|
||||
{
|
||||
if (!mSerializer.getFieldID (type, field, mPos))
|
||||
throw std::runtime_error ("invalid serializer getFieldID");
|
||||
|
||||
++mPos;
|
||||
|
||||
if (type >= 16)
|
||||
++mPos;
|
||||
|
||||
if (field >= 16)
|
||||
++mPos;
|
||||
if (remain_ < 1)
|
||||
throw std::runtime_error(
|
||||
"invalid SerialIter get8");
|
||||
unsigned char t = *p_;
|
||||
++p_;
|
||||
++used_;
|
||||
--remain_;
|
||||
return t;
|
||||
}
|
||||
|
||||
unsigned char SerializerIterator::get8 ()
|
||||
std::uint16_t
|
||||
SerialIter::get16()
|
||||
{
|
||||
int val;
|
||||
|
||||
if (!mSerializer.get8 (val, mPos)) throw std::runtime_error ("invalid serializer get8");
|
||||
|
||||
++mPos;
|
||||
return val;
|
||||
if (remain_ < 2)
|
||||
throw std::runtime_error(
|
||||
"invalid SerialIter get16");
|
||||
auto t = p_;
|
||||
p_ += 2;
|
||||
used_ += 2;
|
||||
remain_ -= 2;
|
||||
return
|
||||
(std::uint64_t(t[0]) << 8) +
|
||||
std::uint64_t(t[1] );
|
||||
}
|
||||
|
||||
std::uint16_t SerializerIterator::get16 ()
|
||||
std::uint32_t
|
||||
SerialIter::get32()
|
||||
{
|
||||
std::uint16_t val;
|
||||
|
||||
if (!mSerializer.get16 (val, mPos)) throw std::runtime_error ("invalid serializer get16");
|
||||
|
||||
mPos += 16 / 8;
|
||||
return val;
|
||||
if (remain_ < 4)
|
||||
throw std::runtime_error(
|
||||
"invalid SerialIter get32");
|
||||
auto t = p_;
|
||||
p_ += 4;
|
||||
used_ += 4;
|
||||
remain_ -= 4;
|
||||
return
|
||||
(std::uint64_t(t[0]) << 24) +
|
||||
(std::uint64_t(t[1]) << 16) +
|
||||
(std::uint64_t(t[2]) << 8) +
|
||||
std::uint64_t(t[3] );
|
||||
}
|
||||
|
||||
std::uint32_t SerializerIterator::get32 ()
|
||||
std::uint64_t
|
||||
SerialIter::get64 ()
|
||||
{
|
||||
std::uint32_t val;
|
||||
|
||||
if (!mSerializer.get32 (val, mPos)) throw std::runtime_error ("invalid serializer get32");
|
||||
|
||||
mPos += 32 / 8;
|
||||
return val;
|
||||
if (remain_ < 8)
|
||||
throw std::runtime_error(
|
||||
"invalid SerialIter get64");
|
||||
auto t = p_;
|
||||
p_ += 8;
|
||||
used_ += 8;
|
||||
remain_ -= 8;
|
||||
return
|
||||
(std::uint64_t(t[0]) << 56) +
|
||||
(std::uint64_t(t[1]) << 48) +
|
||||
(std::uint64_t(t[2]) << 40) +
|
||||
(std::uint64_t(t[3]) << 32) +
|
||||
(std::uint64_t(t[4]) << 24) +
|
||||
(std::uint64_t(t[5]) << 16) +
|
||||
(std::uint64_t(t[6]) << 8) +
|
||||
std::uint64_t(t[7] );
|
||||
}
|
||||
|
||||
std::uint64_t SerializerIterator::get64 ()
|
||||
void
|
||||
SerialIter::getFieldID (int& type, int& name)
|
||||
{
|
||||
std::uint64_t val;
|
||||
type = get8();
|
||||
name = type & 15;
|
||||
type >>= 4;
|
||||
|
||||
if (!mSerializer.get64 (val, mPos)) throw std::runtime_error ("invalid serializer get64");
|
||||
if (type == 0)
|
||||
{
|
||||
// uncommon type
|
||||
type = get8();
|
||||
if (type == 0 || type < 16)
|
||||
throw std::runtime_error(
|
||||
"gFID: uncommon type out of range " +
|
||||
std::to_string(type));
|
||||
}
|
||||
|
||||
mPos += 64 / 8;
|
||||
return val;
|
||||
if (name == 0)
|
||||
{
|
||||
// uncommon name
|
||||
name = get8();
|
||||
if (name == 0 || name < 16)
|
||||
throw std::runtime_error(
|
||||
"gFID: uncommon name out of range " +
|
||||
std::to_string(name));
|
||||
}
|
||||
}
|
||||
|
||||
Blob SerializerIterator::getVL ()
|
||||
// VFALCO DEPRECATED Returns a copy
|
||||
Blob
|
||||
SerialIter::getRaw (int size)
|
||||
{
|
||||
int length;
|
||||
Blob vl;
|
||||
if (remain_ < size)
|
||||
throw std::runtime_error(
|
||||
"invalid SerialIter getRaw");
|
||||
Blob b (p_, p_ + size);
|
||||
p_ += size;
|
||||
used_ += size;
|
||||
remain_ -= size;
|
||||
return b;
|
||||
|
||||
if (!mSerializer.getVL (vl, mPos, length)) throw std::runtime_error ("invalid serializer getVL");
|
||||
|
||||
mPos += length;
|
||||
return vl;
|
||||
}
|
||||
|
||||
Blob SerializerIterator::getRaw (int iLength)
|
||||
// VFALCO DEPRECATED Returns a copy
|
||||
Blob
|
||||
SerialIter::getVL()
|
||||
{
|
||||
int iPos = mPos;
|
||||
mPos += iLength;
|
||||
int b1 = get8();
|
||||
int datLen;
|
||||
int lenLen = Serializer::decodeLengthLength(b1);
|
||||
if (lenLen == 1)
|
||||
{
|
||||
datLen = Serializer::decodeVLLength (b1);
|
||||
}
|
||||
else if (lenLen == 2)
|
||||
{
|
||||
int b2 = get8();
|
||||
datLen = Serializer::decodeVLLength (b1, b2);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(lenLen == 3);
|
||||
int b2 = get8();
|
||||
int b3 = get8();
|
||||
datLen = Serializer::decodeVLLength (b1, b2, b3);
|
||||
}
|
||||
return getRaw(datLen);
|
||||
}
|
||||
|
||||
return mSerializer.getRaw (iPos, iLength);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
uint256
|
||||
getSHA512Half (void const* data, int len)
|
||||
{
|
||||
uint256 j[2];
|
||||
SHA512 (
|
||||
reinterpret_cast<unsigned char const*>(
|
||||
data), len, (unsigned char*) j);
|
||||
return j[0];
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
|
||||
// Check node signing.
|
||||
Blob vucTextSrc = strCopy ("Hello, nurse!");
|
||||
uint256 uHash = Serializer::getSHA512Half (vucTextSrc);
|
||||
uint256 uHash = getSHA512Half (vucTextSrc);
|
||||
Blob vucTextSig;
|
||||
|
||||
naNodePrivate.signNodePrivate (uHash, vucTextSig);
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
Serializer ser;
|
||||
s.add (ser);
|
||||
|
||||
SerializerIterator sit (ser);
|
||||
SerialIter sit (ser);
|
||||
return STAmount::deserialize (sit);
|
||||
}
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ public:
|
||||
|
||||
Serializer s;
|
||||
object1.add (s);
|
||||
SerializerIterator it (s);
|
||||
SerialIter it (s);
|
||||
|
||||
STObject object3 (elements, it, sfTestObject);
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
|
||||
Serializer rawTxn;
|
||||
j.add (rawTxn);
|
||||
SerializerIterator sit (rawTxn);
|
||||
SerialIter sit (rawTxn);
|
||||
STTx copy (sit);
|
||||
|
||||
if (copy != j)
|
||||
|
||||
@@ -39,15 +39,15 @@ Json::Value doSubmit (RPC::Context& context)
|
||||
context.params, true, bFailHard, context.netOps, context.role);
|
||||
}
|
||||
|
||||
Json::Value jvResult;
|
||||
Json::Value jvResult;
|
||||
|
||||
std::pair<Blob, bool> ret(strUnHex (context.params["tx_blob"].asString ()));
|
||||
|
||||
if (!ret.second || !ret.first.size ())
|
||||
return rpcError (rpcINVALID_PARAMS);
|
||||
|
||||
Serializer sTrans (ret.first);
|
||||
SerializerIterator sitTrans (sTrans);
|
||||
Serializer sTrans (ret.first);
|
||||
SerialIter sitTrans (sTrans);
|
||||
|
||||
STTx::pointer stpTrans;
|
||||
|
||||
|
||||
@@ -39,90 +39,50 @@ public:
|
||||
typedef const std::shared_ptr<SHAMapItem>& ref;
|
||||
|
||||
public:
|
||||
explicit SHAMapItem (uint256 const& tag) : mTag (tag)
|
||||
explicit SHAMapItem (uint256 const& tag)
|
||||
: mTag (tag)
|
||||
{
|
||||
;
|
||||
}
|
||||
explicit SHAMapItem (Blob const & data); // tag by hash
|
||||
SHAMapItem (uint256 const& tag, Blob const & data);
|
||||
SHAMapItem (uint256 const& tag, const Serializer & s);
|
||||
|
||||
uint256 const& getTag () const
|
||||
// tag computed from hash of data
|
||||
explicit SHAMapItem (Blob const& data);
|
||||
|
||||
SHAMapItem (uint256 const& tag, Blob const & data);
|
||||
|
||||
SHAMapItem (uint256 const& tag, Serializer const& s);
|
||||
|
||||
std::size_t
|
||||
size() const
|
||||
{
|
||||
return mData.peekData().size();
|
||||
}
|
||||
|
||||
void const*
|
||||
data() const
|
||||
{
|
||||
return mData.peekData().data();
|
||||
}
|
||||
|
||||
uint256 const& getTag() const
|
||||
{
|
||||
return mTag;
|
||||
}
|
||||
Blob const& peekData () const
|
||||
|
||||
Blob const& peekData() const
|
||||
{
|
||||
return mData.peekData ();
|
||||
return mData.peekData();
|
||||
}
|
||||
Serializer& peekSerializer ()
|
||||
|
||||
Serializer& peekSerializer()
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
void addRaw (Blob & s) const
|
||||
|
||||
void addRaw (Blob& s) const
|
||||
{
|
||||
s.insert (s.end (), mData.begin (), mData.end ());
|
||||
}
|
||||
|
||||
void updateData (Blob const & data)
|
||||
{
|
||||
mData = data;
|
||||
}
|
||||
|
||||
bool operator== (const SHAMapItem & i) const
|
||||
{
|
||||
return mTag == i.mTag;
|
||||
}
|
||||
bool operator!= (const SHAMapItem & i) const
|
||||
{
|
||||
return mTag != i.mTag;
|
||||
}
|
||||
bool operator== (uint256 const& i) const
|
||||
{
|
||||
return mTag == i;
|
||||
}
|
||||
bool operator!= (uint256 const& i) const
|
||||
{
|
||||
return mTag != i;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// This code is comment out because it is unused. It could work.
|
||||
bool operator< (const SHAMapItem & i) const
|
||||
{
|
||||
return mTag < i.mTag;
|
||||
}
|
||||
bool operator> (const SHAMapItem & i) const
|
||||
{
|
||||
return mTag > i.mTag;
|
||||
}
|
||||
bool operator<= (const SHAMapItem & i) const
|
||||
{
|
||||
return mTag <= i.mTag;
|
||||
}
|
||||
bool operator>= (const SHAMapItem & i) const
|
||||
{
|
||||
return mTag >= i.mTag;
|
||||
}
|
||||
|
||||
bool operator< (uint256 const& i) const
|
||||
{
|
||||
return mTag < i;
|
||||
}
|
||||
bool operator> (uint256 const& i) const
|
||||
{
|
||||
return mTag > i;
|
||||
}
|
||||
bool operator<= (uint256 const& i) const
|
||||
{
|
||||
return mTag <= i;
|
||||
}
|
||||
bool operator>= (uint256 const& i) const
|
||||
{
|
||||
return mTag >= i;
|
||||
}
|
||||
#endif
|
||||
|
||||
// VFALCO Why is this virtual?
|
||||
virtual void dump (beast::Journal journal);
|
||||
|
||||
|
||||
@@ -74,14 +74,17 @@ public:
|
||||
{
|
||||
return mSeq;
|
||||
}
|
||||
|
||||
void setSeq (std::uint32_t s)
|
||||
{
|
||||
mSeq = s;
|
||||
}
|
||||
|
||||
uint256 const& getNodeHash () const
|
||||
{
|
||||
return mHash;
|
||||
}
|
||||
|
||||
TNType getType () const
|
||||
{
|
||||
return mType;
|
||||
@@ -93,27 +96,33 @@ public:
|
||||
return (mType == tnTRANSACTION_NM) || (mType == tnTRANSACTION_MD) ||
|
||||
(mType == tnACCOUNT_STATE);
|
||||
}
|
||||
|
||||
bool isInner () const
|
||||
{
|
||||
return mType == tnINNER;
|
||||
}
|
||||
|
||||
bool isInBounds (SHAMapNodeID const &id) const
|
||||
{
|
||||
// Nodes at depth 64 must be leaves
|
||||
return (!isInner() || (id.getDepth() < 64));
|
||||
}
|
||||
|
||||
bool isValid () const
|
||||
{
|
||||
return mType != tnERROR;
|
||||
}
|
||||
|
||||
bool isTransaction () const
|
||||
{
|
||||
return (mType == tnTRANSACTION_NM) || (mType == tnTRANSACTION_MD);
|
||||
}
|
||||
|
||||
bool hasMetaData () const
|
||||
{
|
||||
return mType == tnTRANSACTION_MD;
|
||||
}
|
||||
|
||||
bool isAccountState () const
|
||||
{
|
||||
return mType == tnACCOUNT_STATE;
|
||||
@@ -135,9 +144,13 @@ public:
|
||||
{
|
||||
return (mIsBranch & (1 << m)) == 0;
|
||||
}
|
||||
|
||||
bool isEmpty () const;
|
||||
|
||||
int getBranchCount () const;
|
||||
|
||||
void makeInner ();
|
||||
|
||||
uint256 const& getChildHash (int m) const
|
||||
{
|
||||
assert ((m >= 0) && (m < 16) && (mType == tnINNER));
|
||||
@@ -149,38 +162,33 @@ public:
|
||||
{
|
||||
return bool(mItem);
|
||||
}
|
||||
SHAMapItem::ref peekItem ()
|
||||
|
||||
SHAMapItem::ref peekItem () const
|
||||
{
|
||||
// CAUTION: Do not modify the item TODO(tom): a comment in the code does
|
||||
// nothing - this should return a const reference.
|
||||
return mItem;
|
||||
}
|
||||
|
||||
bool setItem (SHAMapItem::ref i, TNType type);
|
||||
uint256 const& getTag () const
|
||||
{
|
||||
return mItem->getTag ();
|
||||
}
|
||||
Blob const& peekData ()
|
||||
{
|
||||
return mItem->peekData ();
|
||||
}
|
||||
|
||||
// sync functions
|
||||
bool isFullBelow (std::uint32_t generation) const
|
||||
{
|
||||
return mFullBelowGen == generation;
|
||||
}
|
||||
|
||||
void setFullBelowGen (std::uint32_t gen)
|
||||
{
|
||||
mFullBelowGen = gen;
|
||||
}
|
||||
|
||||
// VFALCO Why is this virtual?
|
||||
// VFALCO Why are these virtual?
|
||||
virtual void dump (SHAMapNodeID const&, beast::Journal journal);
|
||||
virtual std::string getString (SHAMapNodeID const&) const;
|
||||
|
||||
SHAMapTreeNode* getChildPointer (int branch);
|
||||
|
||||
SHAMapTreeNode::pointer getChild (int branch);
|
||||
|
||||
void canonicalizeChild (int branch, SHAMapTreeNode::pointer& node);
|
||||
|
||||
private:
|
||||
|
||||
@@ -184,7 +184,7 @@ SHAMapTreeNode* SHAMap::walkToPointer (uint256 const& id)
|
||||
nodeID = nodeID.getChildNodeID (branch);
|
||||
}
|
||||
|
||||
return (inNode->getTag () == id) ? inNode : nullptr;
|
||||
return (inNode->peekItem()->getTag () == id) ? inNode : nullptr;
|
||||
}
|
||||
|
||||
SHAMapTreeNode::pointer SHAMap::fetchNodeFromDB (uint256 const& hash)
|
||||
@@ -1100,7 +1100,7 @@ bool SHAMap::getPath (uint256 const& index, std::vector< Blob >& nodes, SHANodeF
|
||||
nodeID = nodeID.getChildNodeID (branch);
|
||||
}
|
||||
|
||||
if (inNode->getTag () != index) // path leads to different leaf
|
||||
if (inNode->peekItem()->getTag () != index) // path leads to different leaf
|
||||
return false;
|
||||
|
||||
// path leads to the requested leaf
|
||||
|
||||
@@ -143,11 +143,11 @@ bool SHAMap::compare (SHAMap::ref otherMap, Delta& differences, int maxCount)
|
||||
if (ourNode->isLeaf () && otherNode->isLeaf ())
|
||||
{
|
||||
// two leaves
|
||||
if (ourNode->getTag () == otherNode->getTag ())
|
||||
if (ourNode->peekItem()->getTag () == otherNode->peekItem()->getTag ())
|
||||
{
|
||||
if (ourNode->peekData () != otherNode->peekData ())
|
||||
if (ourNode->peekItem()->peekData () != otherNode->peekItem()->peekData ())
|
||||
{
|
||||
differences.insert (std::make_pair (ourNode->getTag (),
|
||||
differences.insert (std::make_pair (ourNode->peekItem()->getTag (),
|
||||
DeltaRef (ourNode->peekItem (),
|
||||
otherNode->peekItem ())));
|
||||
if (--maxCount <= 0)
|
||||
@@ -156,13 +156,13 @@ bool SHAMap::compare (SHAMap::ref otherMap, Delta& differences, int maxCount)
|
||||
}
|
||||
else
|
||||
{
|
||||
differences.insert (std::make_pair(ourNode->getTag (),
|
||||
differences.insert (std::make_pair(ourNode->peekItem()->getTag (),
|
||||
DeltaRef(ourNode->peekItem(),
|
||||
SHAMapItem::pointer ())));
|
||||
if (--maxCount <= 0)
|
||||
return false;
|
||||
|
||||
differences.insert(std::make_pair(otherNode->getTag (),
|
||||
differences.insert(std::make_pair(otherNode->peekItem()->getTag (),
|
||||
DeltaRef(SHAMapItem::pointer(),
|
||||
otherNode->peekItem ())));
|
||||
if (--maxCount <= 0)
|
||||
|
||||
@@ -685,7 +685,7 @@ void SHAMap::getFetchPack (SHAMap* have, bool includeLeaves, int max,
|
||||
if (root->isLeaf ())
|
||||
{
|
||||
if (includeLeaves &&
|
||||
(!have || !have->hasLeafNode (root->getTag (), root->getNodeHash ())))
|
||||
(!have || !have->hasLeafNode (root->peekItem()->getTag (), root->getNodeHash ())))
|
||||
{
|
||||
Serializer s;
|
||||
root->addRaw (s, snfPREFIX);
|
||||
@@ -728,7 +728,7 @@ void SHAMap::getFetchPack (SHAMap* have, bool includeLeaves, int max,
|
||||
if (!have || !have->hasInnerNode (childID, childHash))
|
||||
stack.push ({next, childID});
|
||||
}
|
||||
else if (includeLeaves && (!have || !have->hasLeafNode (next->getTag(), childHash)))
|
||||
else if (includeLeaves && (!have || !have->hasLeafNode (next->peekItem()->getTag(), childHash)))
|
||||
{
|
||||
Serializer s;
|
||||
next->addRaw (s, snfPREFIX);
|
||||
|
||||
@@ -185,7 +185,7 @@ SHAMapTreeNode::SHAMapTreeNode (Blob const& rawNode,
|
||||
|
||||
if (prefix == HashPrefix::transactionID)
|
||||
{
|
||||
mItem = std::make_shared<SHAMapItem> (Serializer::getSHA512Half (rawNode), s.peekData ());
|
||||
mItem = std::make_shared<SHAMapItem> (getSHA512Half (rawNode), s.peekData ());
|
||||
mType = tnTRANSACTION_NM;
|
||||
}
|
||||
else if (prefix == HashPrefix::leafNode)
|
||||
@@ -286,7 +286,7 @@ bool SHAMapTreeNode::updateHash ()
|
||||
}
|
||||
else if (mType == tnACCOUNT_STATE)
|
||||
{
|
||||
Serializer s (mItem->peekSerializer ().getDataLength () + (256 + 32) / 8);
|
||||
Serializer s (mItem->size() + (256 + 32) / 8);
|
||||
s.add32 (HashPrefix::leafNode);
|
||||
s.addRaw (mItem->peekData ());
|
||||
s.add256 (mItem->getTag ());
|
||||
@@ -294,7 +294,7 @@ bool SHAMapTreeNode::updateHash ()
|
||||
}
|
||||
else if (mType == tnTRANSACTION_MD)
|
||||
{
|
||||
Serializer s (mItem->peekSerializer ().getDataLength () + (256 + 32) / 8);
|
||||
Serializer s (mItem->size() + (256 + 32) / 8);
|
||||
s.add32 (HashPrefix::txNode);
|
||||
s.addRaw (mItem->peekData ());
|
||||
s.add256 (mItem->getTag ());
|
||||
@@ -475,11 +475,11 @@ std::string SHAMapTreeNode::getString (const SHAMapNodeID & id) const
|
||||
ret += ",leaf\n";
|
||||
|
||||
ret += " Tag=";
|
||||
ret += to_string (getTag ());
|
||||
ret += to_string (peekItem()->getTag ());
|
||||
ret += "\n Hash=";
|
||||
ret += to_string (mHash);
|
||||
ret += "/";
|
||||
ret += beast::lexicalCast <std::string> (mItem->peekSerializer ().getDataLength ());
|
||||
ret += beast::lexicalCast <std::string> (mItem->size());
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -30,6 +30,11 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
inline bool operator== (SHAMapItem const& a, SHAMapItem const& b) { return a.getTag() == b.getTag(); }
|
||||
inline bool operator!= (SHAMapItem const& a, SHAMapItem const& b) { return a.getTag() != b.getTag(); }
|
||||
inline bool operator== (SHAMapItem const& a, uint256 const& b) { return a.getTag() == b; }
|
||||
inline bool operator!= (SHAMapItem const& a, uint256 const& b) { return a.getTag() != b; }
|
||||
|
||||
class SHAMap_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user