From 8edff633d23f15a051acfdb8bd2b56e336f3a034 Mon Sep 17 00:00:00 2001 From: jed Date: Sat, 24 Nov 2012 11:21:18 -0800 Subject: [PATCH 1/3] meta for transaction stream --- src/cpp/ripple/NetworkOPs.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index 97adc8e9f2..8272c2c061 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -1076,6 +1076,7 @@ Json::Value NetworkOPs::transJson(const SerializedTransaction& stTxn, TER terRes void NetworkOPs::pubAcceptedTransaction(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult,TransactionMetaSet::pointer& meta) { Json::Value jvObj = transJson(stTxn, terResult, true, lpCurrent, "transaction"); + if(meta) jvObj["meta"]=meta->getJson(0); { boost::recursive_mutex::scoped_lock sl(mMonitorLock); From e90a1a404d4274845b69d2b01aa6c792d125375a Mon Sep 17 00:00:00 2001 From: jed Date: Wed, 28 Nov 2012 16:29:15 -0800 Subject: [PATCH 2/3] still working --- src/cpp/ripple/NetworkOPs.cpp | 9 ++++++--- src/cpp/ripple/NetworkOPs.h | 2 +- src/cpp/ripple/RPCHandler.cpp | 13 +++++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index 97adc8e9f2..368f59bfeb 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -876,14 +876,15 @@ void NetworkOPs::setMode(OperatingMode om) mMode = om; } + std::vector< std::pair > - NetworkOPs::getAffectedAccounts(const RippleAddress& account, uint32 minLedger, uint32 maxLedger) + NetworkOPs::getAccountTxs(const RippleAddress& account, uint32 minLedger, uint32 maxLedger) { std::vector< std::pair > affectedAccounts; std::string sql = - str(boost::format("SELECT LedgerSeq,TransID FROM AccountTransactions INDEXED BY AcctTxIndex " - " WHERE Account = '%s' AND LedgerSeq <= '%d' AND LedgerSeq >= '%d' ORDER BY LedgerSeq LIMIT 1000;") + str(boost::format("SELECT LedgerSeq,Status,RawTxn,TxnMeta FROM Transactions where TransID in (SELECT TransID from AccountTransactions " + " WHERE Account = '%s' AND LedgerSeq <= '%d' AND LedgerSeq >= '%d' LIMIT 1000) ORDER BY LedgerSeq;") % account.humanAccountID() % maxLedger % minLedger); { @@ -892,6 +893,7 @@ std::vector< std::pair > SQL_FOREACH(db, sql) { + affectedAccounts.push_back(std::make_pair(db->getInt("LedgerSeq"), uint256(db->getStrBinary("TransID")))); } } @@ -1076,6 +1078,7 @@ Json::Value NetworkOPs::transJson(const SerializedTransaction& stTxn, TER terRes void NetworkOPs::pubAcceptedTransaction(Ledger::ref lpCurrent, const SerializedTransaction& stTxn, TER terResult,TransactionMetaSet::pointer& meta) { Json::Value jvObj = transJson(stTxn, terResult, true, lpCurrent, "transaction"); + if(meta) jvObj["meta"]=meta->getJson(0); { boost::recursive_mutex::scoped_lock sl(mMonitorLock); diff --git a/src/cpp/ripple/NetworkOPs.h b/src/cpp/ripple/NetworkOPs.h index 3878689dd8..191a21131a 100644 --- a/src/cpp/ripple/NetworkOPs.h +++ b/src/cpp/ripple/NetworkOPs.h @@ -231,7 +231,7 @@ public: // client information retrieval functions std::vector< std::pair > - getAffectedAccounts(const RippleAddress& account, uint32 minLedger, uint32 maxLedger); + getAccountTxs(const RippleAddress& account, uint32 minLedger, uint32 maxLedger); std::vector getLedgerAffectedAccounts(uint32 ledgerSeq); std::vector getLedgerTransactions(uint32 ledgerSeq); diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 1765efcdf2..22be44e000 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1292,14 +1292,20 @@ Json::Value RPCHandler::doAccountTransactions(const Json::Value& params) try { #endif - std::vector< std::pair > txns = mNetOps->getAffectedAccounts(account, minLedger, maxLedger); + std::vector< std::pair > txns = mNetOps->getAccountTxs(account, minLedger, maxLedger); Json::Value ret(Json::objectValue); ret["account"] = account.humanAccountID(); Json::Value ledgers(Json::arrayValue); // uint32 currentLedger = 0; - for (std::vector< std::pair >::iterator it = txns.begin(), end = txns.end(); it != end; ++it) + for (std::vector< std::pair >::iterator it = txns.begin(), end = txns.end(); it != end; ++it) { + Json::objectValue obj; + obj["tx"]=it->first->getJson(1); + obj["meta"]=it->second->getJson(0); + ret["transactions"].append(obj); + + Transaction::pointer txn = theApp->getMasterTransaction().fetch(it->second, true); if (!txn) { @@ -1309,6 +1315,9 @@ Json::Value RPCHandler::doAccountTransactions(const Json::Value& params) { txn->setLedger(it->first); ret["transactions"].append(txn->getJson(1)); + + TransactionMetaSet::pointer meta = boost::make_shared( + stTxn.getTransactionID(), lpAccepted->getLedgerSeq(), it.getVL()); } } From 32c231ab574ec668a176fa20626ad785121d4bfc Mon Sep 17 00:00:00 2001 From: jed Date: Thu, 29 Nov 2012 09:22:44 -0800 Subject: [PATCH 3/3] add meta to account_tx --- src/cpp/ripple/NetworkOPs.cpp | 22 +++++++++++++++++----- src/cpp/ripple/NetworkOPs.h | 2 +- src/cpp/ripple/RPCHandler.cpp | 22 +++------------------- src/cpp/ripple/Transaction.cpp | 1 + 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index 368f59bfeb..00eba875b9 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -877,10 +877,10 @@ void NetworkOPs::setMode(OperatingMode om) } -std::vector< std::pair > +std::vector< std::pair > NetworkOPs::getAccountTxs(const RippleAddress& account, uint32 minLedger, uint32 maxLedger) { - std::vector< std::pair > affectedAccounts; + std::vector< std::pair > ret; std::string sql = str(boost::format("SELECT LedgerSeq,Status,RawTxn,TxnMeta FROM Transactions where TransID in (SELECT TransID from AccountTransactions " @@ -893,12 +893,24 @@ std::vector< std::pair > SQL_FOREACH(db, sql) { - - affectedAccounts.push_back(std::make_pair(db->getInt("LedgerSeq"), uint256(db->getStrBinary("TransID")))); + Transaction::pointer txn=Transaction::transactionFromSQL(db,false); + + Serializer rawMeta; + int metaSize = 2048; + rawMeta.resize(metaSize); + metaSize = db->getBinary("RawTxn", &*rawMeta.begin(), rawMeta.getLength()); + if (metaSize > rawMeta.getLength()) + { + rawMeta.resize(metaSize); + db->getBinary("RawTxn", &*rawMeta.begin(), rawMeta.getLength()); + }else rawMeta.resize(metaSize); + + TransactionMetaSet::pointer meta= boost::make_shared(txn->getID(), txn->getLedger(), rawMeta.getData()); + ret.push_back(std::make_pair(txn,meta)); } } - return affectedAccounts; + return ret; } std::vector diff --git a/src/cpp/ripple/NetworkOPs.h b/src/cpp/ripple/NetworkOPs.h index 191a21131a..78d6aaabe7 100644 --- a/src/cpp/ripple/NetworkOPs.h +++ b/src/cpp/ripple/NetworkOPs.h @@ -230,7 +230,7 @@ public: uint256 getConsensusLCL(); // client information retrieval functions - std::vector< std::pair > + std::vector< std::pair > getAccountTxs(const RippleAddress& account, uint32 minLedger, uint32 maxLedger); std::vector getLedgerAffectedAccounts(uint32 ledgerSeq); std::vector getLedgerTransactions(uint32 ledgerSeq); diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 22be44e000..f28593b0f5 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1300,26 +1300,10 @@ Json::Value RPCHandler::doAccountTransactions(const Json::Value& params) // uint32 currentLedger = 0; for (std::vector< std::pair >::iterator it = txns.begin(), end = txns.end(); it != end; ++it) { - Json::objectValue obj; - obj["tx"]=it->first->getJson(1); - obj["meta"]=it->second->getJson(0); + Json::Value obj(Json::objectValue); + if(it->first) obj["tx"]=it->first->getJson(1); + if(it->second) obj["meta"]=it->second->getJson(0); ret["transactions"].append(obj); - - - Transaction::pointer txn = theApp->getMasterTransaction().fetch(it->second, true); - if (!txn) - { - ret["transactions"].append(it->second.GetHex()); - } - else - { - txn->setLedger(it->first); - ret["transactions"].append(txn->getJson(1)); - - TransactionMetaSet::pointer meta = boost::make_shared( - stTxn.getTransactionID(), lpAccepted->getLedgerSeq(), it.getVL()); - } - } return ret; #ifndef DEBUG diff --git a/src/cpp/ripple/Transaction.cpp b/src/cpp/ripple/Transaction.cpp index 304494826c..2f35595754 100644 --- a/src/cpp/ripple/Transaction.cpp +++ b/src/cpp/ripple/Transaction.cpp @@ -245,6 +245,7 @@ Transaction::pointer Transaction::transactionFromSQL(const std::string& sql) return tr; } + Transaction::pointer Transaction::load(const uint256& id) { std::string sql = "SELECT LedgerSeq,Status,RawTxn FROM Transactions WHERE TransID='";