Transaction::pointer Transaction::load (uint256 const& id) { std::string sql = "SELECT LedgerSeq,Status,RawTxn " "FROM Transactions WHERE TransID='"; sql.append (to_string (id)); sql.append ("';"); boost::optional<std::uint64_t> ledgerSeq; boost::optional<std::string> status; Blob rawTxn; { auto db = getApp().getTxnDB ().checkoutDb (); soci::blob sociRawTxnBlob (*db); soci::indicator rti; *db << sql, soci::into (ledgerSeq), soci::into (status), soci::into (sociRawTxnBlob, rti); if (!db->got_data () || rti != soci::i_ok) return {}; convert(sociRawTxnBlob, rawTxn); } return Transaction::transactionFromSQL ( ledgerSeq, status, rawTxn, Validate::YES); }
// { // start: <index> // } Json::Value doTxHistory (RPC::Context& context) { context.loadType = Resource::feeMediumBurdenRPC; if (!context.params.isMember (jss::start)) return rpcError (rpcINVALID_PARAMS); unsigned int startIndex = context.params[jss::start].asUInt (); if ((startIndex > 10000) && (! isUnlimited (context.role))) return rpcError (rpcNO_PERMISSION); Json::Value obj; Json::Value txs; obj[jss::index] = startIndex; std::string sql = boost::str (boost::format ( "SELECT LedgerSeq, Status, RawTxn " "FROM Transactions ORDER BY LedgerSeq desc LIMIT %u,20;") % startIndex); { auto db = context.app.getTxnDB ().checkoutDb (); boost::optional<std::uint64_t> ledgerSeq; boost::optional<std::string> status; soci::blob sociRawTxnBlob (*db); soci::indicator rti; Blob rawTxn; soci::statement st = (db->prepare << sql, soci::into (ledgerSeq), soci::into (status), soci::into (sociRawTxnBlob, rti)); st.execute (); while (st.fetch ()) { if (soci::i_ok == rti) convert(sociRawTxnBlob, rawTxn); else rawTxn.clear (); if (auto trans = Transaction::transactionFromSQL ( ledgerSeq, status, rawTxn, context.app)) txs.append (trans->getJson (0)); } } obj[jss::txs] = txs; return obj; }