APIv2(DeliverMax): add alias for Amount in Payment transactions (#4733)

Using the "Amount" field in Payment transactions can cause incorrect
interpretation. There continue to be problems from the use of this
field. "Amount" is rarely the correct field to use; instead,
"delivered_amount" (or "DeliveredAmount") should be used.

Rename the "Amount" field to "DeliverMax", a less misleading name. With
api_version: 2, remove the "Amount" field from Payment transactions.

- Input: "DeliverMax" in `tx_json` is an alias for "Amount"
  - sign
  - submit (in sign-and-submit mode)
  - submit_multisigned
  - sign_for
- Output: Add "DeliverMax" where transactions are provided by the API
  - ledger
  - tx
  - tx_history
  - account_tx
  - transaction_entry
  - subscribe (transactions stream)
- Output: Remove "Amount" from API version 2

Fix #3484

Fix #3902
This commit is contained in:
Bronek Kozicki
2023-10-23 19:26:16 +01:00
committed by GitHub
parent 5026cbdaf3
commit 397268394b
28 changed files with 1014 additions and 83 deletions

View File

@@ -19,6 +19,7 @@
#include <ripple/app/rdb/backend/SQLiteDatabase.h>
#include <ripple/protocol/ErrorCodes.h>
#include <ripple/protocol/STBase.h>
#include <ripple/protocol/jss.h>
#include <ripple/rpc/CTID.h>
#include <optional>
@@ -692,6 +693,60 @@ class Transaction_test : public beast::unit_test::suite
}
}
void
testRequest(FeatureBitset features)
{
testcase("Test Request");
using namespace test::jtx;
using std::to_string;
const char* COMMAND = jss::tx.c_str();
Env env{*this};
Account const alice{"alice"};
Account const alie{"alie"};
Account const gw{"gw"};
auto const USD{gw["USD"]};
env.fund(XRP(1000000), alice, gw);
env.close();
// AccountSet
env(noop(alice));
// Payment
env(pay(alice, gw, XRP(100)));
std::shared_ptr<STTx const> txn = env.tx();
env.close();
std::shared_ptr<STObject const> meta =
env.closed()->txRead(env.tx()->getTransactionID()).second;
Json::Value expected = txn->getJson(JsonOptions::none);
expected[jss::DeliverMax] = expected[jss::Amount];
auto const result =
env.rpc(COMMAND, to_string(txn->getTransactionID()));
BEAST_EXPECT(result[jss::result][jss::status] == jss::success);
for (auto memberIt = expected.begin(); memberIt != expected.end();
memberIt++)
{
std::string const name = memberIt.memberName();
if (BEAST_EXPECT(result[jss::result].isMember(name)))
{
auto const received = result[jss::result][name];
BEAST_EXPECTS(
received == *memberIt,
"Transaction contains \n\"" + name + "\": " //
+ to_string(received) //
+ " but expected " //
+ to_string(expected));
}
}
}
public:
void
run() override
@@ -708,6 +763,7 @@ public:
testRangeCTIDRequest(features);
testCTIDValidation(features);
testCTIDRPC(features);
testRequest(features);
}
};