Skip to content

Commit

Permalink
[fold] populate delivered_amount in convert, remove magic number, rep…
Browse files Browse the repository at this point in the history
…lace auto with type name
  • Loading branch information
cjcobb23 committed Apr 27, 2020
1 parent aa9cd1c commit d10a4a0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
23 changes: 12 additions & 11 deletions src/ripple/rpc/handlers/AccountTx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,19 @@ populateProtoResponse(
if (txnMeta)
{
RPC::convert(*txnProto->mutable_meta(), txnMeta);

auto amt = getDeliveredAmount(
context,
txn->getSTransaction(),
*txnMeta,
txn->getLedger());
if (amt)
if (!txnMeta->hasDeliveredAmount())
{
RPC::convert(
*txnProto->mutable_meta()
->mutable_delivered_amount(),
*amt);
if (auto amt = getDeliveredAmount(
context,
txn->getSTransaction(),
*txnMeta,
txn->getLedger()))
{
RPC::convert(
*txnProto->mutable_meta()
->mutable_delivered_amount(),
*amt);
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/ripple/rpc/impl/GRPCHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,9 @@ convert(org::xrpl::rpc::v1::Meta& to, std::shared_ptr<TxMeta> const& from)
to.mutable_transaction_result()->set_result(
transToken(from->getResultTER()));

if (from->hasDeliveredAmount())
convert(*to.mutable_delivered_amount(), from->getDeliveredAmount());

STArray& nodes = from->getNodes();
for (auto it = nodes.begin(); it != nodes.end(); ++it)
{
Expand Down
13 changes: 9 additions & 4 deletions src/test/rpc/Tx_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,10 @@ class Tx_test : public beast::unit_test::suite
client.status.ok(), client.reply);
};

auto grpcAccountTx = [&grpcPort](auto hash, auto binary, auto account) {
auto grpcAccountTx = [&grpcPort](
uint256 const& hash,
auto binary,
AccountID const& account) {
GrpcAccountTxClient client(grpcPort);
client.request.set_binary(binary);
client.request.mutable_account()->set_address(toBase58(account));
Expand Down Expand Up @@ -728,11 +731,13 @@ class Tx_test : public beast::unit_test::suite
tx);

// Compare result to result from account_tx
// The transactions in later ledgers do not include A1
if (index < startLegSeq + 14)
auto mentioned = tx->getMentionedAccounts();

if (BEAST_EXPECT(mentioned.size()))
{
auto a = *mentioned.begin();
auto const accountTxResult =
grpcAccountTx(id, b, A1);
grpcAccountTx(id, b, a);

BEAST_EXPECT(accountTxResult.first);
if (accountTxResult.first)
Expand Down

0 comments on commit d10a4a0

Please sign in to comment.