From 5ff5e7669d17df9f0cc6ef4e2d1097d351ad33ed Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Tue, 2 Oct 2012 16:22:03 -0700 Subject: [PATCH] RPC: add profile command. --- src/RPCServer.cpp | 132 ++++++++++++++++++++++++++++++++++++-- src/RPCServer.h | 1 + src/Transaction.cpp | 4 +- src/TransactionAction.cpp | 14 +++- 4 files changed, 141 insertions(+), 10 deletions(-) diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index ef0feb4933..587e70cc0e 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -318,7 +319,7 @@ Json::Value RPCServer::authorize(const uint256& uLedger, { naMasterAccountPublic.setAccountPublic(naMasterGenerator, iIndex); - Log(lsINFO) << "authorize: " << iIndex << " : " << naMasterAccountPublic.humanAccountID() << " : " << naSrcAccountID.humanAccountID(); + Log(lsDEBUG) << "authorize: " << iIndex << " : " << naMasterAccountPublic.humanAccountID() << " : " << naSrcAccountID.humanAccountID(); bFound = naSrcAccountID.getAccountID() == naMasterAccountPublic.getAccountID(); if (!bFound) @@ -355,13 +356,10 @@ Json::Value RPCServer::authorize(const uint256& uLedger, } else { - Log(lsINFO) << "authorize: before: fee=" << saFee.getFullText() << " balance=" << saSrcBalance.getFullText(); saSrcBalance -= saFee; - Log(lsINFO) << "authorize: after: fee=" << saFee.getFullText() << " balance=" << saSrcBalance.getFullText(); } - Json::Value obj; - return obj; + return Json::Value(); } // --> strIdent: public key, account ID, or regular seed. @@ -1304,6 +1302,122 @@ Json::Value RPCServer::doPeers(const Json::Value& params) return obj; } +// profile offers [submit] +// profile 0:offers 1:pass_a 2:account_a 3:currency_offer_a 4:pass_b 5:account_b 6:currency_offer_b 7: 8:[submit] +// issuer is the offering account +// the amount of each offer will be 1. +// --> count: defaults to 100 +// --> submit: 'submit|true|false': defaults to false +// Prior to running allow each to have a credit line of what they will be getting from the other account. +Json::Value RPCServer::doProfile(const Json::Value ¶ms) +{ + int iArgs = params.size(); + NewcoinAddress naSeedA; + NewcoinAddress naAccountA; + uint160 uCurrencyOfferA; + NewcoinAddress naSeedB; + NewcoinAddress naAccountB; + uint160 uCurrencyOfferB; + uint32 iCount = 100; + bool bSubmit = false; + + if (iArgs < 7 || "offers" != params[0u].asString()) + { + return RPCError(rpcINVALID_PARAMS); + } + + if (!naSeedA.setSeedGeneric(params[1u].asString())) // + return RPCError(rpcINVALID_PARAMS); + + naAccountA.setAccountID(params[2u].asString()); // + + if (!STAmount::currencyFromString(uCurrencyOfferA, params[3u].asString())) // + return RPCError(rpcINVALID_PARAMS); + + if (!naSeedB.setSeedGeneric(params[4u].asString())) // + return RPCError(rpcINVALID_PARAMS); + + naAccountB.setAccountID(params[5u].asString()); // + if (!STAmount::currencyFromString(uCurrencyOfferB, params[6u].asString())) // + return RPCError(rpcINVALID_PARAMS); + + if (iArgs >= 8) + iCount = lexical_cast_s(params[7u].asString()); + + if (iArgs >= 9 && "false" != params[8u].asString()) + bSubmit = true; + + boost::posix_time::ptime ptStart(boost::posix_time::microsec_clock::local_time()); + + for (int i = iCount; i-- >= 0;) { + NewcoinAddress naMasterGeneratorA; + NewcoinAddress naAccountPublicA; + NewcoinAddress naAccountPrivateA; + AccountState::pointer asSrcA; + STAmount saSrcBalanceA; + Json::Value jvObjA = authorize(uint256(0), naSeedA, naAccountA, naAccountPublicA, naAccountPrivateA, + saSrcBalanceA, theConfig.FEE_DEFAULT, asSrcA, naMasterGeneratorA); + + if (!jvObjA.empty()) + return jvObjA; + + Transaction::pointer tpOfferA = Transaction::sharedOfferCreate( + naAccountPublicA, naAccountPrivateA, + naAccountA, // naSourceAccount, + asSrcA->getSeq(), // uSeq + theConfig.FEE_DEFAULT, + 0, // uSourceTag, + false, // bPassive + STAmount(uCurrencyOfferA, naAccountA.getAccountID(), 1), // saTakerPays + STAmount(uCurrencyOfferB, naAccountB.getAccountID(), 1), // saTakerGets + 0); // uExpiration + + if (bSubmit) + tpOfferA = mNetOps->submitTransaction(tpOfferA); + + NewcoinAddress naMasterGeneratorB; + NewcoinAddress naAccountPublicB; + NewcoinAddress naAccountPrivateB; + AccountState::pointer asSrcB; + STAmount saSrcBalanceB; + Json::Value jvObjB = authorize(uint256(0), naSeedB, naAccountB, naAccountPublicB, naAccountPrivateB, + saSrcBalanceB, theConfig.FEE_DEFAULT, asSrcB, naMasterGeneratorB); + + if (!jvObjB.empty()) + return jvObjB; + + Transaction::pointer tpOfferB = Transaction::sharedOfferCreate( + naAccountPublicB, naAccountPrivateB, + naAccountB, // naSourceAccount, + asSrcB->getSeq(), // uSeq + theConfig.FEE_DEFAULT, + 0, // uSourceTag, + false, // bPassive + STAmount(uCurrencyOfferB, naAccountB.getAccountID(), 1), // saTakerPays + STAmount(uCurrencyOfferA, naAccountA.getAccountID(), 1), // saTakerGets + 0); // uExpiration + + if (bSubmit) + tpOfferB = mNetOps->submitTransaction(tpOfferB); + } + + boost::posix_time::ptime ptEnd(boost::posix_time::microsec_clock::local_time()); + boost::posix_time::time_duration tdInterval = ptEnd-ptStart; + long lMilliseconds = tdInterval.total_milliseconds(); + float fRate = lMilliseconds ? iCount/(lMilliseconds/1000000.0) : 0.0; + + Json::Value obj(Json::objectValue); + + obj["count"] = iCount; + obj["sumbit"] = bSubmit; + obj["start"] = boost::posix_time::to_simple_string(ptStart); + obj["end"] = boost::posix_time::to_simple_string(ptEnd); + obj["interval"] = boost::posix_time::to_simple_string(tdInterval); + obj["rate_per_second"] = fRate; + + return obj; +} + // ripple // [] // + @@ -1701,6 +1815,9 @@ Json::Value RPCServer::doSend(const Json::Value& params) if (params.size() >= 8) sSrcIssuer = params[7u].asString(); + if (params.size() >= 9) + sSrcIssuer = params[8u].asString(); + if (!naSeed.setSeedGeneric(params[0u].asString())) { return RPCError(rpcBAD_SEED); @@ -1717,7 +1834,7 @@ Json::Value RPCServer::doSend(const Json::Value& params) { return RPCError(rpcDST_AMT_MALFORMED); } - else if (params.size() >= 7 && !saSrcAmountMax.setFullValue(params[5u].asString(), sSrcCurrency, sSrcIssuer)) + else if (params.size() >= 7 && !saSrcAmountMax.setFullValue(params[6u].asString(), sSrcCurrency, sSrcIssuer)) { return RPCError(rpcSRC_AMT_MALFORMED); } @@ -2539,7 +2656,7 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params { "data_fetch", &RPCServer::doDataFetch, 1, 1, true }, { "data_store", &RPCServer::doDataStore, 2, 2, true }, { "ledger", &RPCServer::doLedger, 0, 2, false, optNetwork }, - { "logrotate", &RPCServer::doLogRotate, 0, 0, true, 0 }, + { "logrotate", &RPCServer::doLogRotate, 0, 0, true }, { "nickname_info", &RPCServer::doNicknameInfo, 1, 1, false, optCurrent }, { "nickname_set", &RPCServer::doNicknameSet, 2, 3, false, optCurrent }, { "offer_create", &RPCServer::doOfferCreate, 9, 10, false, optCurrent }, @@ -2548,6 +2665,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 }, + { "profile", &RPCServer::doProfile, 1, 9, false, optCurrent }, { "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 }, diff --git a/src/RPCServer.h b/src/RPCServer.h index 8d56ed55aa..d203cbc3ca 100644 --- a/src/RPCServer.h +++ b/src/RPCServer.h @@ -149,6 +149,7 @@ private: Json::Value doOwnerInfo(const Json::Value& params); Json::Value doPasswordFund(const Json::Value& params); Json::Value doPasswordSet(const Json::Value& params); + Json::Value doProfile(const Json::Value& params); Json::Value doPeers(const Json::Value& params); Json::Value doRipple(const Json::Value ¶ms); Json::Value doRippleLinesGet(const Json::Value ¶ms); diff --git a/src/Transaction.cpp b/src/Transaction.cpp index 76bd2a9408..e56e12f0f0 100644 --- a/src/Transaction.cpp +++ b/src/Transaction.cpp @@ -68,8 +68,8 @@ Transaction::Transaction( mTransaction = boost::make_shared(ttKind); - Log(lsINFO) << str(boost::format("Transaction: account: %s") % naSourceAccount.humanAccountID()); - Log(lsINFO) << str(boost::format("Transaction: mAccountFrom: %s") % mAccountFrom.humanAccountID()); + // Log(lsINFO) << str(boost::format("Transaction: account: %s") % naSourceAccount.humanAccountID()); + // Log(lsINFO) << str(boost::format("Transaction: mAccountFrom: %s") % mAccountFrom.humanAccountID()); mTransaction->setSigningPubKey(mFromPubKey); mTransaction->setSourceAccount(mAccountFrom); diff --git a/src/TransactionAction.cpp b/src/TransactionAction.cpp index acdeacadb9..bf96f344f8 100644 --- a/src/TransactionAction.cpp +++ b/src/TransactionAction.cpp @@ -727,7 +727,7 @@ TER TransactionEngine::takeOffers( // Figure out next offer to take, if needed. if (saTakerGets != saTakerGot && saTakerPays != saTakerPaid) { - // Taker has needs. + // Taker, still, needs to get and pay. sleOfferDir = entryCache(ltDIR_NODE, mLedger->getNextLedgerIndex(uTipIndex, uBookEnd)); if (sleOfferDir) @@ -832,7 +832,19 @@ TER TransactionEngine::takeOffers( Log(lsINFO) << "takeOffers: applyOffer: saOfferGets: " << saOfferGets.getFullText(); Log(lsINFO) << "takeOffers: applyOffer: saTakerPays: " << saTakerPays.getFullText(); Log(lsINFO) << "takeOffers: applyOffer: saTakerGets: " << saTakerGets.getFullText(); +#if 0 + STAmount saTakerPaysRate = + uTakerPaysAccountID == uTakerAccountID // Taker is issuing, no fee. + || uTakerPaysAccountID == uOfferAccountID // Taker is redeeming, no fee. + ? 0.0 + : getRate(uTakerPaysAccountID); + STAmount saOfferPaysRate = + uTakerGetsAccountID == uTakerGetsAccountID // Offerer is redeeming, no fee. + || uTakerGetsAccountID == uOfferAccountID // Offerer is issuing, no fee. + ? 0.0 + : getRate(uTakerGetsAccountID); +#endif bool bOfferDelete = STAmount::applyOffer( saOfferFunds, saPay, // Driver XXX need to account for fees.