diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index 92ab2f7c5f..e1d0f9cd7a 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -1065,66 +1065,76 @@ Json::Value NetworkOPs::transJson(const SerializedTransaction& stTxn, TER terRes return jvObj; } -void NetworkOPs::pubTransactionAll(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult, bool bAccepted) +void NetworkOPs::pubAcceptedTransaction(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult) { - Json::Value jvObj = transJson(stTxn, terResult, bAccepted, lpCurrent, "transaction"); + Json::Value jvObj = transJson(stTxn, terResult, true, lpCurrent, "transaction"); - BOOST_FOREACH(InfoSub* ispListener, mSubTransactions) { - ispListener->send(jvObj); + boost::interprocess::sharable_lock sl(mMonitorLock); + BOOST_FOREACH(InfoSub* ispListener, mSubTransactions) + { + ispListener->send(jvObj); + } + + BOOST_FOREACH(InfoSub* ispListener, mSubRTTransactions) + { + ispListener->send(jvObj); + } } + + pubAccountTransaction(lpCurrent,stTxn,terResult,true); } -void NetworkOPs::pubTransactionAccounts(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult, bool bAccepted) + +void NetworkOPs::pubAccountTransaction(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult, bool bAccepted) { - boost::unordered_set usisNotify; + boost::unordered_set notify; { boost::interprocess::sharable_lock sl(mMonitorLock); - if (!mSubAccountTransaction.empty()) + if(!bAccepted && mSubRTAccount.empty()) return; + + if (!mSubAccount.empty() || (!mSubRTAccount.empty()) ) { BOOST_FOREACH(const RippleAddress& naAccountPublic, stTxn.getAffectedAccounts()) { - subInfoMapIterator simiIt = mSubAccountTransaction.find(naAccountPublic.getAccountID()); + subInfoMapIterator simiIt = mSubRTAccount.find(naAccountPublic.getAccountID()); - if (simiIt != mSubAccountTransaction.end()) + if (simiIt != mSubRTAccount.end()) { BOOST_FOREACH(InfoSub* ispListener, simiIt->second) { - usisNotify.insert(ispListener); + notify.insert(ispListener); + } + } + if(bAccepted) + { + simiIt = mSubAccount.find(naAccountPublic.getAccountID()); + + if (simiIt != mSubAccount.end()) + { + BOOST_FOREACH(InfoSub* ispListener, simiIt->second) + { + notify.insert(ispListener); + } } } } } } - if (!usisNotify.empty()) + if (!notify.empty()) { Json::Value jvObj = transJson(stTxn, terResult, bAccepted, lpCurrent, "account"); - BOOST_FOREACH(InfoSub* ispListener, usisNotify) + BOOST_FOREACH(InfoSub* ispListener, notify) { ispListener->send(jvObj); } } } -void NetworkOPs::pubTransaction(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult) -{ - boost::interprocess::sharable_lock sl(mMonitorLock); - - if (!mSubTransactions.empty()) - { - pubTransactionAll(lpCurrent, stTxn, terResult, false); - } - - if (!mSubAccountTransaction.empty()) - { - pubTransactionAccounts(lpCurrent, stTxn, terResult, false); - } -} - // // Monitoring // diff --git a/src/NetworkOPs.h b/src/NetworkOPs.h index 30d526edde..02d5f657e8 100644 --- a/src/NetworkOPs.h +++ b/src/NetworkOPs.h @@ -80,19 +80,17 @@ protected: boost::unordered_set mSubTransactions; // all accepted transactions boost::unordered_set mSubRTTransactions; // all proposed and accepted transactions - subInfoMapType mSubAccountTransaction; // DEPRECATED - subInfoMapType mBootAccountInfo; // DEPRECATED - subInfoMapType mSubAccountInfo; // DEPRECATED void setMode(OperatingMode); Json::Value transJson(const SerializedTransaction& stTxn, TER terResult, bool bAccepted, Ledger::ref lpCurrent, const std::string& strType); - void pubTransactionAll(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult, bool bAccepted); - void pubTransactionAccounts(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult, bool bAccepted); bool haveConsensusObject(); Json::Value pubBootstrapAccountInfo(Ledger::ref lpAccepted, const RippleAddress& naAccountID); + void pubAcceptedTransaction(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult); + void pubAccountTransaction(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult,bool accepted); + public: NetworkOPs(boost::asio::io_service& io_service, LedgerMaster* pLedgerMaster); @@ -212,10 +210,9 @@ public: // // Monitoring: publisher side // - - void pubAccountInfo(const RippleAddress& naAccountID, const Json::Value& jvObj); void pubLedger(Ledger::ref lpAccepted); - void pubTransaction(Ledger::ref lpLedger, const SerializedTransaction& stTxn, TER terResult); + void pubProposedTransaction(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult, bool bAccepted); + // // Monitoring: subscriber side diff --git a/src/RPCHandler.cpp b/src/RPCHandler.cpp index b8eb1c28ac..11eed42d16 100644 --- a/src/RPCHandler.cpp +++ b/src/RPCHandler.cpp @@ -1624,8 +1624,6 @@ Json::Value RPCHandler::doSubmit(const Json::Value& params) Json::Value RPCHandler::handleJSONSubmit(std::string& key, Json::Value& txJSON) { - return rpcError(rpcSRC_ACT_MALFORMED); - /* Json::Value jvResult; RippleAddress naSeed; RippleAddress naAccount; @@ -1636,11 +1634,11 @@ Json::Value RPCHandler::handleJSONSubmit(std::string& key, Json::Value& txJSON) } if (!txJSON.isMember("Account")) { - return rpcError(rpcBAD_SEED); + return rpcError(rpcSRC_ACT_MISSING); } if (!naAccount.setAccountID(txJSON["Account"].asString())) { - return rpcError(rpcBAD_SEED); + return rpcError(rpcSRC_ACT_MISSING); } @@ -1650,7 +1648,7 @@ Json::Value RPCHandler::handleJSONSubmit(std::string& key, Json::Value& txJSON) if (!sleAccountRoot) { // XXX Ignore transactions for accounts not created. - return rpcError(rpcBAD_SEED); + return rpcError(rpcSRC_ACT_MISSING); } bool bHaveAuthKey = false; @@ -1680,7 +1678,7 @@ Json::Value RPCHandler::handleJSONSubmit(std::string& key, Json::Value& txJSON) if (!bFound) { - return rpcError(rpcBAD_SEED); + return rpcError(rpcSRC_ACT_MISSING); } // Use the generator to determine the associated public and private keys. @@ -1698,96 +1696,93 @@ Json::Value RPCHandler::handleJSONSubmit(std::string& key, Json::Value& txJSON) // std::cerr << "sfAuthorizedKey: " << strHex(asSrc->getAuthorizedKey().getAccountID()) << std::endl; // std::cerr << "naAccountPublic: " << strHex(naAccountPublic.getAccountID()) << std::endl; - return rpcError(rpcBAD_SEED); + return rpcError(rpcSRC_ACT_MISSING); } - std::auto_ptr sopTrans; + std::auto_ptr sopTrans; - try - { - sopTrans = STObject::parseJson(jvRequest["transaction"]); - } - catch (std::exception& e) - { - jvResult["error"] = "malformedTransaction"; - jvResult["error_exception"] = e.what(); - return; - } + try + { + sopTrans = STObject::parseJson(txJSON); + } + catch (std::exception& e) + { + jvResult["error"] = "malformedTransaction"; + jvResult["error_exception"] = e.what(); + return(jvResult); + } - sopTrans->setFieldVL(sfSigningPubKey, naAccountPublic.getAccountPublic()); + sopTrans->setFieldVL(sfSigningPubKey, naAccountPublic.getAccountPublic()); - SerializedTransaction::pointer stpTrans; + SerializedTransaction::pointer stpTrans; - try - { - stpTrans = boost::make_shared(*sopTrans); - } - catch (std::exception& e) - { + try + { + stpTrans = boost::make_shared(*sopTrans); + } + catch (std::exception& e) + { + jvResult["error"] = "invalidTransaction"; + jvResult["error_exception"] = e.what(); + return jvResult; + } + + stpTrans->sign(naAccountPrivate); + + Transaction::pointer tpTrans; + + try + { + tpTrans = boost::make_shared(stpTrans, false); + } + catch (std::exception& e) + { + jvResult["error"] = "internalTransaction"; + jvResult["error_exception"] = e.what(); + return(jvResult); + } + + try + { + tpTrans = mNetOps->submitTransaction(tpTrans); + + if (!tpTrans) { jvResult["error"] = "invalidTransaction"; - jvResult["error_exception"] = e.what(); - return jvResult; - } - - stpTrans->sign(naAccountPrivate); - - Transaction::pointer tpTrans; - - try - { - tpTrans = boost::make_shared(stpTrans, false); - } - catch (std::exception& e) - { - jvResult["error"] = "internalTransaction"; - jvResult["error_exception"] = e.what(); - return(jvResult); - } - - try - { - tpTrans = mNetwork.submitTransaction(tpTrans); - - if (!tpTrans) { - jvResult["error"] = "invalidTransaction"; - jvResult["error_exception"] = "Unable to sterilize transaction."; - return(jvResult); - } - } - catch (std::exception& e) - { - jvResult["error"] = "internalSubmit"; - jvResult["error_exception"] = e.what(); - return(jvResult); - } - - try - { - jvResult["transaction"] = tpTrans->getJson(0); - - if (temUNCERTAIN != tpTrans->getResult()) - { - std::string sToken; - std::string sHuman; - - transResultInfo(tpTrans->getResult(), sToken, sHuman); - - jvResult["engine_result"] = sToken; - jvResult["engine_result_code"] = tpTrans->getResult(); - jvResult["engine_result_message"] = sHuman; - } - return(jvResult); - } - catch (std::exception& e) - { - jvResult["error"] = "internalJson"; - jvResult["error_exception"] = e.what(); + jvResult["error_exception"] = "Unable to sterilize transaction."; return(jvResult); } } + catch (std::exception& e) + { + jvResult["error"] = "internalSubmit"; + jvResult["error_exception"] = e.what(); + return(jvResult); + } - */ - + try + { + jvResult["transaction"] = tpTrans->getJson(0); + + if (temUNCERTAIN != tpTrans->getResult()) + { + std::string sToken; + std::string sHuman; + + transResultInfo(tpTrans->getResult(), sToken, sHuman); + + jvResult["engine_result"] = sToken; + jvResult["engine_result_code"] = tpTrans->getResult(); + jvResult["engine_result_message"] = sHuman; + } + return(jvResult); + } + catch (std::exception& e) + { + jvResult["error"] = "internalJson"; + jvResult["error_exception"] = e.what(); + return(jvResult); + } + } // send regular_seed paying_account account_id amount [currency] [issuer] [send_max] [send_currency] [send_issuer]