Modify RPC and transactions to use quality flags for ripple.

This commit is contained in:
Arthur Britto
2012-09-02 21:32:52 -07:00
parent 9329604836
commit 1024af54b6
7 changed files with 46 additions and 53 deletions

View File

@@ -1316,15 +1316,15 @@ Json::Value RPCServer::doPeers(const Json::Value& params)
}
// ripple <regular_seed> <paying_account>
// <source_max> <source_currency> [<source_issuerID>] // XXX [noredeem] [noissue]
// <source_max> <source_currency> [<source_issuerID>]
// <path>+
// full|partial <dest_account> <dest_amount> <dest_currency> [<dest_issuerID>]
// full|partial limit|average <dest_account> <dest_amount> <dest_currency> [<dest_issuerID>]
//
// path:
// path <path_element>+
//
// path_element:
// account <accountID> [<currency>] [<issuerID>] [noredeem] [noissue]
// account <accountID> [<currency>] [<issuerID>]
// offer <currency> [<issuerID>]
Json::Value RPCServer::doRipple(const Json::Value &params)
{
@@ -1333,10 +1333,10 @@ Json::Value RPCServer::doRipple(const Json::Value &params)
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 &params)
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 &params)
NewcoinAddress naAccountID;
uint160 uCurrencyID;
NewcoinAddress naIssuerID;
bool bRedeem = true;
bool bIssue = true;
++iArg;
@@ -1437,24 +1423,10 @@ Json::Value RPCServer::doRipple(const Json::Value &params)
++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 &params)
++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())) // <dest_account>
{
return RPCError(rpcDST_ACT_MALFORMED);
@@ -1543,7 +1528,9 @@ Json::Value RPCServer::doRipple(const Json::Value &params)
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 },

View File

@@ -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);
}

View File

@@ -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; }

View File

@@ -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<Transaction>(ttPAYMENT, naPublicKey, naSourceAccount, uSeq, saFee, uSourceTag);
return tResult->setPayment(naPrivateKey, naDstAccountID, saAmount, saSendMax, spsPaths);
return tResult->setPayment(naPrivateKey, naDstAccountID, saAmount, saSendMax, spsPaths, bPartial, bLimit);
}
//

View File

@@ -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(

View File

@@ -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,

View File

@@ -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);