Skip to content

Commit

Permalink
Add delivered amount to GetAccountTransactionHistory responses
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcobb23 committed Apr 22, 2020
1 parent 020b285 commit aa9cd1c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 11 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 @@ -373,19 +373,20 @@ populateProtoResponse(
closeTime->time_since_epoch().count());
if (txnMeta)
{
if (!txnMeta->hasDeliveredAmount())
RPC::convert(*txnProto->mutable_meta(), txnMeta);

auto amt = getDeliveredAmount(
context,
txn->getSTransaction(),
*txnMeta,
txn->getLedger());
if (amt)
{
std::optional<STAmount> amount = getDeliveredAmount(
context,
txn->getSTransaction(),
*txnMeta,
txn->getLedger());
if (amount)
{
txnMeta->setDeliveredAmount(*amount);
}
RPC::convert(
*txnProto->mutable_meta()
->mutable_delivered_amount(),
*amt);
}
RPC::convert(*txnProto->mutable_meta(), txnMeta);
}
}
}
Expand Down
59 changes: 59 additions & 0 deletions src/test/rpc/Tx_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,24 @@ class Tx_test : public beast::unit_test::suite
}
};

class GrpcAccountTxClient : public GRPCTestClientBase
{
public:
org::xrpl::rpc::v1::GetAccountTransactionHistoryRequest request;
org::xrpl::rpc::v1::GetAccountTransactionHistoryResponse reply;

explicit GrpcAccountTxClient(std::string const& port)
: GRPCTestClientBase(port)
{
}

void
AccountTx()
{
status = stub_->GetAccountTransactionHistory(&context, request, &reply);
}
};

void
testTxGrpc()
{
Expand All @@ -528,6 +546,26 @@ class Tx_test : public beast::unit_test::suite
client.status.ok(), client.reply);
};

auto grpcAccountTx = [&grpcPort](auto hash, auto binary, auto account) {
GrpcAccountTxClient client(grpcPort);
client.request.set_binary(binary);
client.request.mutable_account()->set_address(toBase58(account));
client.AccountTx();
org::xrpl::rpc::v1::GetTransactionResponse res;

for (auto tx : client.reply.transactions())
{
if (uint256::fromVoid(tx.hash().data()) == hash)
{
return std::
pair<bool, org::xrpl::rpc::v1::GetTransactionResponse>(
client.status.ok(), tx);
}
}
return std::pair<bool, org::xrpl::rpc::v1::GetTransactionResponse>(
false, res);
};

Account A1{"A1"};
Account A2{"A2"};
Account A3{"A3"};
Expand Down Expand Up @@ -688,6 +726,27 @@ class Tx_test : public beast::unit_test::suite
result.second.transaction(),
txMeta,
tx);

// Compare result to result from account_tx
// The transactions in later ledgers do not include A1
if (index < startLegSeq + 14)
{
auto const accountTxResult =
grpcAccountTx(id, b, A1);

BEAST_EXPECT(accountTxResult.first);
if (accountTxResult.first)
{
cmpPaymentTx(
accountTxResult.second.transaction(), tx);
cmpMeta(accountTxResult.second.meta(), txMeta);
cmpDeliveredAmount(
accountTxResult.second.meta(),
accountTxResult.second.transaction(),
txMeta,
tx);
}
}
}
}
}
Expand Down

0 comments on commit aa9cd1c

Please sign in to comment.