From 1024af54b6455e35ff7b67d42227477a10050ac7 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sun, 2 Sep 2012 21:32:52 -0700 Subject: [PATCH] Modify RPC and transactions to use quality flags for ripple. --- src/RPCServer.cpp | 59 +++++++++++++++------------------------ src/SerializedTypes.cpp | 4 +-- src/SerializedTypes.h | 6 ++-- src/Transaction.cpp | 10 +++++-- src/Transaction.h | 8 ++++-- src/TransactionEngine.cpp | 9 +++--- src/TransactionFormats.h | 3 +- 7 files changed, 46 insertions(+), 53 deletions(-) diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index 5c47ed30a3..cd79010c4a 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -1316,15 +1316,15 @@ Json::Value RPCServer::doPeers(const Json::Value& params) } // ripple -// [] // XXX [noredeem] [noissue] +// [] // + -// full|partial [] +// full|partial limit|average [] // // path: // path + // // path_element: -// account [] [] [noredeem] [noissue] +// account [] [] // offer [] Json::Value RPCServer::doRipple(const Json::Value ¶ms) { @@ -1333,10 +1333,10 @@ Json::Value RPCServer::doRipple(const Json::Value ¶ms) uint160 uSrcCurrencyID; NewcoinAddress naSrcAccountID; NewcoinAddress naSrcIssuerID; - bool bSrcRedeem = true; - bool bSrcIssue = true; bool bPartial; bool bFull; + bool bLimit; + bool bAverage; NewcoinAddress naDstAccountID; STAmount saDstAmount; uint160 uDstCurrencyID; @@ -1366,18 +1366,6 @@ Json::Value RPCServer::doRipple(const Json::Value ¶ms) int iArg = 4 + naSrcIssuerID.isValid(); - if (params[iArg].asString() == "noredeem") // [noredeem] - { - ++iArg; - bSrcRedeem = false; - } - - if (params[iArg].asString() == "noissue") // [noissue] - { - ++iArg; - bSrcIssue = false; - } - // XXX bSrcRedeem & bSrcIssue not used. STPath spPath; @@ -1417,8 +1405,6 @@ Json::Value RPCServer::doRipple(const Json::Value ¶ms) NewcoinAddress naAccountID; uint160 uCurrencyID; NewcoinAddress naIssuerID; - bool bRedeem = true; - bool bIssue = true; ++iArg; @@ -1437,24 +1423,10 @@ Json::Value RPCServer::doRipple(const Json::Value ¶ms) ++iArg; } - if (params.size() != iArg && params[iArg].asString() == "noredeem") // [noredeem] - { - ++iArg; - bRedeem = false; - } - - if (params.size() != iArg && params[iArg].asString() == "noissue") // [noissue] - { - ++iArg; - bIssue = false; - } - spPath.addElement(STPathElement( naAccountID.getAccountID(), uCurrencyID, - naIssuerID.isValid() ? naIssuerID.getAccountID() : uint160(0), - bRedeem, - bIssue)); + naIssuerID.isValid() ? naIssuerID.getAccountID() : uint160(0))); } else { @@ -1486,6 +1458,19 @@ Json::Value RPCServer::doRipple(const Json::Value ¶ms) ++iArg; } + // limit|average + bLimit = params.size() != iArg ? params[iArg].asString() == "limit" : false; + bAverage = params.size() != iArg ? params[iArg].asString() == "average" : false; + + if (!bPartial && !bFull) + { + return RPCError(rpcINVALID_PARAMS); + } + else + { + ++iArg; + } + if (params.size() != iArg && !naDstAccountID.setAccountID(params[iArg++].asString())) // { return RPCError(rpcDST_ACT_MALFORMED); @@ -1543,7 +1528,9 @@ Json::Value RPCServer::doRipple(const Json::Value ¶ms) naDstAccountID, saDstAmount, saSrcAmountMax, - spsPaths); + spsPaths, + bPartial, + bLimit); trans = mNetOps->submitTransaction(trans); @@ -2564,7 +2551,7 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params { "password_fund", &RPCServer::doPasswordFund, 2, 3, false, optCurrent }, { "password_set", &RPCServer::doPasswordSet, 2, 3, false, optNetwork }, { "peers", &RPCServer::doPeers, 0, 0, true }, - { "ripple", &RPCServer::doRipple, 8, -1, false, optCurrent|optClosed }, + { "ripple", &RPCServer::doRipple, 9, -1, false, optCurrent|optClosed }, { "ripple_lines_get", &RPCServer::doRippleLinesGet, 1, 2, false, optCurrent }, { "ripple_line_set", &RPCServer::doRippleLineSet, 4, 7, false, optCurrent }, { "send", &RPCServer::doSend, 3, 9, false, optCurrent }, diff --git a/src/SerializedTypes.cpp b/src/SerializedTypes.cpp index 16572e5d78..4684345496 100644 --- a/src/SerializedTypes.cpp +++ b/src/SerializedTypes.cpp @@ -332,8 +332,6 @@ STPathSet* STPathSet::construct(SerializerIterator& s, const char *name) else { const bool bAccount = !!(iType & STPathElement::typeAccount); - const bool bRedeem = !!(iType & STPathElement::typeRedeem); - const bool bIssue = !!(iType & STPathElement::typeIssue); const bool bCurrency = !!(iType & STPathElement::typeCurrency); const bool bIssuer = !!(iType & STPathElement::typeIssuer); @@ -350,7 +348,7 @@ STPathSet* STPathSet::construct(SerializerIterator& s, const char *name) if (bIssuer) uIssuerID = s.get160(); - path.push_back(STPathElement(uAccountID, uCurrency, uIssuerID, bRedeem, bIssue)); + path.push_back(STPathElement(uAccountID, uCurrency, uIssuerID)); } } while(1); } diff --git a/src/SerializedTypes.h b/src/SerializedTypes.h index 065c6895d7..4baa4e9b40 100644 --- a/src/SerializedTypes.h +++ b/src/SerializedTypes.h @@ -564,15 +564,13 @@ protected: uint160 mIssuerID; public: - STPathElement(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID, bool bRedeem=false, bool bIssue=false) + STPathElement(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID) : mAccountID(uAccountID), mCurrencyID(uCurrencyID), mIssuerID(uIssuerID) { mType = (uAccountID.isZero() ? 0 : STPathElement::typeAccount) | (uCurrencyID.isZero() ? 0 : STPathElement::typeCurrency) - | (uIssuerID.isZero() ? 0 : STPathElement::typeIssuer) - | (bRedeem ? STPathElement::typeRedeem : 0) - | (bIssue ? STPathElement::typeIssue : 0); + | (uIssuerID.isZero() ? 0 : STPathElement::typeIssuer); } int getNodeType() const { return mType; } diff --git a/src/Transaction.cpp b/src/Transaction.cpp index 38aec72865..00988712d9 100644 --- a/src/Transaction.cpp +++ b/src/Transaction.cpp @@ -489,7 +489,9 @@ Transaction::pointer Transaction::setPayment( const NewcoinAddress& naDstAccountID, const STAmount& saAmount, const STAmount& saSendMax, - const STPathSet& spsPaths) + const STPathSet& spsPaths, + const bool bPartial, + const bool bLimit) { mTransaction->setITFieldAccount(sfDestination, naDstAccountID); mTransaction->setITFieldAmount(sfAmount, saAmount); @@ -518,11 +520,13 @@ Transaction::pointer Transaction::sharedPayment( const NewcoinAddress& naDstAccountID, const STAmount& saAmount, const STAmount& saSendMax, - const STPathSet& spsPaths) + const STPathSet& spsPaths, + const bool bPartial, + const bool bLimit) { pointer tResult = boost::make_shared(ttPAYMENT, naPublicKey, naSourceAccount, uSeq, saFee, uSourceTag); - return tResult->setPayment(naPrivateKey, naDstAccountID, saAmount, saSendMax, spsPaths); + return tResult->setPayment(naPrivateKey, naDstAccountID, saAmount, saSendMax, spsPaths, bPartial, bLimit); } // diff --git a/src/Transaction.h b/src/Transaction.h index 7198ef04ea..1ae8c0aa43 100644 --- a/src/Transaction.h +++ b/src/Transaction.h @@ -116,7 +116,9 @@ private: const NewcoinAddress& naDstAccountID, const STAmount& saAmount, const STAmount& saSendMax, - const STPathSet& spsPaths); + const STPathSet& spsPaths, + const bool bPartial, + const bool bLimit); Transaction::pointer setWalletAdd( const NewcoinAddress& naPrivateKey, @@ -231,7 +233,9 @@ public: const NewcoinAddress& naDstAccountID, const STAmount& saAmount, const STAmount& saSendMax, - const STPathSet& spsPaths); + const STPathSet& spsPaths, + const bool bPartial = false, + const bool bLimit = false); // Place an offer. static Transaction::pointer sharedOfferCreate( diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp index b7cc2200d2..947b53f50d 100644 --- a/src/TransactionEngine.cpp +++ b/src/TransactionEngine.cpp @@ -2770,11 +2770,12 @@ TER TransactionEngine::calcNodeAccountRev(const unsigned int uIndex, const PathS return terResult; } -// The previous node: specifies what to push through to current. +// Perfrom balance adjustments between previous and current node. +// - The previous node: specifies what to push through to current. // - All of previous output is consumed. -// The current node: specify what to push through to next. -// - Output to next node minus fees. -// Perform balance adjustment with previous. +// Then, compute output for next node. +// - Current node: specify what to push through to next. +// - Output to next node is computed as input minus quality or transfer fee. TER TransactionEngine::calcNodeAccountFwd( const unsigned int uIndex, // 0 <= uIndex <= uLast const PathState::pointer& pspCur, diff --git a/src/TransactionFormats.h b/src/TransactionFormats.h index a49a1513e1..6aadec3a68 100644 --- a/src/TransactionFormats.h +++ b/src/TransactionFormats.h @@ -45,7 +45,8 @@ const uint32 tfPassive = 0x00010000; // Payment flags: const uint32 tfCreateAccount = 0x00010000; const uint32 tfPartialPayment = 0x00020000; -const uint32 tfNoRippleDirect = 0x00040000; +const uint32 tfLimitQuality = 0x00040000; +const uint32 tfNoRippleDirect = 0x00080000; extern TransactionFormat InnerTxnFormats[]; extern TransactionFormat* getTxnFormat(TransactionType t);