mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-05 11:32:26 +00:00
Compare commits
6 Commits
mvadari/pa
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0ee813666 | ||
|
|
8e05416211 | ||
|
|
81555d5456 | ||
|
|
6b55c4cdc8 | ||
|
|
3414a1776b | ||
|
|
6d9ed125f3 |
8
.github/scripts/rename/copyright.sh
vendored
8
.github/scripts/rename/copyright.sh
vendored
@@ -76,11 +76,11 @@ fi
|
||||
if ! grep -q 'Dev Null' src/test/rpc/ValidatorInfo_test.cpp; then
|
||||
echo -e "// Copyright (c) 2020 Dev Null Productions\n\n$(cat src/test/rpc/ValidatorInfo_test.cpp)" > src/test/rpc/ValidatorInfo_test.cpp
|
||||
fi
|
||||
if ! grep -q 'Dev Null' src/xrpld/rpc/handlers/DoManifest.cpp; then
|
||||
echo -e "// Copyright (c) 2019 Dev Null Productions\n\n$(cat src/xrpld/rpc/handlers/DoManifest.cpp)" > src/xrpld/rpc/handlers/DoManifest.cpp
|
||||
if ! grep -q 'Dev Null' src/xrpld/rpc/handlers/server_info/Manifest.cpp; then
|
||||
echo -e "// Copyright (c) 2019 Dev Null Productions\n\n$(cat src/xrpld/rpc/handlers/server_info/Manifest.cpp)" > src/xrpld/rpc/handlers/server_info/Manifest.cpp
|
||||
fi
|
||||
if ! grep -q 'Dev Null' src/xrpld/rpc/handlers/ValidatorInfo.cpp; then
|
||||
echo -e "// Copyright (c) 2019 Dev Null Productions\n\n$(cat src/xrpld/rpc/handlers/ValidatorInfo.cpp)" > src/xrpld/rpc/handlers/ValidatorInfo.cpp
|
||||
if ! grep -q 'Dev Null' src/xrpld/rpc/handlers/admin/status/ValidatorInfo.cpp; then
|
||||
echo -e "// Copyright (c) 2019 Dev Null Productions\n\n$(cat src/xrpld/rpc/handlers/admin/status/ValidatorInfo.cpp)" > src/xrpld/rpc/handlers/admin/status/ValidatorInfo.cpp
|
||||
fi
|
||||
if ! grep -q 'Bougalis' include/xrpl/basics/SlabAllocator.h; then
|
||||
echo -e "// Copyright (c) 2022, Nikolaos D. Bougalis <nikb@bougalis.net>\n\n$(cat include/xrpl/basics/SlabAllocator.h)" > include/xrpl/basics/SlabAllocator.h # cspell: ignore Nikolaos Bougalis nikb
|
||||
|
||||
2
.github/workflows/check-pr-commits.yml
vendored
2
.github/workflows/check-pr-commits.yml
vendored
@@ -10,4 +10,4 @@ permissions:
|
||||
|
||||
jobs:
|
||||
check_commits:
|
||||
uses: XRPLF/actions/.github/workflows/check-pr-commits.yml@481048b78b94ac3343d1292b4ef125a813879f2b
|
||||
uses: XRPLF/actions/.github/workflows/check-pr-commits.yml@e2c7f400d1e85ae65dad552fd425169fbacca4a3
|
||||
|
||||
2
.github/workflows/check-pr-title.yml
vendored
2
.github/workflows/check-pr-title.yml
vendored
@@ -11,4 +11,4 @@ on:
|
||||
jobs:
|
||||
check_title:
|
||||
if: ${{ github.event.pull_request.draft != true }}
|
||||
uses: XRPLF/actions/.github/workflows/check-pr-title.yml@e2c7f400d1e85ae65dad552fd425169fbacca4a3
|
||||
uses: XRPLF/actions/.github/workflows/check-pr-title.yml@a5d8dd35be543365e90a11358447130c8763871d
|
||||
|
||||
2
.github/workflows/pre-commit.yml
vendored
2
.github/workflows/pre-commit.yml
vendored
@@ -14,7 +14,7 @@ on:
|
||||
jobs:
|
||||
# Call the workflow in the XRPLF/actions repo that runs the pre-commit hooks.
|
||||
run-hooks:
|
||||
uses: XRPLF/actions/.github/workflows/pre-commit.yml@e7896f15cc60d0da1a272c77ee5c4026b424f9c7
|
||||
uses: XRPLF/actions/.github/workflows/pre-commit.yml@9307df762265e15c745ddcdb38a581c989f7f349
|
||||
with:
|
||||
runs_on: ubuntu-latest
|
||||
container: '{ "image": "ghcr.io/xrplf/ci/tools-rippled-pre-commit:sha-41ec7c1" }'
|
||||
|
||||
2
.github/workflows/publish-docs.yml
vendored
2
.github/workflows/publish-docs.yml
vendored
@@ -47,7 +47,7 @@ jobs:
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: Prepare runner
|
||||
uses: XRPLF/actions/prepare-runner@2bbc2dc1abeec7bfaa886804ab86871ac201764e
|
||||
uses: XRPLF/actions/prepare-runner@90f11ee655d1687824fb8793db770477d52afbab
|
||||
with:
|
||||
enable_ccache: false
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ jobs:
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: Prepare runner
|
||||
uses: XRPLF/actions/prepare-runner@2bbc2dc1abeec7bfaa886804ab86871ac201764e
|
||||
uses: XRPLF/actions/prepare-runner@90f11ee655d1687824fb8793db770477d52afbab
|
||||
with:
|
||||
enable_ccache: ${{ inputs.ccache_enabled }}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ jobs:
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: Prepare runner
|
||||
uses: XRPLF/actions/prepare-runner@2bbc2dc1abeec7bfaa886804ab86871ac201764e
|
||||
uses: XRPLF/actions/prepare-runner@90f11ee655d1687824fb8793db770477d52afbab
|
||||
with:
|
||||
enable_ccache: false
|
||||
|
||||
|
||||
2
.github/workflows/upload-conan-deps.yml
vendored
2
.github/workflows/upload-conan-deps.yml
vendored
@@ -70,7 +70,7 @@ jobs:
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: Prepare runner
|
||||
uses: XRPLF/actions/prepare-runner@2bbc2dc1abeec7bfaa886804ab86871ac201764e
|
||||
uses: XRPLF/actions/prepare-runner@90f11ee655d1687824fb8793db770477d52afbab
|
||||
with:
|
||||
enable_ccache: false
|
||||
|
||||
|
||||
@@ -58,8 +58,8 @@ private:
|
||||
{
|
||||
explicit Value() = default;
|
||||
|
||||
STAmount lowAcctDebits;
|
||||
STAmount highAcctDebits;
|
||||
STAmount lowAcctCredits;
|
||||
STAmount highAcctCredits;
|
||||
STAmount lowAcctOrigBalance;
|
||||
};
|
||||
|
||||
|
||||
@@ -503,6 +503,14 @@ public:
|
||||
{
|
||||
return cur_.size();
|
||||
}
|
||||
|
||||
void
|
||||
removeIndex(std::size_t i)
|
||||
{
|
||||
if (i >= next_.size())
|
||||
return;
|
||||
next_.erase(next_.begin() + i);
|
||||
}
|
||||
};
|
||||
/// @endcond
|
||||
|
||||
@@ -627,6 +635,11 @@ flow(
|
||||
std::optional<BestStrand> best;
|
||||
if (flowDebugInfo)
|
||||
flowDebugInfo->newLiquidityPass();
|
||||
// Index of strand to mark as inactive (remove from the active list) if
|
||||
// the liquidity is used. This is used for strands that consume too many
|
||||
// offers Constructed as `false,0` to workaround a gcc warning about
|
||||
// uninitialized variables
|
||||
std::optional<std::size_t> markInactiveOnUse;
|
||||
for (size_t strandIndex = 0, sie = activeStrands.size(); strandIndex != sie; ++strandIndex)
|
||||
{
|
||||
Strand const* strand = activeStrands.get(strandIndex);
|
||||
@@ -690,6 +703,11 @@ flow(
|
||||
|
||||
if (best)
|
||||
{
|
||||
if (markInactiveOnUse)
|
||||
{
|
||||
activeStrands.removeIndex(*markInactiveOnUse);
|
||||
markInactiveOnUse.reset();
|
||||
}
|
||||
savedIns.insert(best->in);
|
||||
savedOuts.insert(best->out);
|
||||
remainingOut = outReq - sum(savedOuts);
|
||||
|
||||
@@ -37,14 +37,14 @@ DeferredCredits::credit(
|
||||
|
||||
if (sender < receiver)
|
||||
{
|
||||
v.lowAcctDebits = amount;
|
||||
v.highAcctDebits = amount.zeroed();
|
||||
v.highAcctCredits = amount;
|
||||
v.lowAcctCredits = amount.zeroed();
|
||||
v.lowAcctOrigBalance = preCreditSenderBalance;
|
||||
}
|
||||
else
|
||||
{
|
||||
v.lowAcctDebits = amount.zeroed();
|
||||
v.highAcctDebits = amount;
|
||||
v.highAcctCredits = amount.zeroed();
|
||||
v.lowAcctCredits = amount;
|
||||
v.lowAcctOrigBalance = -preCreditSenderBalance;
|
||||
}
|
||||
|
||||
@@ -56,11 +56,11 @@ DeferredCredits::credit(
|
||||
auto& v = i->second;
|
||||
if (sender < receiver)
|
||||
{
|
||||
v.lowAcctDebits += amount;
|
||||
v.highAcctCredits += amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
v.highAcctDebits += amount;
|
||||
v.lowAcctCredits += amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,11 +104,11 @@ DeferredCredits::adjustments(
|
||||
|
||||
if (main < other)
|
||||
{
|
||||
result.emplace(v.lowAcctDebits, v.highAcctDebits, v.lowAcctOrigBalance);
|
||||
result.emplace(v.highAcctCredits, v.lowAcctCredits, v.lowAcctOrigBalance);
|
||||
return result;
|
||||
}
|
||||
|
||||
result.emplace(v.highAcctDebits, v.lowAcctDebits, -v.lowAcctOrigBalance);
|
||||
result.emplace(v.lowAcctCredits, v.highAcctCredits, -v.lowAcctOrigBalance);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -122,8 +122,8 @@ DeferredCredits::apply(DeferredCredits& to)
|
||||
{
|
||||
auto& toVal = r.first->second;
|
||||
auto const& fromVal = i.second;
|
||||
toVal.lowAcctDebits += fromVal.lowAcctDebits;
|
||||
toVal.highAcctDebits += fromVal.highAcctDebits;
|
||||
toVal.lowAcctCredits += fromVal.lowAcctCredits;
|
||||
toVal.highAcctCredits += fromVal.highAcctCredits;
|
||||
// Do not update the orig balance, it's already correct
|
||||
}
|
||||
}
|
||||
@@ -349,14 +349,14 @@ PaymentSandbox::balanceChanges(ReadView const& view) const
|
||||
auto const cur = newBalance.getCurrency();
|
||||
result[std::make_tuple(lowID, highID, cur)] = delta;
|
||||
auto r = result.emplace(std::make_tuple(lowID, lowID, cur), delta);
|
||||
if (!r.second)
|
||||
if (r.second)
|
||||
{
|
||||
r.first->second += delta;
|
||||
}
|
||||
|
||||
delta.negate();
|
||||
r = result.emplace(std::make_tuple(highID, highID, cur), delta);
|
||||
if (!r.second)
|
||||
if (r.second)
|
||||
{
|
||||
r.first->second += delta;
|
||||
}
|
||||
|
||||
@@ -69,11 +69,7 @@ transferRate(ReadView const& view, MPTID const& issuanceID)
|
||||
// which represents 50% of 1,000,000,000
|
||||
if (auto const sle = view.read(keylet::mptIssuance(issuanceID));
|
||||
sle && sle->isFieldPresent(sfTransferFee))
|
||||
{
|
||||
auto const fee = sle->getFieldU16(sfTransferFee);
|
||||
XRPL_ASSERT(fee <= maxTransferFee, "xrpl::transferRate : fee is too large");
|
||||
return Rate{1'000'000'000u + (10'000 * fee)};
|
||||
}
|
||||
return Rate{1'000'000'000u + (10'000 * sle->getFieldU16(sfTransferFee))};
|
||||
|
||||
return parityRate;
|
||||
}
|
||||
@@ -139,7 +135,7 @@ authorizeMPToken(
|
||||
// When a holder wants to unauthorize/delete a MPT, the ledger must
|
||||
// - delete mptokenKey from owner directory
|
||||
// - delete the MPToken
|
||||
if ((flags & tfMPTUnauthorize) != 0u)
|
||||
if ((flags & tfMPTUnauthorize) != 0)
|
||||
{
|
||||
auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
|
||||
auto const sleMpt = view.peek(mptokenKey);
|
||||
@@ -219,7 +215,7 @@ authorizeMPToken(
|
||||
|
||||
// Issuer wants to unauthorize the holder, unset lsfMPTAuthorized on
|
||||
// their MPToken
|
||||
if ((flags & tfMPTUnauthorize) != 0u)
|
||||
if ((flags & tfMPTUnauthorize) != 0)
|
||||
{
|
||||
flagsOut &= ~lsfMPTAuthorized;
|
||||
}
|
||||
|
||||
@@ -363,6 +363,13 @@ Transactor::checkFee(PreclaimContext const& ctx, XRPAmount baseFee)
|
||||
|
||||
auto const balance = (*sle)[sfBalance].xrp();
|
||||
|
||||
// NOTE: Because preclaim evaluates against a static readview, it
|
||||
// does not reflect fee deductions from other transactions paid by
|
||||
// the same account within the current ledger.
|
||||
// As a result, if an account's balance is over-committed across multiple
|
||||
// transactions, this check may pass optimistically.
|
||||
// The fee shortfall will be handled by the Transactor::reset mechanism,
|
||||
// which caps the fee to the remaining actual balance.
|
||||
if (balance < feePaid)
|
||||
{
|
||||
JLOG(ctx.j.trace()) << "Insufficient balance:" << " balance=" << to_string(balance)
|
||||
|
||||
@@ -175,18 +175,32 @@ ValidLoanBroker::finalize(
|
||||
return false;
|
||||
}
|
||||
auto const& vaultAsset = vault->at(sfAsset);
|
||||
if (after->at(sfCoverAvailable) < accountHolds(
|
||||
view,
|
||||
after->at(sfAccount),
|
||||
vaultAsset,
|
||||
FreezeHandling::fhIGNORE_FREEZE,
|
||||
AuthHandling::ahIGNORE_AUTH,
|
||||
j))
|
||||
auto const pseudoBalance = accountHolds(
|
||||
view,
|
||||
after->at(sfAccount),
|
||||
vaultAsset,
|
||||
FreezeHandling::fhIGNORE_FREEZE,
|
||||
AuthHandling::ahIGNORE_AUTH,
|
||||
j);
|
||||
if (after->at(sfCoverAvailable) < pseudoBalance)
|
||||
{
|
||||
JLOG(j.fatal()) << "Invariant failed: Loan Broker cover available "
|
||||
"is less than pseudo-account asset balance";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (view.rules().enabled(fixSecurity3_1_3))
|
||||
{
|
||||
// Don't check the balance when LoanBroker is deleted,
|
||||
// sfCoverAvailable is not zeroed
|
||||
if (tx.getTxnType() != ttLOAN_BROKER_DELETE &&
|
||||
after->at(sfCoverAvailable) > pseudoBalance)
|
||||
{
|
||||
JLOG(j.fatal()) << "Invariant failed: Loan Broker cover available is greater "
|
||||
"than pseudo-account asset balance";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ AccountDelete::preclaim(PreclaimContext const& ctx)
|
||||
if (!cdirFirst(ctx.view, ownerDirKeylet.key, sleDirNode, uDirEntry, dirEntry))
|
||||
return tesSUCCESS;
|
||||
|
||||
std::int32_t deletableDirEntryCount{0};
|
||||
std::uint32_t deletableDirEntryCount{0};
|
||||
do
|
||||
{
|
||||
// Make sure any directory node types that we find are the kind
|
||||
|
||||
@@ -564,6 +564,7 @@ OfferCreate::applyGuts(Sandbox& sb, Sandbox& sbCancel)
|
||||
return {tecEXPIRED, true};
|
||||
}
|
||||
|
||||
bool const bOpenLedger = sb.open();
|
||||
bool crossed = false;
|
||||
|
||||
if (isTesSuccess(result))
|
||||
@@ -649,8 +650,7 @@ OfferCreate::applyGuts(Sandbox& sb, Sandbox& sbCancel)
|
||||
stream << " out: " << format_amount(place_offer.out);
|
||||
}
|
||||
|
||||
bool const isLedgerOpen = sb.open();
|
||||
if (result == tecFAILED_PROCESSING && isLedgerOpen)
|
||||
if (result == tecFAILED_PROCESSING && bOpenLedger)
|
||||
result = telFAILED_PROCESSING;
|
||||
|
||||
if (!isTesSuccess(result))
|
||||
|
||||
@@ -386,21 +386,29 @@ LoanManage::doApply()
|
||||
return tefBAD_LEDGER; // LCOV_EXCL_LINE
|
||||
auto const vaultAsset = vaultSle->at(sfAsset);
|
||||
|
||||
// Valid flag combinations are checked in preflight. No flags is valid -
|
||||
// just a noop.
|
||||
if (tx.isFlag(tfLoanDefault))
|
||||
return defaultLoan(view, loanSle, brokerSle, vaultSle, vaultAsset, j_);
|
||||
if (tx.isFlag(tfLoanImpair))
|
||||
return impairLoan(view, loanSle, vaultSle, vaultAsset, j_);
|
||||
if (tx.isFlag(tfLoanUnimpair))
|
||||
return unimpairLoan(view, loanSle, vaultSle, vaultAsset, j_);
|
||||
// Noop, as described above.
|
||||
auto const result = [&]() -> TER {
|
||||
// Valid flag combinations are checked in preflight. No flags is valid -
|
||||
// just a noop.
|
||||
if (tx.isFlag(tfLoanDefault))
|
||||
return defaultLoan(view, loanSle, brokerSle, vaultSle, vaultAsset, j_);
|
||||
if (tx.isFlag(tfLoanImpair))
|
||||
return impairLoan(view, loanSle, vaultSle, vaultAsset, j_);
|
||||
if (tx.isFlag(tfLoanUnimpair))
|
||||
return unimpairLoan(view, loanSle, vaultSle, vaultAsset, j_);
|
||||
// Noop, as described above.
|
||||
return tesSUCCESS;
|
||||
}();
|
||||
|
||||
associateAsset(*loanSle, vaultAsset);
|
||||
associateAsset(*brokerSle, vaultAsset);
|
||||
associateAsset(*vaultSle, vaultAsset);
|
||||
// Pre-amendment, associateAsset was only called on the noop (no flags)
|
||||
// path. Post-amendment, we call associateAsset on all successful paths.
|
||||
if (view.rules().enabled(fixSecurity3_1_3) && isTesSuccess(result))
|
||||
{
|
||||
associateAsset(*loanSle, vaultAsset);
|
||||
associateAsset(*brokerSle, vaultAsset);
|
||||
associateAsset(*vaultSle, vaultAsset);
|
||||
}
|
||||
|
||||
return tesSUCCESS;
|
||||
return result;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -155,7 +155,7 @@ LoanPay::preclaim(PreclaimContext const& ctx)
|
||||
if (tx.isFlag(tfLoanOverpayment) && !loanSle->isFlag(lsfLoanOverpayment))
|
||||
{
|
||||
JLOG(ctx.j.warn()) << "Requested overpayment on a loan that doesn't allow it";
|
||||
return temINVALID_FLAG;
|
||||
return ctx.view.rules().enabled(fixSecurity3_1_3) ? TER{tecNO_PERMISSION} : temINVALID_FLAG;
|
||||
}
|
||||
|
||||
auto const principalOutstanding = loanSle->at(sfPrincipalOutstanding);
|
||||
|
||||
@@ -388,7 +388,6 @@ Payment::doApply()
|
||||
sleDst = std::make_shared<SLE>(k);
|
||||
sleDst->setAccountID(sfAccount, dstAccountID);
|
||||
sleDst->setFieldU32(sfSequence, view().seq());
|
||||
sleDst->setFieldAmount(sfBalance, XRPAmount(beast::zero));
|
||||
|
||||
view().insert(sleDst);
|
||||
}
|
||||
@@ -560,18 +559,23 @@ Payment::doApply()
|
||||
// This is the total reserve in drops.
|
||||
auto const reserve = view().fees().accountReserve(ownerCount);
|
||||
|
||||
// preFeeBalance_ is the balance on the sending account BEFORE the
|
||||
// fees were charged. We want to make sure we have enough reserve
|
||||
// to send. Allow final spend to use reserve for fee.
|
||||
auto const mmm = std::max(reserve, ctx_.tx.getFieldAmount(sfFee).xrp());
|
||||
// In a delegated payment, the fee payer is the delegated account,
|
||||
// not the source account (account_).
|
||||
bool const accountIsPayer = (ctx_.tx.getFeePayer() == account_);
|
||||
|
||||
if (preFeeBalance_ < dstAmount.xrp() + mmm)
|
||||
// preFeeBalance_ is the balance on the source account (account_) BEFORE the fees
|
||||
// were charged. If source account is the fee payer, it must also cover the fee.
|
||||
// The final spend may use the reserve to cover fees.
|
||||
auto const minRequiredFunds =
|
||||
accountIsPayer ? std::max(reserve, ctx_.tx.getFieldAmount(sfFee).xrp()) : reserve;
|
||||
|
||||
if (preFeeBalance_ < dstAmount.xrp() + minRequiredFunds)
|
||||
{
|
||||
// Vote no. However the transaction might succeed, if applied in
|
||||
// a different order.
|
||||
JLOG(j_.trace()) << "Delay transaction: Insufficient funds: " << to_string(preFeeBalance_)
|
||||
<< " / " << to_string(dstAmount.xrp() + mmm) << " (" << to_string(reserve)
|
||||
<< ")";
|
||||
<< " / " << to_string(dstAmount.xrp() + minRequiredFunds) << " ("
|
||||
<< to_string(reserve) << ")";
|
||||
|
||||
return tecUNFUNDED_PAYMENT;
|
||||
}
|
||||
|
||||
@@ -274,37 +274,42 @@ class Delegate_test : public beast::unit_test::suite
|
||||
testcase("test fee");
|
||||
using namespace jtx;
|
||||
|
||||
Env env(*this);
|
||||
Account const alice{"alice"};
|
||||
Account const bob{"bob"};
|
||||
Account const carol{"carol"};
|
||||
env.fund(XRP(10000), alice, carol);
|
||||
env.fund(XRP(1000), bob);
|
||||
env.close();
|
||||
// Common setup: fund alice, bob, carol with 1000 XRP.
|
||||
auto setup = [&](Env& env) {
|
||||
Account const alice{"alice"};
|
||||
Account const bob{"bob"};
|
||||
Account const carol{"carol"};
|
||||
env.fund(XRP(1000), alice, bob, carol);
|
||||
env.close();
|
||||
return std::make_tuple(alice, bob, carol);
|
||||
};
|
||||
|
||||
// No fee deduction for terNO_DELEGATE_PERMISSION.
|
||||
{
|
||||
auto aliceBalance = env.balance(alice);
|
||||
auto bobBalance = env.balance(bob);
|
||||
auto carolBalance = env.balance(carol);
|
||||
Env env(*this);
|
||||
auto [alice, bob, carol] = setup(env);
|
||||
|
||||
env(pay(alice, carol, XRP(100)),
|
||||
fee(XRP(2000)),
|
||||
delegate::as(bob),
|
||||
ter(terNO_DELEGATE_PERMISSION));
|
||||
auto const aliceBalance = env.balance(alice);
|
||||
auto const bobBalance = env.balance(bob);
|
||||
auto const carolBalance = env.balance(carol);
|
||||
|
||||
env(pay(alice, carol, XRP(100)), delegate::as(bob), ter(terNO_DELEGATE_PERMISSION));
|
||||
env.close();
|
||||
BEAST_EXPECT(env.balance(alice) == aliceBalance);
|
||||
BEAST_EXPECT(env.balance(bob) == bobBalance);
|
||||
BEAST_EXPECT(env.balance(carol) == carolBalance);
|
||||
}
|
||||
|
||||
env(delegate::set(alice, bob, {"Payment"}));
|
||||
env.close();
|
||||
|
||||
// Delegate pays the fee successfully.
|
||||
{
|
||||
// Delegate pays the fee
|
||||
auto aliceBalance = env.balance(alice);
|
||||
auto bobBalance = env.balance(bob);
|
||||
auto carolBalance = env.balance(carol);
|
||||
Env env(*this);
|
||||
auto [alice, bob, carol] = setup(env);
|
||||
env(delegate::set(alice, bob, {"Payment"}));
|
||||
env.close();
|
||||
|
||||
auto const aliceBalance = env.balance(alice);
|
||||
auto const bobBalance = env.balance(bob);
|
||||
auto const carolBalance = env.balance(carol);
|
||||
|
||||
auto const sendAmt = XRP(100);
|
||||
auto const feeAmt = XRP(10);
|
||||
@@ -315,11 +320,16 @@ class Delegate_test : public beast::unit_test::suite
|
||||
BEAST_EXPECT(env.balance(carol) == carolBalance + sendAmt);
|
||||
}
|
||||
|
||||
// Bob has insufficient balance to pay the fee, will get terINSUF_FEE_B.
|
||||
{
|
||||
// insufficient balance to pay fee
|
||||
auto aliceBalance = env.balance(alice);
|
||||
auto bobBalance = env.balance(bob);
|
||||
auto carolBalance = env.balance(carol);
|
||||
Env env(*this);
|
||||
auto [alice, bob, carol] = setup(env);
|
||||
env(delegate::set(alice, bob, {"Payment"}));
|
||||
env.close();
|
||||
|
||||
auto const aliceBalance = env.balance(alice);
|
||||
auto const bobBalance = env.balance(bob);
|
||||
auto const carolBalance = env.balance(carol);
|
||||
|
||||
env(pay(alice, carol, XRP(100)),
|
||||
fee(XRP(2000)),
|
||||
@@ -331,22 +341,143 @@ class Delegate_test : public beast::unit_test::suite
|
||||
BEAST_EXPECT(env.balance(carol) == carolBalance);
|
||||
}
|
||||
|
||||
// The delegated account has enough balance to pay and delegator has enough reserve
|
||||
{
|
||||
// fee is paid by Delegate
|
||||
// on context reset (tec error)
|
||||
auto aliceBalance = env.balance(alice);
|
||||
auto bobBalance = env.balance(bob);
|
||||
auto carolBalance = env.balance(carol);
|
||||
auto const feeAmt = XRP(10);
|
||||
// Common setup: fund accounts and grant Bob permission to pay on Alice's behalf.
|
||||
// Alice is funded with exactly (paymentAmount + reserve + baseFee): baseFee covers
|
||||
// the DelegateSet tx cost, leaving Alice with exactly (paymentAmount + reserve).
|
||||
// highFee = reserve + baseFee, strictly greater than reserve, so that
|
||||
// max(reserve, highFee) = highFee — making the direct payment check fail.
|
||||
auto setup = [&](Env& env) {
|
||||
Account const alice{"alice"};
|
||||
Account const bob{"bob"};
|
||||
Account const carol{"carol"};
|
||||
|
||||
env(pay(alice, carol, XRP(20000)),
|
||||
fee(feeAmt),
|
||||
delegate::as(bob),
|
||||
ter(tecUNFUNDED_PAYMENT));
|
||||
auto const baseFee = env.current()->fees().base;
|
||||
auto const reserve = env.current()->fees().accountReserve(1);
|
||||
auto const paymentAmount = XRP(1);
|
||||
auto const highFee = reserve + baseFee;
|
||||
BEAST_EXPECT(highFee > reserve);
|
||||
|
||||
env.fund(paymentAmount + reserve + baseFee, alice);
|
||||
env.fund(XRP(1000), bob);
|
||||
env.fund(XRP(1000), carol);
|
||||
env.close();
|
||||
|
||||
env(delegate::set(alice, bob, {"Payment"}));
|
||||
env.close();
|
||||
|
||||
env.require(balance(alice, paymentAmount + reserve));
|
||||
|
||||
return std::make_tuple(alice, bob, carol, paymentAmount, highFee, reserve);
|
||||
};
|
||||
|
||||
// Alice's balance (paymentAmount + reserve) is insufficient to cover both
|
||||
// the payment and highFee directly. Even though fees are allowed to dip
|
||||
// below reserve, when Alice pays the fee herself the required funds =
|
||||
// paymentAmount + max(reserve, highFee) = paymentAmount + highFee
|
||||
// (since highFee > reserve), which still exceeds her balance.
|
||||
// tec: highFee is consumed from Alice's balance.
|
||||
{
|
||||
Env env(*this);
|
||||
auto [alice, bob, carol, paymentAmount, highFee, reserve] = setup(env);
|
||||
auto const aliceBalance = env.balance(alice);
|
||||
auto const bobBalance = env.balance(bob);
|
||||
auto const carolBalance = env.balance(carol);
|
||||
|
||||
env(pay(alice, carol, paymentAmount), fee(highFee), ter(tecUNFUNDED_PAYMENT));
|
||||
|
||||
// tec consumes the fee from Alice; carol and bob are unaffected.
|
||||
BEAST_EXPECT(env.balance(alice) == aliceBalance - highFee);
|
||||
BEAST_EXPECT(env.balance(bob) == bobBalance);
|
||||
BEAST_EXPECT(env.balance(carol) == carolBalance);
|
||||
}
|
||||
|
||||
// The payment succeeds because the delegated account pays the fee.
|
||||
// Alice only needs (paymentAmount + reserve).
|
||||
{
|
||||
Env env(*this);
|
||||
auto [alice, bob, carol, paymentAmount, highFee, reserve] = setup(env);
|
||||
|
||||
auto const alicePrePay = env.balance(alice, XRP);
|
||||
auto const bobPrePay = env.balance(bob, XRP);
|
||||
auto const carolPrePay = env.balance(carol, XRP);
|
||||
|
||||
env(pay(alice, carol, paymentAmount), delegate::as(bob), fee(highFee));
|
||||
env.close();
|
||||
|
||||
env.require(balance(alice, alicePrePay - paymentAmount));
|
||||
env.require(balance(bob, bobPrePay - highFee));
|
||||
env.require(balance(carol, carolPrePay + paymentAmount));
|
||||
}
|
||||
}
|
||||
|
||||
// Delegated account can pay the fee even if it dips below reserve.
|
||||
{
|
||||
Env env(*this);
|
||||
Account const alice{"alice"};
|
||||
Account const bob{"bob"};
|
||||
Account const carol{"carol"};
|
||||
|
||||
auto const baseFee = env.current()->fees().base;
|
||||
auto const baseReserve = env.current()->fees().accountReserve(0);
|
||||
|
||||
env.fund(env.current()->fees().accountReserve(1) + baseFee + XRP(1), alice);
|
||||
env.fund(baseReserve, bob);
|
||||
env.fund(XRP(1000), carol);
|
||||
env.close();
|
||||
BEAST_EXPECT(env.balance(alice) == aliceBalance);
|
||||
BEAST_EXPECT(env.balance(bob) == bobBalance - feeAmt);
|
||||
BEAST_EXPECT(env.balance(carol) == carolBalance);
|
||||
|
||||
env(delegate::set(alice, bob, {"Payment"}));
|
||||
env.close();
|
||||
|
||||
auto const alicePreTx = env.balance(alice, XRP);
|
||||
auto const bobPreTx = env.balance(bob, XRP);
|
||||
|
||||
// After paying for this transaction, bob's balance will
|
||||
// dip below the base reserve
|
||||
env(pay(alice, carol, XRP(1)), delegate::as(bob));
|
||||
env.close();
|
||||
|
||||
// Bob's balance is now less than the base reserve.
|
||||
BEAST_EXPECT(env.balance(bob, XRP) < baseReserve);
|
||||
env.require(balance(bob, bobPreTx - drops(baseFee)));
|
||||
|
||||
// Alice's balance only decreased by the 1.0 XRP she sent.
|
||||
env.require(balance(alice, alicePreTx - XRP(1)));
|
||||
}
|
||||
|
||||
// The delegated account has enough balance for the fee, but delegator
|
||||
// runs into tecUNFUNDED_PAYMENT.
|
||||
{
|
||||
Env env(*this);
|
||||
Account const alice{"alice"};
|
||||
Account const bob{"bob"};
|
||||
Account const carol{"carol"};
|
||||
|
||||
auto const baseFee = env.current()->fees().base;
|
||||
auto const reserve = env.current()->fees().accountReserve(1);
|
||||
|
||||
// Alice is funded with (reserve + baseFee): after DelegateSet she has
|
||||
// exactly 'reserve', which is insufficient to send XRP(10) while keeping
|
||||
// reserve. Bob has plenty to pay the fee.
|
||||
env.fund(reserve + baseFee, alice);
|
||||
env.fund(XRP(1000), bob);
|
||||
env.fund(XRP(1000), carol);
|
||||
env.close();
|
||||
|
||||
env(delegate::set(alice, bob, {"Payment"}));
|
||||
env.close();
|
||||
|
||||
auto const alicePrePay = env.balance(alice, XRP);
|
||||
auto const bobPrePay = env.balance(bob, XRP);
|
||||
auto const carolPrePay = env.balance(carol, XRP);
|
||||
|
||||
// Bob pays the fee, but Alice has insufficient balance to send XRP(10).
|
||||
env(pay(alice, carol, XRP(10)), delegate::as(bob), ter(tecUNFUNDED_PAYMENT));
|
||||
|
||||
env.require(balance(alice, alicePrePay));
|
||||
env.require(balance(bob, bobPrePay - drops(baseFee)));
|
||||
env.require(balance(carol, carolPrePay));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1238,8 +1369,8 @@ class Delegate_test : public beast::unit_test::suite
|
||||
// test MPTokenIssuanceUnlock and MPTokenIssuanceLock permissions
|
||||
{
|
||||
Env env(*this);
|
||||
Account alice{"alice"};
|
||||
Account bob{"bob"};
|
||||
Account const alice{"alice"};
|
||||
Account const bob{"bob"};
|
||||
env.fund(XRP(100000), alice, bob);
|
||||
env.close();
|
||||
|
||||
@@ -1285,8 +1416,8 @@ class Delegate_test : public beast::unit_test::suite
|
||||
// test mix of granular and transaction level permission
|
||||
{
|
||||
Env env(*this);
|
||||
Account alice{"alice"};
|
||||
Account bob{"bob"};
|
||||
Account const alice{"alice"};
|
||||
Account const bob{"bob"};
|
||||
env.fund(XRP(100000), alice, bob);
|
||||
env.close();
|
||||
|
||||
@@ -1332,8 +1463,8 @@ class Delegate_test : public beast::unit_test::suite
|
||||
// tfFullyCanonicalSig won't block delegated transaction
|
||||
{
|
||||
Env env(*this);
|
||||
Account alice{"alice"};
|
||||
Account bob{"bob"};
|
||||
Account const alice{"alice"};
|
||||
Account const bob{"bob"};
|
||||
env.fund(XRP(100000), alice, bob);
|
||||
env.close();
|
||||
|
||||
@@ -1410,11 +1541,9 @@ class Delegate_test : public beast::unit_test::suite
|
||||
|
||||
{
|
||||
Env env(*this);
|
||||
|
||||
Account const alice{"alice"};
|
||||
Account const bob{"bob"};
|
||||
Account const carol{"carol"};
|
||||
|
||||
env.fund(XRP(100000), alice, bob, carol);
|
||||
env.close();
|
||||
|
||||
@@ -1448,11 +1577,9 @@ class Delegate_test : public beast::unit_test::suite
|
||||
|
||||
{
|
||||
Env env(*this);
|
||||
|
||||
Account const alice{"alice"};
|
||||
Account const bob{"bob"};
|
||||
Account const carol{"carol"};
|
||||
|
||||
env.fund(XRP(100000), alice, bob, carol);
|
||||
env.close();
|
||||
|
||||
@@ -1567,8 +1694,8 @@ class Delegate_test : public beast::unit_test::suite
|
||||
|
||||
Env env(*this, features);
|
||||
|
||||
Account alice{"alice"};
|
||||
Account bob{"bob"};
|
||||
Account const alice{"alice"};
|
||||
Account const bob{"bob"};
|
||||
env.fund(XRP(100000), alice, bob);
|
||||
env.close();
|
||||
|
||||
|
||||
@@ -2046,36 +2046,36 @@ class Invariants_test : public beast::unit_test::suite
|
||||
{
|
||||
// Initialize with a placeholder value because there's no default
|
||||
// ctor
|
||||
auto const setupAsset =
|
||||
[&](Account const& alice, Account const& issuer, Env& env) -> PrettyAsset {
|
||||
switch (assetType)
|
||||
{
|
||||
case Asset::IOU: {
|
||||
PrettyAsset const iouAsset = issuer["IOU"];
|
||||
env(trust(alice, iouAsset(1000)));
|
||||
env(pay(issuer, alice, iouAsset(1000)));
|
||||
env.close();
|
||||
return iouAsset;
|
||||
}
|
||||
case Asset::MPT: {
|
||||
MPTTester mptt{env, issuer, mptInitNoFund};
|
||||
mptt.create({.flags = tfMPTCanClawback | tfMPTCanTransfer | tfMPTCanLock});
|
||||
PrettyAsset const mptAsset = mptt.issuanceID();
|
||||
mptt.authorize({.account = alice});
|
||||
env(pay(issuer, alice, mptAsset(1000)));
|
||||
env.close();
|
||||
return mptAsset;
|
||||
}
|
||||
case Asset::XRP:
|
||||
default:
|
||||
return PrettyAsset{xrpIssue(), 1'000'000};
|
||||
}
|
||||
};
|
||||
|
||||
Keylet loanBrokerKeylet = keylet::amendments();
|
||||
Preclose const createLoanBroker =
|
||||
[&, this](Account const& alice, Account const& issuer, Env& env) {
|
||||
PrettyAsset const asset = [&]() {
|
||||
switch (assetType)
|
||||
{
|
||||
case Asset::IOU: {
|
||||
PrettyAsset const iouAsset = issuer["IOU"];
|
||||
env(trust(alice, iouAsset(1000)));
|
||||
env(pay(issuer, alice, iouAsset(1000)));
|
||||
env.close();
|
||||
return iouAsset;
|
||||
}
|
||||
|
||||
case Asset::MPT: {
|
||||
MPTTester mptt{env, issuer, mptInitNoFund};
|
||||
mptt.create(
|
||||
{.flags = tfMPTCanClawback | tfMPTCanTransfer | tfMPTCanLock});
|
||||
PrettyAsset const mptAsset = mptt.issuanceID();
|
||||
mptt.authorize({.account = alice});
|
||||
env(pay(issuer, alice, mptAsset(1000)));
|
||||
env.close();
|
||||
return mptAsset;
|
||||
}
|
||||
|
||||
case Asset::XRP:
|
||||
default:
|
||||
return PrettyAsset{xrpIssue(), 1'000'000};
|
||||
}
|
||||
}();
|
||||
auto const asset = setupAsset(alice, issuer, env);
|
||||
loanBrokerKeylet = this->createLoanBroker(alice, env, asset);
|
||||
return BEAST_EXPECT(env.le(loanBrokerKeylet));
|
||||
};
|
||||
@@ -2249,6 +2249,56 @@ class Invariants_test : public beast::unit_test::suite
|
||||
STTx{ttLOAN_BROKER_SET, [](STObject& tx) {}},
|
||||
{tecINVARIANT_FAILED, tefINVARIANT_FAILED},
|
||||
createLoanBroker);
|
||||
|
||||
// Test: cover available less than pseudo-account asset balance
|
||||
{
|
||||
Keylet brokerKeylet = keylet::amendments();
|
||||
Preclose const createBrokerWithCover =
|
||||
[&, this](Account const& alice, Account const& issuer, Env& env) {
|
||||
auto const asset = setupAsset(alice, issuer, env);
|
||||
brokerKeylet = this->createLoanBroker(alice, env, asset);
|
||||
if (!BEAST_EXPECT(env.le(brokerKeylet)))
|
||||
return false;
|
||||
env(loanBroker::coverDeposit(alice, brokerKeylet.key, asset(10)));
|
||||
env.close();
|
||||
return BEAST_EXPECT(env.le(brokerKeylet));
|
||||
};
|
||||
|
||||
doInvariantCheck(
|
||||
{{"Loan Broker cover available is less than pseudo-account asset balance"}},
|
||||
[&](Account const&, Account const&, ApplyContext& ac) {
|
||||
auto sle = ac.view().peek(brokerKeylet);
|
||||
if (!BEAST_EXPECT(sle))
|
||||
return false;
|
||||
// Pseudo-account holds 10 units, set cover to 5
|
||||
sle->at(sfCoverAvailable) = Number(5);
|
||||
ac.view().update(sle);
|
||||
return true;
|
||||
},
|
||||
XRPAmount{},
|
||||
STTx{ttLOAN_BROKER_SET, [](STObject& tx) {}},
|
||||
{tecINVARIANT_FAILED, tefINVARIANT_FAILED},
|
||||
createBrokerWithCover);
|
||||
}
|
||||
|
||||
// Test: cover available greater than pseudo-account asset balance
|
||||
// (requires fixSecurity3_1_3)
|
||||
doInvariantCheck(
|
||||
{{"Loan Broker cover available is greater than pseudo-account asset balance"}},
|
||||
[&](Account const&, Account const&, ApplyContext& ac) {
|
||||
auto sle = ac.view().peek(loanBrokerKeylet);
|
||||
if (!BEAST_EXPECT(sle))
|
||||
return false;
|
||||
// Pseudo-account has no cover deposited; set cover
|
||||
// higher than any incidental balance
|
||||
sle->at(sfCoverAvailable) = Number(1'000'000);
|
||||
ac.view().update(sle);
|
||||
return true;
|
||||
},
|
||||
XRPAmount{},
|
||||
STTx{ttLOAN_BROKER_SET, [](STObject& tx) {}},
|
||||
{tecINVARIANT_FAILED, tefINVARIANT_FAILED},
|
||||
createLoanBroker);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2071,7 +2071,19 @@ protected:
|
||||
STAmount{broker.asset, state.periodicPayment * Number{15, -1}},
|
||||
tfLoanOverpayment),
|
||||
fee(XRPAmount{baseFee * (Number{15, -1} / loanPaymentsPerFeeIncrement + 1)}),
|
||||
ter(temINVALID_FLAG));
|
||||
ter(tecNO_PERMISSION));
|
||||
|
||||
{
|
||||
env.disableFeature(fixSecurity3_1_3);
|
||||
env(pay(borrower,
|
||||
loanKeylet.key,
|
||||
STAmount{broker.asset, state.periodicPayment * Number{15, -1}},
|
||||
tfLoanOverpayment),
|
||||
fee(XRPAmount{
|
||||
baseFee * (Number{15, -1} / loanPaymentsPerFeeIncrement + 1)}),
|
||||
ter(temINVALID_FLAG));
|
||||
env.enableFeature(fixSecurity3_1_3);
|
||||
}
|
||||
}
|
||||
// Try to send a payment marked as multiple mutually exclusive
|
||||
// payment types. Do not include `txFlags`, so we don't duplicate
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <test/jtx/TestSuite.h>
|
||||
|
||||
#include <xrpld/rpc/detail/RPCHelpers.h>
|
||||
#include <xrpld/rpc/handlers/WalletPropose.h>
|
||||
#include <xrpld/rpc/handlers/admin/keygen/WalletPropose.h>
|
||||
|
||||
#include <xrpl/json/json_value.h>
|
||||
#include <xrpl/json/json_writer.h>
|
||||
|
||||
@@ -1710,7 +1710,7 @@ ValidatorList::for_each_available(
|
||||
if (plCollection.status != PublisherStatus::available)
|
||||
continue;
|
||||
XRPL_ASSERT(
|
||||
plCollection.maxSequence != 0,
|
||||
plCollection.maxSequence.value_or(0) != 0,
|
||||
"xrpl::ValidatorList::for_each_available : nonzero maxSequence");
|
||||
func(
|
||||
plCollection.rawManifest,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <xrpld/overlay/detail/Tuning.h>
|
||||
#include <xrpld/overlay/predicates.h>
|
||||
#include <xrpld/peerfinder/make_Manager.h>
|
||||
#include <xrpld/rpc/handlers/GetCounts.h>
|
||||
#include <xrpld/rpc/handlers/admin/status/GetCounts.h>
|
||||
#include <xrpld/rpc/json_body.h>
|
||||
|
||||
#include <xrpl/basics/base64.h>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <xrpld/rpc/detail/Handler.h>
|
||||
#include <xrpld/rpc/handlers/Handlers.h>
|
||||
#include <xrpld/rpc/handlers/Version.h>
|
||||
#include <xrpld/rpc/handlers/server_info/Version.h>
|
||||
|
||||
#include <xrpl/basics/contract.h>
|
||||
#include <xrpl/protocol/ApiVersion.h>
|
||||
@@ -75,7 +75,7 @@ Handler const handlerArray[]{
|
||||
{"account_nfts", byRef(&doAccountNFTs), Role::USER, NO_CONDITION},
|
||||
{"account_objects", byRef(&doAccountObjects), Role::USER, NO_CONDITION},
|
||||
{"account_offers", byRef(&doAccountOffers), Role::USER, NO_CONDITION},
|
||||
{"account_tx", byRef(&doAccountTxJson), Role::USER, NO_CONDITION},
|
||||
{"account_tx", byRef(&doAccountTx), Role::USER, NO_CONDITION},
|
||||
{"amm_info", byRef(&doAMMInfo), Role::USER, NO_CONDITION},
|
||||
{"blacklist", byRef(&doBlackList), Role::ADMIN, NO_CONDITION},
|
||||
{"book_changes", byRef(&doBookChanges), Role::USER, NO_CONDITION},
|
||||
|
||||
71
src/xrpld/rpc/handlers/ChannelVerify.cpp
Normal file
71
src/xrpld/rpc/handlers/ChannelVerify.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/detail/RPCHelpers.h>
|
||||
|
||||
#include <xrpl/basics/StringUtilities.h>
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
#include <xrpl/protocol/PayChan.h>
|
||||
#include <xrpl/protocol/RPCErr.h>
|
||||
#include <xrpl/protocol/jss.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
// {
|
||||
// public_key: <public_key>
|
||||
// channel_id: 256-bit channel id
|
||||
// drops: 64-bit uint (as string)
|
||||
// signature: signature to verify
|
||||
// }
|
||||
Json::Value
|
||||
doChannelVerify(RPC::JsonContext& context)
|
||||
{
|
||||
auto const& params(context.params);
|
||||
for (auto const& p : {jss::public_key, jss::channel_id, jss::amount, jss::signature})
|
||||
{
|
||||
if (!params.isMember(p))
|
||||
return RPC::missing_field_error(p);
|
||||
}
|
||||
|
||||
std::optional<PublicKey> pk;
|
||||
{
|
||||
std::string const strPk = params[jss::public_key].asString();
|
||||
pk = parseBase58<PublicKey>(TokenType::AccountPublic, strPk);
|
||||
|
||||
if (!pk)
|
||||
{
|
||||
auto pkHex = strUnHex(strPk);
|
||||
if (!pkHex)
|
||||
return rpcError(rpcPUBLIC_MALFORMED);
|
||||
auto const pkType = publicKeyType(makeSlice(*pkHex));
|
||||
if (!pkType)
|
||||
return rpcError(rpcPUBLIC_MALFORMED);
|
||||
pk.emplace(makeSlice(*pkHex));
|
||||
}
|
||||
}
|
||||
|
||||
uint256 channelId;
|
||||
if (!channelId.parseHex(params[jss::channel_id].asString()))
|
||||
return rpcError(rpcCHANNEL_MALFORMED);
|
||||
|
||||
std::optional<std::uint64_t> const optDrops =
|
||||
params[jss::amount].isString() ? to_uint64(params[jss::amount].asString()) : std::nullopt;
|
||||
|
||||
if (!optDrops)
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
std::uint64_t const drops = *optDrops;
|
||||
|
||||
auto sig = strUnHex(params[jss::signature].asString());
|
||||
if (!sig || sig->empty())
|
||||
return rpcError(rpcINVALID_PARAMS);
|
||||
|
||||
Serializer msg;
|
||||
serializePayChanAuthorization(msg, channelId, XRPAmount(drops));
|
||||
|
||||
Json::Value result;
|
||||
result[jss::signature_verified] = verify(*pk, msg.slice(), makeSlice(*sig));
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <xrpld/rpc/handlers/LedgerHandler.h>
|
||||
#include <xrpld/rpc/handlers/ledger/Ledger.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
@@ -19,7 +19,7 @@ doAccountObjects(RPC::JsonContext&);
|
||||
Json::Value
|
||||
doAccountOffers(RPC::JsonContext&);
|
||||
Json::Value
|
||||
doAccountTxJson(RPC::JsonContext&);
|
||||
doAccountTx(RPC::JsonContext&);
|
||||
Json::Value
|
||||
doAMMInfo(RPC::JsonContext&);
|
||||
Json::Value
|
||||
|
||||
160
src/xrpld/rpc/handlers/account/AccountNFTs.cpp
Normal file
160
src/xrpld/rpc/handlers/account/AccountNFTs.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/detail/RPCHelpers.h>
|
||||
#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
|
||||
#include <xrpld/rpc/detail/Tuning.h>
|
||||
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
#include <xrpl/protocol/Indexes.h>
|
||||
#include <xrpl/protocol/RPCErr.h>
|
||||
#include <xrpl/protocol/jss.h>
|
||||
#include <xrpl/protocol/nftPageMask.h>
|
||||
#include <xrpl/resource/Fees.h>
|
||||
#include <xrpl/tx/transactors/nft/NFTokenUtils.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
/** General RPC command that can retrieve objects in the account root.
|
||||
{
|
||||
account: <account>
|
||||
ledger_hash: <string> // optional
|
||||
ledger_index: <string | unsigned integer> // optional
|
||||
type: <string> // optional, defaults to all account objects types
|
||||
limit: <integer> // optional
|
||||
marker: <opaque> // optional, resume previous query
|
||||
}
|
||||
*/
|
||||
Json::Value
|
||||
doAccountNFTs(RPC::JsonContext& context)
|
||||
{
|
||||
auto const& params = context.params;
|
||||
if (!params.isMember(jss::account))
|
||||
return RPC::missing_field_error(jss::account);
|
||||
|
||||
if (!params[jss::account].isString())
|
||||
return RPC::invalid_field_error(jss::account);
|
||||
|
||||
auto id = parseBase58<AccountID>(params[jss::account].asString());
|
||||
if (!id)
|
||||
{
|
||||
return rpcError(rpcACT_MALFORMED);
|
||||
}
|
||||
|
||||
std::shared_ptr<ReadView const> ledger;
|
||||
auto result = RPC::lookupLedger(ledger, context);
|
||||
if (ledger == nullptr)
|
||||
return result;
|
||||
auto const accountID{id.value()};
|
||||
|
||||
if (!ledger->exists(keylet::account(accountID)))
|
||||
return rpcError(rpcACT_NOT_FOUND);
|
||||
|
||||
unsigned int limit = 0;
|
||||
if (auto err = readLimitField(limit, RPC::Tuning::accountNFTokens, context))
|
||||
return *err;
|
||||
|
||||
uint256 marker;
|
||||
bool const markerSet = params.isMember(jss::marker);
|
||||
|
||||
if (markerSet)
|
||||
{
|
||||
auto const& m = params[jss::marker];
|
||||
if (!m.isString())
|
||||
return RPC::expected_field_error(jss::marker, "string");
|
||||
|
||||
if (!marker.parseHex(m.asString()))
|
||||
return RPC::invalid_field_error(jss::marker);
|
||||
}
|
||||
|
||||
auto const first = keylet::nftpage(keylet::nftpage_min(accountID), marker);
|
||||
auto const last = keylet::nftpage_max(accountID);
|
||||
|
||||
auto cp = ledger->read(
|
||||
Keylet(ltNFTOKEN_PAGE, ledger->succ(first.key, last.key.next()).value_or(last.key)));
|
||||
|
||||
std::uint32_t cnt = 0;
|
||||
auto& nfts = (result[jss::account_nfts] = Json::arrayValue);
|
||||
|
||||
// Continue iteration from the current page:
|
||||
bool pastMarker = marker.isZero();
|
||||
bool markerFound = false;
|
||||
uint256 const maskedMarker = marker & nft::pageMask;
|
||||
while (cp)
|
||||
{
|
||||
auto arr = cp->getFieldArray(sfNFTokens);
|
||||
|
||||
for (auto const& o : arr)
|
||||
{
|
||||
// Scrolling past the marker gets weird. We need to look at
|
||||
// a couple of conditions.
|
||||
//
|
||||
// 1. If the low 96-bits don't match, then we compare only
|
||||
// against the low 96-bits, since that's what determines
|
||||
// the sort order of the pages.
|
||||
//
|
||||
// 2. However, within one page there can be a number of
|
||||
// NFTokenIDs that all have the same low 96 bits. If we're
|
||||
// in that case then we need to compare against the full
|
||||
// 256 bits.
|
||||
uint256 const nftokenID = o[sfNFTokenID];
|
||||
uint256 const maskedNftokenID = nftokenID & nft::pageMask;
|
||||
|
||||
if (!pastMarker)
|
||||
{
|
||||
if (maskedNftokenID < maskedMarker)
|
||||
continue;
|
||||
|
||||
if (maskedNftokenID == maskedMarker && nftokenID < marker)
|
||||
continue;
|
||||
|
||||
if (nftokenID == marker)
|
||||
{
|
||||
markerFound = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (markerSet && !markerFound)
|
||||
return RPC::invalid_field_error(jss::marker);
|
||||
|
||||
pastMarker = true;
|
||||
|
||||
{
|
||||
Json::Value& obj = nfts.append(o.getJson(JsonOptions::none));
|
||||
|
||||
// Pull out the components of the nft ID.
|
||||
obj[sfFlags.jsonName] = nft::getFlags(nftokenID);
|
||||
obj[sfIssuer.jsonName] = to_string(nft::getIssuer(nftokenID));
|
||||
obj[sfNFTokenTaxon.jsonName] = nft::toUInt32(nft::getTaxon(nftokenID));
|
||||
obj[jss::nft_serial] = nft::getSerial(nftokenID);
|
||||
if (std::uint16_t const xferFee = {nft::getTransferFee(nftokenID)})
|
||||
obj[sfTransferFee.jsonName] = xferFee;
|
||||
}
|
||||
|
||||
if (++cnt == limit)
|
||||
{
|
||||
result[jss::limit] = limit;
|
||||
result[jss::marker] = to_string(o.getFieldH256(sfNFTokenID));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (auto npm = (*cp)[~sfNextPageMin])
|
||||
{
|
||||
cp = ledger->read(Keylet(ltNFTOKEN_PAGE, *npm));
|
||||
}
|
||||
else
|
||||
{
|
||||
cp = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (markerSet && !markerFound)
|
||||
return RPC::invalid_field_error(jss::marker);
|
||||
|
||||
result[jss::account] = toBase58(accountID);
|
||||
context.loadType = Resource::feeMediumBurdenRPC;
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
@@ -11,156 +11,11 @@
|
||||
#include <xrpl/protocol/jss.h>
|
||||
#include <xrpl/protocol/nftPageMask.h>
|
||||
#include <xrpl/resource/Fees.h>
|
||||
#include <xrpl/tx/transactors/nft/NFTokenUtils.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
/** General RPC command that can retrieve objects in the account root.
|
||||
{
|
||||
account: <account>
|
||||
ledger_hash: <string> // optional
|
||||
ledger_index: <string | unsigned integer> // optional
|
||||
type: <string> // optional, defaults to all account objects types
|
||||
limit: <integer> // optional
|
||||
marker: <opaque> // optional, resume previous query
|
||||
}
|
||||
*/
|
||||
|
||||
Json::Value
|
||||
doAccountNFTs(RPC::JsonContext& context)
|
||||
{
|
||||
auto const& params = context.params;
|
||||
if (!params.isMember(jss::account))
|
||||
return RPC::missing_field_error(jss::account);
|
||||
|
||||
if (!params[jss::account].isString())
|
||||
return RPC::invalid_field_error(jss::account);
|
||||
|
||||
auto id = parseBase58<AccountID>(params[jss::account].asString());
|
||||
if (!id)
|
||||
{
|
||||
return rpcError(rpcACT_MALFORMED);
|
||||
}
|
||||
|
||||
std::shared_ptr<ReadView const> ledger;
|
||||
auto result = RPC::lookupLedger(ledger, context);
|
||||
if (ledger == nullptr)
|
||||
return result;
|
||||
auto const accountID{id.value()};
|
||||
|
||||
if (!ledger->exists(keylet::account(accountID)))
|
||||
return rpcError(rpcACT_NOT_FOUND);
|
||||
|
||||
unsigned int limit = 0;
|
||||
if (auto err = readLimitField(limit, RPC::Tuning::accountNFTokens, context))
|
||||
return *err;
|
||||
|
||||
uint256 marker;
|
||||
bool const markerSet = params.isMember(jss::marker);
|
||||
|
||||
if (markerSet)
|
||||
{
|
||||
auto const& m = params[jss::marker];
|
||||
if (!m.isString())
|
||||
return RPC::expected_field_error(jss::marker, "string");
|
||||
|
||||
if (!marker.parseHex(m.asString()))
|
||||
return RPC::invalid_field_error(jss::marker);
|
||||
}
|
||||
|
||||
auto const first = keylet::nftpage(keylet::nftpage_min(accountID), marker);
|
||||
auto const last = keylet::nftpage_max(accountID);
|
||||
|
||||
auto cp = ledger->read(
|
||||
Keylet(ltNFTOKEN_PAGE, ledger->succ(first.key, last.key.next()).value_or(last.key)));
|
||||
|
||||
std::uint32_t cnt = 0;
|
||||
auto& nfts = (result[jss::account_nfts] = Json::arrayValue);
|
||||
|
||||
// Continue iteration from the current page:
|
||||
bool pastMarker = marker.isZero();
|
||||
bool markerFound = false;
|
||||
uint256 const maskedMarker = marker & nft::pageMask;
|
||||
while (cp)
|
||||
{
|
||||
auto arr = cp->getFieldArray(sfNFTokens);
|
||||
|
||||
for (auto const& o : arr)
|
||||
{
|
||||
// Scrolling past the marker gets weird. We need to look at
|
||||
// a couple of conditions.
|
||||
//
|
||||
// 1. If the low 96-bits don't match, then we compare only
|
||||
// against the low 96-bits, since that's what determines
|
||||
// the sort order of the pages.
|
||||
//
|
||||
// 2. However, within one page there can be a number of
|
||||
// NFTokenIDs that all have the same low 96 bits. If we're
|
||||
// in that case then we need to compare against the full
|
||||
// 256 bits.
|
||||
uint256 const nftokenID = o[sfNFTokenID];
|
||||
uint256 const maskedNftokenID = nftokenID & nft::pageMask;
|
||||
|
||||
if (!pastMarker)
|
||||
{
|
||||
if (maskedNftokenID < maskedMarker)
|
||||
continue;
|
||||
|
||||
if (maskedNftokenID == maskedMarker && nftokenID < marker)
|
||||
continue;
|
||||
|
||||
if (nftokenID == marker)
|
||||
{
|
||||
markerFound = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (markerSet && !markerFound)
|
||||
return RPC::invalid_field_error(jss::marker);
|
||||
|
||||
pastMarker = true;
|
||||
|
||||
{
|
||||
Json::Value& obj = nfts.append(o.getJson(JsonOptions::none));
|
||||
|
||||
// Pull out the components of the nft ID.
|
||||
obj[sfFlags.jsonName] = nft::getFlags(nftokenID);
|
||||
obj[sfIssuer.jsonName] = to_string(nft::getIssuer(nftokenID));
|
||||
obj[sfNFTokenTaxon.jsonName] = nft::toUInt32(nft::getTaxon(nftokenID));
|
||||
obj[jss::nft_serial] = nft::getSerial(nftokenID);
|
||||
if (std::uint16_t const xferFee = {nft::getTransferFee(nftokenID)})
|
||||
obj[sfTransferFee.jsonName] = xferFee;
|
||||
}
|
||||
|
||||
if (++cnt == limit)
|
||||
{
|
||||
result[jss::limit] = limit;
|
||||
result[jss::marker] = to_string(o.getFieldH256(sfNFTokenID));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (auto npm = (*cp)[~sfNextPageMin])
|
||||
{
|
||||
cp = ledger->read(Keylet(ltNFTOKEN_PAGE, *npm));
|
||||
}
|
||||
else
|
||||
{
|
||||
cp = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (markerSet && !markerFound)
|
||||
return RPC::invalid_field_error(jss::marker);
|
||||
|
||||
result[jss::account] = toBase58(accountID);
|
||||
context.loadType = Resource::feeMediumBurdenRPC;
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Gathers all objects for an account in a ledger.
|
||||
@param ledger Ledger to search account objects.
|
||||
@param account AccountID to find objects for.
|
||||
@@ -364,7 +364,7 @@ populateJsonResponse(
|
||||
// resume previous query
|
||||
// }
|
||||
Json::Value
|
||||
doAccountTxJson(RPC::JsonContext& context)
|
||||
doAccountTx(RPC::JsonContext& context)
|
||||
{
|
||||
if (!context.app.config().useTxTables())
|
||||
return rpcError(rpcNOT_ENABLED);
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/detail/RPCHelpers.h>
|
||||
#include <xrpld/rpc/handlers/WalletPropose.h>
|
||||
#include <xrpld/rpc/handlers/admin/keygen/WalletPropose.h>
|
||||
|
||||
#include <xrpl/basics/strHex.h>
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
@@ -66,46 +65,4 @@ doPeerReservationsAdd(RPC::JsonContext& context)
|
||||
return result;
|
||||
}
|
||||
|
||||
Json::Value
|
||||
doPeerReservationsDel(RPC::JsonContext& context)
|
||||
{
|
||||
auto const& params = context.params;
|
||||
|
||||
// We repeat much of the parameter parsing from `doPeerReservationsAdd`.
|
||||
if (!params.isMember(jss::public_key))
|
||||
return RPC::missing_field_error(jss::public_key);
|
||||
if (!params[jss::public_key].isString())
|
||||
return RPC::expected_field_error(jss::public_key, "a string");
|
||||
|
||||
std::optional<PublicKey> optPk =
|
||||
parseBase58<PublicKey>(TokenType::NodePublic, params[jss::public_key].asString());
|
||||
if (!optPk)
|
||||
return rpcError(rpcPUBLIC_MALFORMED);
|
||||
PublicKey const& nodeId = *optPk;
|
||||
|
||||
auto const previous = context.app.getPeerReservations().erase(nodeId);
|
||||
|
||||
Json::Value result{Json::objectValue};
|
||||
if (previous)
|
||||
{
|
||||
result[jss::previous] = previous->toJson();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Json::Value
|
||||
doPeerReservationsList(RPC::JsonContext& context)
|
||||
{
|
||||
auto const& reservations = context.app.getPeerReservations().list();
|
||||
// Enumerate the reservations in context.app.getPeerReservations()
|
||||
// as a Json::Value.
|
||||
Json::Value result{Json::objectValue};
|
||||
Json::Value& jaReservations = result[jss::reservations] = Json::arrayValue;
|
||||
for (auto const& reservation : reservations)
|
||||
{
|
||||
jaReservations.append(reservation.toJson());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
41
src/xrpld/rpc/handlers/admin/peer/PeerReservationsDel.cpp
Normal file
41
src/xrpld/rpc/handlers/admin/peer/PeerReservationsDel.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/handlers/Handlers.h>
|
||||
|
||||
#include <xrpl/json/json_value.h>
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
#include <xrpl/protocol/PublicKey.h>
|
||||
#include <xrpl/protocol/RPCErr.h>
|
||||
#include <xrpl/protocol/jss.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
Json::Value
|
||||
doPeerReservationsDel(RPC::JsonContext& context)
|
||||
{
|
||||
auto const& params = context.params;
|
||||
|
||||
// We repeat much of the parameter parsing from `doPeerReservationsAdd`.
|
||||
if (!params.isMember(jss::public_key))
|
||||
return RPC::missing_field_error(jss::public_key);
|
||||
if (!params[jss::public_key].isString())
|
||||
return RPC::expected_field_error(jss::public_key, "a string");
|
||||
|
||||
std::optional<PublicKey> optPk =
|
||||
parseBase58<PublicKey>(TokenType::NodePublic, params[jss::public_key].asString());
|
||||
if (!optPk)
|
||||
return rpcError(rpcPUBLIC_MALFORMED);
|
||||
PublicKey const& nodeId = *optPk;
|
||||
|
||||
auto const previous = context.app.getPeerReservations().erase(nodeId);
|
||||
|
||||
Json::Value result{Json::objectValue};
|
||||
if (previous)
|
||||
{
|
||||
result[jss::previous] = previous->toJson();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
24
src/xrpld/rpc/handlers/admin/peer/PeerReservationsList.cpp
Normal file
24
src/xrpld/rpc/handlers/admin/peer/PeerReservationsList.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/handlers/Handlers.h>
|
||||
|
||||
#include <xrpl/json/json_value.h>
|
||||
#include <xrpl/protocol/jss.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
Json::Value
|
||||
doPeerReservationsList(RPC::JsonContext& context)
|
||||
{
|
||||
auto const& reservations = context.app.getPeerReservations().list();
|
||||
// Enumerate the reservations in context.app.getPeerReservations()
|
||||
// as a Json::Value.
|
||||
Json::Value result{Json::objectValue};
|
||||
Json::Value& jaReservations = result[jss::reservations] = Json::arrayValue;
|
||||
for (auto const& reservation : reservations)
|
||||
{
|
||||
jaReservations.append(reservation.toJson());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <xrpld/rpc/detail/RPCHelpers.h>
|
||||
|
||||
#include <xrpl/basics/StringUtilities.h>
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
#include <xrpl/protocol/PayChan.h>
|
||||
#include <xrpl/protocol/RPCErr.h>
|
||||
@@ -83,61 +82,4 @@ doChannelAuthorize(RPC::JsonContext& context)
|
||||
return result;
|
||||
}
|
||||
|
||||
// {
|
||||
// public_key: <public_key>
|
||||
// channel_id: 256-bit channel id
|
||||
// drops: 64-bit uint (as string)
|
||||
// signature: signature to verify
|
||||
// }
|
||||
Json::Value
|
||||
doChannelVerify(RPC::JsonContext& context)
|
||||
{
|
||||
auto const& params(context.params);
|
||||
for (auto const& p : {jss::public_key, jss::channel_id, jss::amount, jss::signature})
|
||||
{
|
||||
if (!params.isMember(p))
|
||||
return RPC::missing_field_error(p);
|
||||
}
|
||||
|
||||
std::optional<PublicKey> pk;
|
||||
{
|
||||
std::string const strPk = params[jss::public_key].asString();
|
||||
pk = parseBase58<PublicKey>(TokenType::AccountPublic, strPk);
|
||||
|
||||
if (!pk)
|
||||
{
|
||||
auto pkHex = strUnHex(strPk);
|
||||
if (!pkHex)
|
||||
return rpcError(rpcPUBLIC_MALFORMED);
|
||||
auto const pkType = publicKeyType(makeSlice(*pkHex));
|
||||
if (!pkType)
|
||||
return rpcError(rpcPUBLIC_MALFORMED);
|
||||
pk.emplace(makeSlice(*pkHex));
|
||||
}
|
||||
}
|
||||
|
||||
uint256 channelId;
|
||||
if (!channelId.parseHex(params[jss::channel_id].asString()))
|
||||
return rpcError(rpcCHANNEL_MALFORMED);
|
||||
|
||||
std::optional<std::uint64_t> const optDrops =
|
||||
params[jss::amount].isString() ? to_uint64(params[jss::amount].asString()) : std::nullopt;
|
||||
|
||||
if (!optDrops)
|
||||
return rpcError(rpcCHANNEL_AMT_MALFORMED);
|
||||
|
||||
std::uint64_t const drops = *optDrops;
|
||||
|
||||
auto sig = strUnHex(params[jss::signature].asString());
|
||||
if (!sig || sig->empty())
|
||||
return rpcError(rpcINVALID_PARAMS);
|
||||
|
||||
Serializer msg;
|
||||
serializePayChanAuthorization(msg, channelId, XRPAmount(drops));
|
||||
|
||||
Json::Value result;
|
||||
result[jss::signature_verified] = verify(*pk, msg.slice(), makeSlice(*sig));
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <xrpld/rpc/GRPCHandlers.h>
|
||||
#include <xrpld/rpc/Role.h>
|
||||
#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
|
||||
#include <xrpld/rpc/handlers/LedgerHandler.h>
|
||||
#include <xrpld/rpc/handlers/ledger/Ledger.h>
|
||||
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
#include <xrpl/protocol/jss.h>
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/GRPCHandlers.h>
|
||||
#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
|
||||
#include <xrpld/rpc/handlers/LedgerEntryHelpers.h>
|
||||
#include <xrpld/rpc/handlers/ledger/LedgerEntryHelpers.h>
|
||||
|
||||
#include <xrpl/basics/StringUtilities.h>
|
||||
#include <xrpl/basics/strHex.h>
|
||||
21
src/xrpld/rpc/handlers/orderbook/BookChanges.cpp
Normal file
21
src/xrpld/rpc/handlers/orderbook/BookChanges.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <xrpld/rpc/BookChanges.h>
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
|
||||
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
Json::Value
|
||||
doBookChanges(RPC::JsonContext& context)
|
||||
{
|
||||
std::shared_ptr<ReadView const> ledger;
|
||||
|
||||
Json::Value result = RPC::lookupLedger(ledger, context);
|
||||
if (ledger == nullptr)
|
||||
return result;
|
||||
|
||||
return RPC::computeBookChanges(ledger);
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <xrpld/app/main/Application.h>
|
||||
#include <xrpld/rpc/BookChanges.h>
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/detail/RPCHelpers.h>
|
||||
#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
|
||||
@@ -205,16 +204,4 @@ doBookOffers(RPC::JsonContext& context)
|
||||
return jvResult;
|
||||
}
|
||||
|
||||
Json::Value
|
||||
doBookChanges(RPC::JsonContext& context)
|
||||
{
|
||||
std::shared_ptr<ReadView const> ledger;
|
||||
|
||||
Json::Value result = RPC::lookupLedger(ledger, context);
|
||||
if (ledger == nullptr)
|
||||
return result;
|
||||
|
||||
return RPC::computeBookChanges(ledger);
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
24
src/xrpld/rpc/handlers/orderbook/NFTBuyOffers.cpp
Normal file
24
src/xrpld/rpc/handlers/orderbook/NFTBuyOffers.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/handlers/orderbook/NFTOffersHelpers.h>
|
||||
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
#include <xrpl/protocol/RPCErr.h>
|
||||
#include <xrpl/protocol/jss.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
Json::Value
|
||||
doNFTBuyOffers(RPC::JsonContext& context)
|
||||
{
|
||||
if (!context.params.isMember(jss::nft_id))
|
||||
return RPC::missing_field_error(jss::nft_id);
|
||||
|
||||
uint256 nftId;
|
||||
|
||||
if (!nftId.parseHex(context.params[jss::nft_id].asString()))
|
||||
return RPC::invalid_field_error(jss::nft_id);
|
||||
|
||||
return enumerateNFTOffers(context, nftId, keylet::nft_buys(nftId));
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/detail/RPCHelpers.h>
|
||||
#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
|
||||
@@ -14,7 +16,7 @@
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
static void
|
||||
inline void
|
||||
appendNftOfferJson(
|
||||
Application const& app,
|
||||
std::shared_ptr<SLE const> const& offer,
|
||||
@@ -42,7 +44,7 @@ appendNftOfferJson(
|
||||
// limit: integer // optional
|
||||
// marker: opaque // optional, resume previous query
|
||||
// }
|
||||
static Json::Value
|
||||
inline Json::Value
|
||||
enumerateNFTOffers(RPC::JsonContext& context, uint256 const& nftId, Keylet const& directory)
|
||||
{
|
||||
unsigned int limit = 0;
|
||||
@@ -127,32 +129,4 @@ enumerateNFTOffers(RPC::JsonContext& context, uint256 const& nftId, Keylet const
|
||||
return result;
|
||||
}
|
||||
|
||||
Json::Value
|
||||
doNFTSellOffers(RPC::JsonContext& context)
|
||||
{
|
||||
if (!context.params.isMember(jss::nft_id))
|
||||
return RPC::missing_field_error(jss::nft_id);
|
||||
|
||||
uint256 nftId;
|
||||
|
||||
if (!nftId.parseHex(context.params[jss::nft_id].asString()))
|
||||
return RPC::invalid_field_error(jss::nft_id);
|
||||
|
||||
return enumerateNFTOffers(context, nftId, keylet::nft_sells(nftId));
|
||||
}
|
||||
|
||||
Json::Value
|
||||
doNFTBuyOffers(RPC::JsonContext& context)
|
||||
{
|
||||
if (!context.params.isMember(jss::nft_id))
|
||||
return RPC::missing_field_error(jss::nft_id);
|
||||
|
||||
uint256 nftId;
|
||||
|
||||
if (!nftId.parseHex(context.params[jss::nft_id].asString()))
|
||||
return RPC::invalid_field_error(jss::nft_id);
|
||||
|
||||
return enumerateNFTOffers(context, nftId, keylet::nft_buys(nftId));
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
24
src/xrpld/rpc/handlers/orderbook/NFTSellOffers.cpp
Normal file
24
src/xrpld/rpc/handlers/orderbook/NFTSellOffers.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <xrpld/rpc/Context.h>
|
||||
#include <xrpld/rpc/handlers/orderbook/NFTOffersHelpers.h>
|
||||
|
||||
#include <xrpl/protocol/ErrorCodes.h>
|
||||
#include <xrpl/protocol/RPCErr.h>
|
||||
#include <xrpl/protocol/jss.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
Json::Value
|
||||
doNFTSellOffers(RPC::JsonContext& context)
|
||||
{
|
||||
if (!context.params.isMember(jss::nft_id))
|
||||
return RPC::missing_field_error(jss::nft_id);
|
||||
|
||||
uint256 nftId;
|
||||
|
||||
if (!nftId.parseHex(context.params[jss::nft_id].asString()))
|
||||
return RPC::invalid_field_error(jss::nft_id);
|
||||
|
||||
return enumerateNFTOffers(context, nftId, keylet::nft_sells(nftId));
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user