diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj index 13edb7dab..2a7b9ca05 100755 --- a/Builds/VisualStudio2013/RippleD.vcxproj +++ b/Builds/VisualStudio2013/RippleD.vcxproj @@ -1775,8 +1775,6 @@ - - diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters index bab5140ab..348038c4d 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters @@ -2652,9 +2652,6 @@ ripple\basics - - ripple\basics - ripple\basics diff --git a/src/ripple/app/consensus/LedgerConsensus.cpp b/src/ripple/app/consensus/LedgerConsensus.cpp index 7f431453f..6904c243c 100644 --- a/src/ripple/app/consensus/LedgerConsensus.cpp +++ b/src/ripple/app/consensus/LedgerConsensus.cpp @@ -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(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(sit); if (applyTransaction (engine, txn, diff --git a/src/ripple/app/ledger/AcceptedLedger.cpp b/src/ripple/app/ledger/AcceptedLedger.cpp index ff1201ebb..2d1cda79b 100644 --- a/src/ripple/app/ledger/AcceptedLedger.cpp +++ b/src/ripple/app/ledger/AcceptedLedger.cpp @@ -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 (ledger, std::ref (sit))); } } diff --git a/src/ripple/app/ledger/AcceptedLedgerTx.cpp b/src/ripple/app/ledger/AcceptedLedgerTx.cpp index 4ff61016f..2b5418538 100644 --- a/src/ripple/app/ledger/AcceptedLedgerTx.cpp +++ b/src/ripple/app/ledger/AcceptedLedgerTx.cpp @@ -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 (std::ref (txnIt)); mRawMeta = sit.getVL (); diff --git a/src/ripple/app/ledger/AcceptedLedgerTx.h b/src/ripple/app/ledger/AcceptedLedgerTx.h index 187ee0c36..f12cd3a11 100644 --- a/src/ripple/app/ledger/AcceptedLedgerTx.h +++ b/src/ripple/app/ledger/AcceptedLedgerTx.h @@ -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); diff --git a/src/ripple/app/ledger/ConsensusTransSetSF.cpp b/src/ripple/app/ledger/ConsensusTransSetSF.cpp index eaa59e9ad..e59d9a9af 100644 --- a/src/ripple/app/ledger/ConsensusTransSetSF.cpp +++ b/src/ripple/app/ledger/ConsensusTransSetSF.cpp @@ -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 (std::ref (sit)); assert (stx->getTransactionID () == nodeHash); getApp().getJobQueue ().addJob ( diff --git a/src/ripple/app/ledger/Ledger.cpp b/src/ripple/app/ledger/Ledger.cpp index ab7e3804e..31766c76c 100644 --- a/src/ripple/app/ledger/Ledger.cpp +++ b/src/ripple/app/ledger/Ledger.cpp @@ -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 (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 (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 ( 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 (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; diff --git a/src/ripple/app/ledger/LedgerToJson.h b/src/ripple/app/ledger/LedgerToJson.h index 553cc3af0..2264f34eb 100644 --- a/src/ripple/app/ledger/LedgerToJson.h +++ b/src/ripple/app/ledger/LedgerToJson.h @@ -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 ( diff --git a/src/ripple/app/misc/NetworkOPs.cpp b/src/ripple/app/misc/NetworkOPs.cpp index 56e276590..f8c489853 100644 --- a/src/ripple/app/misc/NetworkOPs.cpp +++ b/src/ripple/app/misc/NetworkOPs.cpp @@ -887,7 +887,7 @@ void NetworkOPsImp::submitTransaction ( Serializer s; iTrans->add (s); - SerializerIterator sit (s); + SerialIter sit (s); auto trans = std::make_shared (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; diff --git a/src/ripple/app/peers/UniqueNodeList.cpp b/src/ripple/app/peers/UniqueNodeList.cpp index 4e878a365..53db568cd 100644 --- a/src/ripple/app/peers/UniqueNodeList.cpp +++ b/src/ripple/app/peers/UniqueNodeList.cpp @@ -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; diff --git a/src/ripple/app/transactors/AddWallet.cpp b/src/ripple/app/transactors/AddWallet.cpp new file mode 100644 index 000000000..5dcbe923a --- /dev/null +++ b/src/ripple/app/transactors/AddWallet.cpp @@ -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 +#include +#include +#include +#include + +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 (); +} + +} diff --git a/src/ripple/app/tx/Transaction.cpp b/src/ripple/app/tx/Transaction.cpp index e2236ce49..86cdfb1f5 100644 --- a/src/ripple/app/tx/Transaction.cpp +++ b/src/ripple/app/tx/Transaction.cpp @@ -56,7 +56,7 @@ Transaction::pointer Transaction::sharedTransaction ( try { Serializer s (vucTransaction); - SerializerIterator sit (s); + SerialIter sit (s); return std::make_shared ( std::make_shared (sit), @@ -111,7 +111,7 @@ Transaction::pointer Transaction::transactionFromSQL ( rawTxn.resize (txSize); - SerializerIterator it (rawTxn); + SerialIter it (rawTxn); auto txn = std::make_shared (it); auto tr = std::make_shared (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 (it); auto tr = std::make_shared (txn, Validate::YES); diff --git a/src/ripple/app/tx/TransactionEngine.cpp b/src/ripple/app/tx/TransactionEngine.cpp index f904ba288..23ee38670 100644 --- a/src/ripple/app/tx/TransactionEngine.cpp +++ b/src/ripple/app/tx/TransactionEngine.cpp @@ -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)) diff --git a/src/ripple/app/tx/TransactionMaster.cpp b/src/ripple/app/tx/TransactionMaster.cpp index f511ac62c..ec960b5e7 100644 --- a/src/ripple/app/tx/TransactionMaster.cpp +++ b/src/ripple/app/tx/TransactionMaster.cpp @@ -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 (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 (std::ref (sit)); } diff --git a/src/ripple/app/tx/TransactionMeta.cpp b/src/ripple/app/tx/TransactionMeta.cpp index cd1de09bb..22d4e644d 100644 --- a/src/ripple/app/tx/TransactionMeta.cpp +++ b/src/ripple/app/tx/TransactionMeta.cpp @@ -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 pobj = STObject::deserialize (sit, sfMetadata); STObject* obj = static_cast (pobj.get ()); diff --git a/src/ripple/basics/byte_view.h b/src/ripple/basics/byte_view.h deleted file mode 100644 index 7dc57fda3..000000000 --- a/src/ripple/basics/byte_view.h +++ /dev/null @@ -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 - -#include - -namespace ripple { - -// VFALCO DEPRECATED -typedef beast::buffer_view byte_view; -typedef beast::buffer_view const_byte_view; - -} - -#endif diff --git a/src/ripple/nodestore/impl/DatabaseImp.h b/src/ripple/nodestore/impl/DatabaseImp.h index e3a45a05b..3fed69354 100644 --- a/src/ripple/nodestore/impl/DatabaseImp.h +++ b/src/ripple/nodestore/impl/DatabaseImp.h @@ -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); diff --git a/src/ripple/overlay/impl/PeerImp.cpp b/src/ripple/overlay/impl/PeerImp.cpp index 754227ff1..a43502469 100644 --- a/src/ripple/overlay/impl/PeerImp.cpp +++ b/src/ripple/overlay/impl/PeerImp.cpp @@ -991,11 +991,10 @@ PeerImp::onMessage (std::shared_ptr 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 const& m) catch (...) { p_journal_.warning << "Transaction invalid: " << - s.getHex(); + strHex(m->rawtransaction ()); } } @@ -1314,7 +1313,7 @@ PeerImp::onMessage (std::shared_ptr const& m) try { Serializer s (m->validation ()); - SerializerIterator sit (s); + SerialIter sit (s); STValidation::pointer val = std::make_shared < STValidation> (std::ref (sit), false); diff --git a/src/ripple/overlay/impl/TMHello.cpp b/src/ripple/overlay/impl/TMHello.cpp index 8807ed7e2..112429089 100644 --- a/src/ripple/overlay/impl/TMHello.cpp +++ b/src/ripple/overlay/impl/TMHello.cpp @@ -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; } diff --git a/src/ripple/protocol/STAccount.h b/src/ripple/protocol/STAccount.h index 58fefbdc4..3f58fd45f 100644 --- a/src/ripple/protocol/STAccount.h +++ b/src/ripple/protocol/STAccount.h @@ -47,7 +47,7 @@ public: { ; } - static std::unique_ptr deserialize (SerializerIterator& sit, SField::ref name) + static std::unique_ptr deserialize (SerialIter& sit, SField::ref name) { return std::unique_ptr (construct (sit, name)); } @@ -87,7 +87,7 @@ public: } private: - static STAccount* construct (SerializerIterator&, SField::ref); + static STAccount* construct (SerialIter&, SField::ref); }; } // ripple diff --git a/src/ripple/protocol/STAmount.h b/src/ripple/protocol/STAmount.h index 255b64607..a91acccc8 100644 --- a/src/ripple/protocol/STAmount.h +++ b/src/ripple/protocol/STAmount.h @@ -109,7 +109,7 @@ public: private: static std::unique_ptr - construct (SerializerIterator&, SField::ref name); + construct (SerialIter&, SField::ref name); void setSNValue (std::int64_t); @@ -122,14 +122,14 @@ public: static std::unique_ptr deserialize ( - SerializerIterator& sit, SField::ref name) + SerialIter& sit, SField::ref name) { return construct (sit, name); } static STAmount - deserialize (SerializerIterator&); + deserialize (SerialIter&); //-------------------------------------------------------------------------- // diff --git a/src/ripple/protocol/STArray.h b/src/ripple/protocol/STArray.h index 6079c7575..5f7556e80 100644 --- a/src/ripple/protocol/STArray.h +++ b/src/ripple/protocol/STArray.h @@ -74,7 +74,7 @@ public: static std::unique_ptr - deserialize (SerializerIterator & sit, SField::ref name); + deserialize (SerialIter & sit, SField::ref name); const vector& getValue () const { diff --git a/src/ripple/protocol/STBitString.h b/src/ripple/protocol/STBitString.h index ee112ea6a..f1c04bcf6 100644 --- a/src/ripple/protocol/STBitString.h +++ b/src/ripple/protocol/STBitString.h @@ -59,7 +59,7 @@ public: static std::unique_ptr - deserialize (SerializerIterator& sit, SField::ref name) + deserialize (SerialIter& sit, SField::ref name) { return std::make_unique (name, sit.getBitString ()); } diff --git a/src/ripple/protocol/STBlob.h b/src/ripple/protocol/STBlob.h index 110acea5f..9f262fb7d 100644 --- a/src/ripple/protocol/STBlob.h +++ b/src/ripple/protocol/STBlob.h @@ -44,11 +44,11 @@ public: : STBase (n) { } - STBlob (SerializerIterator&, SField::ref name = sfGeneric); + STBlob (SerialIter&, SField::ref name = sfGeneric); static std::unique_ptr - deserialize (SerializerIterator& sit, SField::ref name) + deserialize (SerialIter& sit, SField::ref name) { return std::make_unique (name, sit.getVL ()); } diff --git a/src/ripple/protocol/STInteger.h b/src/ripple/protocol/STInteger.h index 2ecd48e37..e13582958 100644 --- a/src/ripple/protocol/STInteger.h +++ b/src/ripple/protocol/STInteger.h @@ -40,7 +40,7 @@ public: static std::unique_ptr - 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; +using STUInt8 = STInteger; using STUInt16 = STInteger; using STUInt32 = STInteger; using STUInt64 = STInteger; diff --git a/src/ripple/protocol/STLedgerEntry.h b/src/ripple/protocol/STLedgerEntry.h index 94886c23c..1b99220f4 100644 --- a/src/ripple/protocol/STLedgerEntry.h +++ b/src/ripple/protocol/STLedgerEntry.h @@ -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); diff --git a/src/ripple/protocol/STObject.h b/src/ripple/protocol/STObject.h index 4d17b19b2..37f076a41 100644 --- a/src/ripple/protocol/STObject.h +++ b/src/ripple/protocol/STObject.h @@ -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 - 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 makeDeserializedObject ( SerializedTypeID id, SField::ref name, - SerializerIterator&, + SerialIter&, int depth); static std::unique_ptr diff --git a/src/ripple/protocol/STPathSet.h b/src/ripple/protocol/STPathSet.h index 6c2f445e8..c86b92ec8 100644 --- a/src/ripple/protocol/STPathSet.h +++ b/src/ripple/protocol/STPathSet.h @@ -239,7 +239,7 @@ public: static std::unique_ptr - deserialize (SerializerIterator& sit, SField::ref name); + deserialize (SerialIter& sit, SField::ref name); std::unique_ptr duplicate () const override diff --git a/src/ripple/protocol/STTx.h b/src/ripple/protocol/STTx.h index 934bf3f84..b33235014 100644 --- a/src/ripple/protocol/STTx.h +++ b/src/ripple/protocol/STTx.h @@ -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? diff --git a/src/ripple/protocol/STValidation.h b/src/ripple/protocol/STValidation.h index ce3d3f28d..42bc1d7a7 100644 --- a/src/ripple/protocol/STValidation.h +++ b/src/ripple/protocol/STValidation.h @@ -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, diff --git a/src/ripple/protocol/STVector256.h b/src/ripple/protocol/STVector256.h index 52d99ceb9..554fa1c0b 100644 --- a/src/ripple/protocol/STVector256.h +++ b/src/ripple/protocol/STVector256.h @@ -52,7 +52,7 @@ public: static std::unique_ptr - 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 mValue; + std::vector mValue; }; } // ripple diff --git a/src/ripple/protocol/Serializer.h b/src/ripple/protocol/Serializer.h index 95770b9b5..c48c9f53f 100644 --- a/src/ripple/protocol/Serializer.h +++ b/src/ripple/protocol/Serializer.h @@ -20,11 +20,14 @@ #ifndef RIPPLE_PROTOCOL_SERIALIZER_H_INCLUDED #define RIPPLE_PROTOCOL_SERIALIZER_H_INCLUDED -#include #include #include +#include +#include +#include #include #include +#include // namespace ripple { @@ -32,10 +35,8 @@ class CKey; // forward declaration class Serializer { -public: - typedef std::shared_ptr 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 ::value && + sizeof(T) == 1>* = nullptr> + explicit + SerialIter (std::vector 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(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 - void getBitString (base_uint& bits) { - if (!mSerializer.getBitString (bits, mPos)) - throw std::runtime_error ("invalid serializer getBitString"); + std::uint32_t + get32(); - mPos += Bits / 8; + std::uint64_t + get64(); + + template + base_uint + getBitString(); + + uint128 + get128() + { + return getBitString<128>(); } - template - base_uint getBitString () { - base_uint bits; - getBitString(bits); - return bits; + uint160 + get160() + { + return getBitString<160>(); + } + + uint256 + get256() + { + return getBitString<256>(); } - void getFieldID (int& type, int& field); + void + getFieldID (int& type, int& name); - Blob getRaw (int iLength); + // VFALCO DEPRECATED Returns a copy + Blob + getRaw (int size); - Blob getVL (); + // VFALCO DEPRECATED Returns a copy + Blob + getVL(); }; +template +base_uint +SerialIter::getBitString() +{ + base_uint 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 ::value && + sizeof(T) == 1>* = nullptr> +inline +uint256 +getSHA512Half (std::vector const& v) +{ + return getSHA512Half(v.data(), v.size()); +} + } // ripple #endif diff --git a/src/ripple/protocol/impl/STAccount.cpp b/src/ripple/protocol/impl/STAccount.cpp index f19336c5f..2b0a6ed35 100644 --- a/src/ripple/protocol/impl/STAccount.cpp +++ b/src/ripple/protocol/impl/STAccount.cpp @@ -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 ()); } diff --git a/src/ripple/protocol/impl/STAmount.cpp b/src/ripple/protocol/impl/STAmount.cpp index 5be7c52a5..75bcd9592 100644 --- a/src/ripple/protocol/impl/STAmount.cpp +++ b/src/ripple/protocol/impl/STAmount.cpp @@ -138,7 +138,7 @@ STAmount::STAmount (Issue const& issue, } std::unique_ptr -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 (-value), true); } -STAmount STAmount::deserialize (SerializerIterator& it) +STAmount STAmount::deserialize (SerialIter& it) { auto s = construct (it, sfGeneric); diff --git a/src/ripple/protocol/impl/STArray.cpp b/src/ripple/protocol/impl/STArray.cpp index 28049d16d..ed793a1af 100644 --- a/src/ripple/protocol/impl/STArray.cpp +++ b/src/ripple/protocol/impl/STArray.cpp @@ -25,7 +25,7 @@ namespace ripple { std::unique_ptr -STArray::deserialize (SerializerIterator& sit, SField::ref field) +STArray::deserialize (SerialIter& sit, SField::ref field) { std::unique_ptr ret (std::make_unique (field)); vector& value (ret->getValue ()); diff --git a/src/ripple/protocol/impl/STBlob.cpp b/src/ripple/protocol/impl/STBlob.cpp index 43d0405c4..198040650 100644 --- a/src/ripple/protocol/impl/STBlob.cpp +++ b/src/ripple/protocol/impl/STBlob.cpp @@ -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 (); diff --git a/src/ripple/protocol/impl/STInteger.cpp b/src/ripple/protocol/impl/STInteger.cpp index 287c5f205..0c8cd24b6 100644 --- a/src/ripple/protocol/impl/STInteger.cpp +++ b/src/ripple/protocol/impl/STInteger.cpp @@ -37,7 +37,7 @@ STUInt8::getSType () const template <> std::unique_ptr -STUInt8::deserialize (SerializerIterator& sit, SField::ref name) +STUInt8::deserialize (SerialIter& sit, SField::ref name) { return std::make_unique (name, sit.get8 ()); } @@ -86,7 +86,7 @@ STUInt16::getSType () const template <> std::unique_ptr -STUInt16::deserialize (SerializerIterator& sit, SField::ref name) +STUInt16::deserialize (SerialIter& sit, SField::ref name) { return std::make_unique (name, sit.get16 ()); } @@ -152,7 +152,7 @@ STUInt32::getSType () const template <> std::unique_ptr -STUInt32::deserialize (SerializerIterator& sit, SField::ref name) +STUInt32::deserialize (SerialIter& sit, SField::ref name) { return std::make_unique (name, sit.get32 ()); } @@ -182,7 +182,7 @@ STUInt64::getSType () const template <> std::unique_ptr -STUInt64::deserialize (SerializerIterator& sit, SField::ref name) +STUInt64::deserialize (SerialIter& sit, SField::ref name) { return std::make_unique (name, sit.get64 ()); } diff --git a/src/ripple/protocol/impl/STLedgerEntry.cpp b/src/ripple/protocol/impl/STLedgerEntry.cpp index 41045eebf..fe61efebf 100644 --- a/src/ripple/protocol/impl/STLedgerEntry.cpp +++ b/src/ripple/protocol/impl/STLedgerEntry.cpp @@ -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 (s)); + SerialIter sit (const_cast (s)); set (sit); setSLEType (); } diff --git a/src/ripple/protocol/impl/STObject.cpp b/src/ripple/protocol/impl/STObject.cpp index d7f7dc597..ef58f247f 100644 --- a/src/ripple/protocol/impl/STObject.cpp +++ b/src/ripple/protocol/impl/STObject.cpp @@ -94,7 +94,7 @@ STObject::makeDefaultObject (SerializedTypeID id, SField::ref name) // VFALCO TODO Remove the 'depth' parameter std::unique_ptr 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 -STObject::deserialize (SerializerIterator& sit, SField::ref name) +STObject::deserialize (SerialIter& sit, SField::ref name) { std::unique_ptr object (std::make_unique (name)); object->set (sit, 1); diff --git a/src/ripple/protocol/impl/STPathSet.cpp b/src/ripple/protocol/impl/STPathSet.cpp index 83a506111..275e4fd82 100644 --- a/src/ripple/protocol/impl/STPathSet.cpp +++ b/src/ripple/protocol/impl/STPathSet.cpp @@ -51,7 +51,7 @@ STPathElement::get_hash (STPathElement const& element) } std::unique_ptr -STPathSet::deserialize (SerializerIterator& sit, SField::ref name) +STPathSet::deserialize (SerialIter& sit, SField::ref name) { std::vector path; diff --git a/src/ripple/protocol/impl/STTx.cpp b/src/ripple/protocol/impl/STTx.cpp index 847006264..56061b0b1 100644 --- a/src/ripple/protocol/impl/STTx.cpp +++ b/src/ripple/protocol/impl/STTx.cpp @@ -74,7 +74,7 @@ STTx::STTx (STObject const& object) } } -STTx::STTx (SerializerIterator& sit) +STTx::STTx (SerialIter& sit) : STObject (sfTransaction) , sig_state_ (boost::indeterminate) { diff --git a/src/ripple/protocol/impl/STValidation.cpp b/src/ripple/protocol/impl/STValidation.cpp index 6c6b026a3..0a7a4e9b2 100644 --- a/src/ripple/protocol/impl/STValidation.cpp +++ b/src/ripple/protocol/impl/STValidation.cpp @@ -25,7 +25,7 @@ namespace ripple { -STValidation::STValidation (SerializerIterator& sit, bool checkSignature) +STValidation::STValidation (SerialIter& sit, bool checkSignature) : STObject (getFormat (), sit, sfValidation) , mTrusted (false) { diff --git a/src/ripple/protocol/impl/STVector256.cpp b/src/ripple/protocol/impl/STVector256.cpp index 5bb113b54..6ffec6093 100644 --- a/src/ripple/protocol/impl/STVector256.cpp +++ b/src/ripple/protocol/impl/STVector256.cpp @@ -26,7 +26,7 @@ namespace ripple { std::unique_ptr -STVector256::deserialize (SerializerIterator& sit, SField::ref name) +STVector256::deserialize (SerialIter& sit, SField::ref name) { auto vec = std::make_unique (name); diff --git a/src/ripple/protocol/impl/Serializer.cpp b/src/ripple/protocol/impl/Serializer.cpp index d0c9bff90..2f9a1daf1 100644 --- a/src/ripple/protocol/impl/Serializer.cpp +++ b/src/ripple/protocol/impl/Serializer.cpp @@ -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 (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( + data), len, (unsigned char*) j); + return j[0]; } } // ripple diff --git a/src/ripple/protocol/tests/RippleAddress.test.cpp b/src/ripple/protocol/tests/RippleAddress.test.cpp index ce5923207..fa06fa859 100644 --- a/src/ripple/protocol/tests/RippleAddress.test.cpp +++ b/src/ripple/protocol/tests/RippleAddress.test.cpp @@ -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); diff --git a/src/ripple/protocol/tests/STAmount.test.cpp b/src/ripple/protocol/tests/STAmount.test.cpp index f21d6fd85..6c934d509 100644 --- a/src/ripple/protocol/tests/STAmount.test.cpp +++ b/src/ripple/protocol/tests/STAmount.test.cpp @@ -33,7 +33,7 @@ public: Serializer ser; s.add (ser); - SerializerIterator sit (ser); + SerialIter sit (ser); return STAmount::deserialize (sit); } diff --git a/src/ripple/protocol/tests/STObject.test.cpp b/src/ripple/protocol/tests/STObject.test.cpp index 80e958023..7e03e6982 100644 --- a/src/ripple/protocol/tests/STObject.test.cpp +++ b/src/ripple/protocol/tests/STObject.test.cpp @@ -183,7 +183,7 @@ public: Serializer s; object1.add (s); - SerializerIterator it (s); + SerialIter it (s); STObject object3 (elements, it, sfTestObject); diff --git a/src/ripple/protocol/tests/STTx.test.cpp b/src/ripple/protocol/tests/STTx.test.cpp index f267e89de..de51b1d29 100644 --- a/src/ripple/protocol/tests/STTx.test.cpp +++ b/src/ripple/protocol/tests/STTx.test.cpp @@ -46,7 +46,7 @@ public: Serializer rawTxn; j.add (rawTxn); - SerializerIterator sit (rawTxn); + SerialIter sit (rawTxn); STTx copy (sit); if (copy != j) diff --git a/src/ripple/rpc/handlers/Submit.cpp b/src/ripple/rpc/handlers/Submit.cpp index b5dd55b4c..3fbb8c3bc 100644 --- a/src/ripple/rpc/handlers/Submit.cpp +++ b/src/ripple/rpc/handlers/Submit.cpp @@ -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 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; diff --git a/src/ripple/shamap/SHAMapItem.h b/src/ripple/shamap/SHAMapItem.h index 2c78899ce..51a17628d 100644 --- a/src/ripple/shamap/SHAMapItem.h +++ b/src/ripple/shamap/SHAMapItem.h @@ -39,90 +39,50 @@ public: typedef const std::shared_ptr& ref; public: - explicit SHAMapItem (uint256 const& tag) : mTag (tag) + explicit SHAMapItem (uint256 const& tag) + : mTag (tag) { - ; } - explicit SHAMapItem (Blob const & data); // tag by hash + + // tag computed from hash of data + explicit SHAMapItem (Blob const& data); + SHAMapItem (uint256 const& tag, Blob const & data); - SHAMapItem (uint256 const& tag, const Serializer & s); - uint256 const& getTag () const + 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); diff --git a/src/ripple/shamap/SHAMapTreeNode.h b/src/ripple/shamap/SHAMapTreeNode.h index 3c4934165..397544a86 100644 --- a/src/ripple/shamap/SHAMapTreeNode.h +++ b/src/ripple/shamap/SHAMapTreeNode.h @@ -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: diff --git a/src/ripple/shamap/impl/SHAMap.cpp b/src/ripple/shamap/impl/SHAMap.cpp index 0f36f8d32..6c459b669 100644 --- a/src/ripple/shamap/impl/SHAMap.cpp +++ b/src/ripple/shamap/impl/SHAMap.cpp @@ -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 diff --git a/src/ripple/shamap/impl/SHAMapDelta.cpp b/src/ripple/shamap/impl/SHAMapDelta.cpp index 38d79dd57..71ae48bc3 100644 --- a/src/ripple/shamap/impl/SHAMapDelta.cpp +++ b/src/ripple/shamap/impl/SHAMapDelta.cpp @@ -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) diff --git a/src/ripple/shamap/impl/SHAMapSync.cpp b/src/ripple/shamap/impl/SHAMapSync.cpp index ee101b668..79cc8cb39 100644 --- a/src/ripple/shamap/impl/SHAMapSync.cpp +++ b/src/ripple/shamap/impl/SHAMapSync.cpp @@ -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); diff --git a/src/ripple/shamap/impl/SHAMapTreeNode.cpp b/src/ripple/shamap/impl/SHAMapTreeNode.cpp index 9688c99f7..fcdaa3a57 100644 --- a/src/ripple/shamap/impl/SHAMapTreeNode.cpp +++ b/src/ripple/shamap/impl/SHAMapTreeNode.cpp @@ -185,7 +185,7 @@ SHAMapTreeNode::SHAMapTreeNode (Blob const& rawNode, if (prefix == HashPrefix::transactionID) { - mItem = std::make_shared (Serializer::getSHA512Half (rawNode), s.peekData ()); + mItem = std::make_shared (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 (mItem->peekSerializer ().getDataLength ()); + ret += beast::lexicalCast (mItem->size()); } return ret; diff --git a/src/ripple/shamap/tests/SHAMap.test.cpp b/src/ripple/shamap/tests/SHAMap.test.cpp index 75a6eccd5..97e0e326e 100644 --- a/src/ripple/shamap/tests/SHAMap.test.cpp +++ b/src/ripple/shamap/tests/SHAMap.test.cpp @@ -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: