Skip to content

Commit b3abe5e

Browse files
author
wangchao
committed
fix(tx_history): add date and transactionResult field
1 parent 35789dc commit b3abe5e

File tree

3 files changed

+49
-38
lines changed

3 files changed

+49
-38
lines changed

src/ripple/app/misc/impl/AccountTxPaging.cpp

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -95,49 +95,51 @@ processTransRes(Schema& app,DatabaseCon& connection,std::function<
9595
st.execute();
9696

9797
std::map<uint32_t, std::shared_ptr<const ripple::Ledger>> ledgerCache;
98-
while (st.fetch ())
98+
while (st.fetch())
99+
{
100+
if (lookingForMarker)
101+
{
102+
if (findLedger == ledgerSeq.value_or(0) &&
103+
findSeq == txnSeq.value_or(0))
104+
{
105+
lookingForMarker = false;
106+
}
107+
}
108+
else if (numberOfResults == 0)
109+
{
110+
marker = {
111+
rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0)),
112+
txnSeq.value_or(0)};
113+
break;
114+
}
115+
116+
if (!lookingForMarker)
99117
{
100-
if (lookingForMarker)
118+
auto const seq =
119+
rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0));
120+
auto const txID = from_hex_text<uint256>(transID.value());
121+
122+
std::shared_ptr<const ripple::Ledger> lgr = nullptr;
123+
124+
if (ledgerCache.count(seq))
101125
{
102-
if (findLedger == ledgerSeq.value_or(0) &&
103-
findSeq == txnSeq.value_or(0))
104-
{
105-
lookingForMarker = false;
106-
}
126+
lgr = ledgerCache[seq];
107127
}
108-
else if (numberOfResults == 0)
128+
else if (
129+
lgr =
130+
app.getLedgerMaster().getLedgerBySeq(ledgerSeq.value_or(0)))
109131
{
110-
marker = {
111-
rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0)),
112-
txnSeq.value_or(0)};
113-
break;
132+
ledgerCache.emplace(seq, lgr);
114133
}
115134

116-
if (!lookingForMarker)
135+
Blob txRaw, txMeta;
136+
if (lgr && getRawMeta(*lgr, txID, txRaw, txMeta))
117137
{
118-
auto const seq =
119-
rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or(0));
120-
auto const txID = from_hex_text<uint256>(transID.value());
121-
122-
std::shared_ptr<const ripple::Ledger> lgr = nullptr;
123-
124-
if (ledgerCache.count(seq))
125-
{
126-
lgr = ledgerCache[seq];
127-
}
128-
else if (lgr = app.getLedgerMaster().getLedgerBySeq(ledgerSeq.value_or(0)))
129-
{
130-
ledgerCache.emplace(seq, lgr);
131-
}
132-
133-
Blob txRaw, txMeta;
134-
if (lgr && getRawMeta(*lgr, txID, txRaw, txMeta))
135-
{
136-
onTransaction(seq, std::move(txRaw), std::move(txMeta));
137-
}
138-
--numberOfResults;
138+
onTransaction(seq, std::move(txRaw), std::move(txMeta));
139139
}
140+
--numberOfResults;
140141
}
142+
}
141143
}
142144

143145
void

src/ripple/rpc/handlers/Tx.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,10 @@ doTxCount(RPC::JsonContext& context)
12181218
int ledger_index = -1;
12191219
if (context.params.isMember(jss::ledger_index))
12201220
ledger_index = context.params[jss::ledger_index].asInt();
1221+
if (ledger_index = -1)
1222+
{
1223+
ledger_index = context.app.getLedgerMaster().getValidLedgerIndex();
1224+
}
12211225
if (context.params.isMember(jss::chainsql_tx))
12221226
bChainsql = context.params[jss::chainsql_tx].asBool();
12231227
Json::Value ret(Json::objectValue);

src/ripple/rpc/handlers/TxHistory.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ doTxHistory(RPC::JsonContext& context)
9797
{
9898
sql = boost::str(
9999
boost::format(
100-
"SELECT TransID "
100+
"SELECT TransID, TxResult "
101101
"FROM Transactions WHERE (TransType != 'EnableAmendment' "
102102
"AND TransType != 'SetFee' AND TransType != 'UNLModify') "
103103
"ORDER BY LedgerSeq desc LIMIT %u,20;") %
@@ -115,7 +115,7 @@ doTxHistory(RPC::JsonContext& context)
115115
}
116116

117117
sql = boost::str(
118-
boost::format("SELECT TransID "
118+
boost::format("SELECT TransID, TxResult "
119119
"FROM Transactions WHERE (%s) "
120120
"ORDER BY LedgerSeq desc LIMIT %u,20;") %
121121
cond % startIndex);
@@ -125,7 +125,9 @@ doTxHistory(RPC::JsonContext& context)
125125
auto db = context.app.getTxnDB().checkoutDbRead();
126126

127127
boost::optional<std::string> stxnHash;
128-
soci::statement st = (db->prepare << sql, soci::into(stxnHash));
128+
boost::optional<std::string> stxnResult;
129+
soci::statement st =
130+
(db->prepare << sql, soci::into(stxnHash), soci::into(stxnResult));
129131
st.execute();
130132

131133
while (st.fetch())
@@ -137,7 +139,10 @@ doTxHistory(RPC::JsonContext& context)
137139
continue;
138140
}
139141

140-
txs.append(txn->getJson(JsonOptions::none));
142+
Json::Value obj = txn->getJson(JsonOptions::include_date);
143+
obj["TransactionResult"] = stxnResult.value();
144+
145+
txs.append(obj);
141146
}
142147
}
143148

0 commit comments

Comments
 (0)