20#include <xrpld/app/paths/Flow.h>
21#include <xrpld/app/tx/detail/SignerEntries.h>
22#include <xrpld/app/tx/detail/Transactor.h>
23#include <xrpld/app/tx/detail/XChainBridge.h>
25#include <xrpl/basics/Log.h>
26#include <xrpl/basics/Number.h>
27#include <xrpl/basics/chrono.h>
28#include <xrpl/beast/utility/Journal.h>
29#include <xrpl/beast/utility/instrumentation.h>
30#include <xrpl/ledger/ApplyView.h>
31#include <xrpl/ledger/PaymentSandbox.h>
32#include <xrpl/ledger/View.h>
33#include <xrpl/protocol/AccountID.h>
34#include <xrpl/protocol/Feature.h>
35#include <xrpl/protocol/Indexes.h>
36#include <xrpl/protocol/PublicKey.h>
37#include <xrpl/protocol/SField.h>
38#include <xrpl/protocol/STAmount.h>
39#include <xrpl/protocol/STObject.h>
40#include <xrpl/protocol/STXChainBridge.h>
41#include <xrpl/protocol/TER.h>
42#include <xrpl/protocol/TxFlags.h>
43#include <xrpl/protocol/XChainAttestations.h>
44#include <xrpl/protocol/XRPAmount.h>
111checkAttestationPublicKey(
112 ReadView
const& view,
114 AccountID const& attestationSignerAccount,
118 if (!signersList.
contains(attestationSignerAccount))
125 if (
auto const sleAttestationSigningAccount =
128 if (accountFromPK == attestationSignerAccount)
131 if (sleAttestationSigningAccount->getFieldU32(sfFlags) &
134 JLOG(j.
trace()) <<
"Attempt to add an attestation with "
135 "disabled master key.";
143 (*sleAttestationSigningAccount)[~sfRegularKey];
144 regularKey != accountFromPK)
149 <<
"Attempt to add an attestation with "
150 "account present and non-present regular key.";
154 JLOG(j.
trace()) <<
"Attempt to add an attestation with "
155 "account present and mismatched "
156 "regular key/public key.";
168 <<
"Attempt to add an attestation with non-existant account "
169 "and mismatched pk/account pair.";
188enum class CheckDst {
check, ignore };
189template <
class TAttestation>
190Expected<std::vector<AccountID>,
TER>
192 XChainAttestationsBase<TAttestation>& attestations,
193 ReadView
const& view,
194 typename TAttestation::MatchFields
const& toMatch,
203 attestations.erase_if([&](
auto const& a) {
204 return checkAttestationPublicKey(
205 view, signersList, a.keyAccount, a.publicKey, j) !=
211 rewardAccounts.reserve(attestations.size());
213 for (
auto const& a : attestations)
215 auto const matchR = a.match(toMatch);
221 (checkDst == CheckDst::check && matchR !=
match))
223 auto i = signersList.
find(a.keyAccount);
224 if (i == signersList.
end())
228 "ripple::claimHelper : invalid inputs");
234 rewardAccounts.push_back(a.rewardAccount);
237 if (weight >= quorum)
238 return rewardAccounts;
274struct OnNewAttestationResult
282template <
class TAttestation>
283[[nodiscard]] OnNewAttestationResult
285 XChainAttestationsBase<TAttestation>& attestations,
286 ReadView
const& view,
287 typename TAttestation::TSignedAttestation
const* attBegin,
288 typename TAttestation::TSignedAttestation
const* attEnd,
293 bool changed =
false;
294 for (
auto att = attBegin; att != attEnd; ++att)
296 if (checkAttestationPublicKey(
299 att->attestationSignerAccount,
310 auto const& claimSigningAccount = att->attestationSignerAccount;
312 attestations.begin(),
315 return a.keyAccount == claimSigningAccount;
317 i != attestations.end())
321 *i = TAttestation{*att};
326 attestations.emplace_back(*att);
331 auto r = claimHelper(
334 typename TAttestation::MatchFields{*attBegin},
343 return {std::move(r.value()), changed};
349Expected<std::vector<AccountID>,
TER>
351 XChainClaimAttestations& attestations,
352 ReadView
const& view,
353 STAmount
const& sendingAmount,
354 bool wasLockingChainSend,
359 XChainClaimAttestation::MatchFields toMatch{
362 attestations, view, toMatch, CheckDst::ignore, quorum, signersList, j);
365enum class CanCreateDstPolicy {
no,
yes };
367enum class DepositAuthPolicy { normal, dstCanBypass };
371struct TransferHelperSubmittingAccountInfo
374 STAmount preFeeBalance;
375 STAmount postFeeBalance;
408 CanCreateDstPolicy canCreate,
409 DepositAuthPolicy depositAuthPolicy,
411 submittingAccountInfo,
418 if (
auto sleDst = psb.read(dstK))
428 bool const canBypassDepositAuth = dst == claimOwner &&
429 depositAuthPolicy == DepositAuthPolicy::dstCanBypass;
431 if (!canBypassDepositAuth && (sleDst->getFlags() &
lsfDepositAuth) &&
437 else if (!amt.native() || canCreate == CanCreateDstPolicy::no)
445 XRPL_ASSERT(sleSrc,
"ripple::transferHelper : non-null source account");
450 auto const ownerCount = sleSrc->getFieldU32(sfOwnerCount);
451 auto const reserve = psb.fees().accountReserve(ownerCount);
453 auto const availableBalance = [&]() -> STAmount {
454 STAmount
const curBal = (*sleSrc)[sfBalance];
458 if (!submittingAccountInfo ||
459 submittingAccountInfo->account != src ||
460 submittingAccountInfo->postFeeBalance != curBal)
462 return submittingAccountInfo->preFeeBalance;
465 if (availableBalance < amt + reserve)
471 auto sleDst = psb.peek(dstK);
474 if (canCreate == CanCreateDstPolicy::no)
479 if (amt < psb.fees().reserve)
481 JLOG(j.
trace()) <<
"Insufficient payment to create account.";
487 psb.rules().enabled(featureDeletableAccounts) ? psb.seq() : 1};
490 sleDst->setAccountID(sfAccount, dst);
491 sleDst->setFieldU32(sfSequence, seqno);
496 (*sleSrc)[sfBalance] = (*sleSrc)[sfBalance] - amt;
497 (*sleDst)[sfBalance] = (*sleDst)[sfBalance] + amt;
504 auto const result =
flow(
519 if (
auto const r = result.result();
530enum class OnTransferFail {
537struct FinalizeClaimHelperResult
558 if ((!mainFundsTer || *mainFundsTer ==
tesSUCCESS) &&
567 return *mainFundsTer;
576 if (mainFundsTer && mainFundsTer !=
tesSUCCESS)
577 return *mainFundsTer;
614FinalizeClaimHelperResult
616 PaymentSandbox& outerSb,
617 STXChainBridge
const& bridgeSpec,
621 STAmount
const& sendingAmount,
623 STAmount
const& rewardPool,
626 Keylet
const& claimIDKeylet,
627 OnTransferFail onTransferFail,
628 DepositAuthPolicy depositAuthPolicy,
631 FinalizeClaimHelperResult result;
635 STAmount
const thisChainAmount = [&] {
636 STAmount r = sendingAmount;
637 r.setIssue(bridgeSpec.issue(dstChain));
640 auto const& thisDoor = bridgeSpec.door(dstChain);
643 PaymentSandbox innerSb{&outerSb};
654 result.mainFundsTer = transferHelper(
661 CanCreateDstPolicy::yes,
667 onTransferFail == OnTransferFail::keepClaim)
673 result.rewardTer = [&]() ->
TER {
674 if (rewardAccounts.empty())
680 STAmount
const share = [&] {
681 auto const round_mode =
682 innerSb.rules().enabled(fixXChainRewardRounding)
687 STAmount
const den{rewardAccounts.size()};
688 return divide(rewardPool, den, rewardPool.issue());
690 STAmount distributed = rewardPool.zeroed();
691 for (
auto const& rewardAccount : rewardAccounts)
693 auto const thTer = transferHelper(
701 CanCreateDstPolicy::no,
702 DepositAuthPolicy::normal,
710 distributed += share;
716 if (distributed > rewardPool)
723 (onTransferFail == OnTransferFail::keepClaim ||
735 innerSb.apply(outerSb);
739 if (
auto const sleClaimID = outerSb.peek(claimIDKeylet))
741 auto const cidOwner = (*sleClaimID)[sfAccount];
745 auto const page = (*sleClaimID)[sfOwnerNode];
746 if (!outerSb.dirRemove(
750 <<
"Unable to delete xchain seq number from owner.";
756 outerSb.erase(sleClaimID);
775getSignersListAndQuorum(
776 ReadView
const& view,
777 SLE const& sleBridge,
783 AccountID const thisDoor = sleBridge[sfAccount];
784 auto const sleDoor = [&] {
return view.read(
keylet::account(thisDoor)); }();
796 q = (*sleS)[sfSignerQuorum];
805 for (
auto const& as : *accountSigners)
807 r[as.account] = as.weight;
813template <
class R,
class F>
815readOrpeekBridge(F&& getter, STXChainBridge
const& bridgeSpec)
818 if (
auto r = getter(bridgeSpec, ct))
820 if ((*r)[sfXChainBridge] == bridgeSpec)
831peekBridge(ApplyView& v, STXChainBridge
const& bridgeSpec)
833 return readOrpeekBridge<SLE>(
840readBridge(ReadView
const& v, STXChainBridge
const& bridgeSpec)
842 return readOrpeekBridge<SLE const>(
852template <
class TIter>
854applyClaimAttestations(
859 STXChainBridge
const& bridgeSpec,
865 if (attBegin == attEnd)
868 PaymentSandbox psb(&view);
870 auto const claimIDKeylet =
875 OnNewAttestationResult newAttResult;
876 STAmount rewardAmount;
880 auto const scopeResult = [&]() -> Expected<ScopeResult, TER> {
885 auto const sleClaimID = psb.peek(claimIDKeylet);
892 for (
auto att = attBegin; att != attEnd; ++att)
894 if (!signersList.
contains(att->attestationSignerAccount))
904 AccountID const otherChainSource = (*sleClaimID)[sfOtherChainSource];
905 if (attBegin->sendingAccount != otherChainSource)
917 if (attDstChain != dstChain)
923 XChainClaimAttestations curAtts{
924 sleClaimID->getFieldArray(sfXChainClaimAttestations)};
926 auto const newAttResult = onNewAttestations(
930 &atts[0] + atts.
size(),
936 sleClaimID->setFieldArray(
937 sfXChainClaimAttestations, curAtts.toSTArray());
938 psb.update(sleClaimID);
942 (*sleClaimID)[sfSignatureReward],
943 (*sleClaimID)[sfAccount]};
946 if (!scopeResult.has_value())
947 return scopeResult.error();
949 auto const& [newAttResult, rewardAmount, cidOwner] = scopeResult.value();
950 auto const& [rewardAccounts, attListChanged] = newAttResult;
951 if (rewardAccounts && attBegin->dst)
953 auto const r = finalizeClaimHelper(
959 attBegin->sendingAmount,
965 OnTransferFail::keepClaim,
966 DepositAuthPolicy::normal,
969 auto const rTer = r.ter();
981template <
class TIter>
983applyCreateAccountAttestations(
990 STXChainBridge
const& bridgeSpec,
991 Keylet
const& bridgeK,
997 if (attBegin == attEnd)
1000 PaymentSandbox psb(&view);
1002 auto const claimCountResult = [&]() -> Expected<std::uint64_t, TER> {
1003 auto const sleBridge = psb.peek(bridgeK);
1007 return (*sleBridge)[sfXChainAccountClaimCount];
1010 if (!claimCountResult.has_value())
1011 return claimCountResult.error();
1015 if (attBegin->createCount <= claimCount)
1032 if (attDstChain != dstChain)
1038 auto const claimIDKeylet =
1043 OnNewAttestationResult newAttResult;
1045 XChainCreateAccountAttestations curAtts;
1048 auto const scopeResult = [&]() -> Expected<ScopeResult, TER> {
1056 auto const sleClaimID = psb.peek(claimIDKeylet);
1057 bool createCID =
false;
1062 auto const sleDoor = psb.peek(doorK);
1067 auto const balance = (*sleDoor)[sfBalance];
1068 auto const reserve =
1069 psb.fees().accountReserve((*sleDoor)[sfOwnerCount] + 1);
1071 if (balance < reserve)
1077 for (
auto att = attBegin; att != attEnd; ++att)
1079 if (!signersList.
contains(att->attestationSignerAccount))
1088 XChainCreateAccountAttestations curAtts = [&] {
1090 return XChainCreateAccountAttestations{
1091 sleClaimID->getFieldArray(
1092 sfXChainCreateAccountAttestations)};
1093 return XChainCreateAccountAttestations{};
1096 auto const newAttResult = onNewAttestations(
1100 &atts[0] + atts.
size(),
1111 sleClaimID->setFieldArray(
1112 sfXChainCreateAccountAttestations, curAtts.toSTArray());
1113 psb.update(sleClaimID);
1115 return ScopeResult{newAttResult, createCID, curAtts};
1118 if (!scopeResult.has_value())
1119 return scopeResult.error();
1121 auto const& [attResult, createCID, curAtts] = scopeResult.value();
1122 auto const& [rewardAccounts, attListChanged] = attResult;
1125 if (rewardAccounts && claimCount + 1 == attBegin->createCount)
1127 auto const r = finalizeClaimHelper(
1133 attBegin->sendingAmount,
1135 attBegin->rewardAmount,
1139 OnTransferFail::removeClaim,
1140 DepositAuthPolicy::normal,
1143 auto const rTer = r.ter();
1153 auto const sleBridge = psb.peek(bridgeK);
1156 (*sleBridge)[sfXChainAccountClaimCount] = attBegin->createCount;
1157 psb.update(sleBridge);
1162 (*createdSleClaimID)[sfAccount] = doorAccount;
1163 (*createdSleClaimID)[sfXChainBridge] = bridgeSpec;
1164 (*createdSleClaimID)[sfXChainAccountCreateCount] =
1165 attBegin->createCount;
1166 createdSleClaimID->setFieldArray(
1167 sfXChainCreateAccountAttestations, curAtts.toSTArray());
1170 auto const page = psb.dirInsert(
1176 (*createdSleClaimID)[sfOwnerNode] = *
page;
1178 auto const sleDoor = psb.peek(doorK);
1184 psb.insert(createdSleClaimID);
1185 psb.update(sleDoor);
1193template <
class TAttestation>
1195toClaim(STTx
const& tx)
1204 o.setAccountID(sfAccount, o[sfOtherChainSource]);
1205 return TAttestation(o);
1213template <
class TAttestation>
1215attestationpreflight(PreflightContext
const& ctx)
1220 auto const att = toClaim<TAttestation>(ctx.tx);
1224 STXChainBridge
const bridgeSpec = ctx.tx[sfXChainBridge];
1225 if (!att->verify(bridgeSpec))
1227 if (!att->validAmounts())
1230 if (att->sendingAmount.signum() <= 0)
1232 auto const expectedIssue =
1234 if (att->sendingAmount.issue() != expectedIssue)
1240template <
class TAttestation>
1242attestationPreclaim(PreclaimContext
const& ctx)
1244 auto const att = toClaim<TAttestation>(ctx.tx);
1249 STXChainBridge
const bridgeSpec = ctx.tx[sfXChainBridge];
1250 auto const sleBridge = readBridge(ctx.view, bridgeSpec);
1256 AccountID const attestationSignerAccount{
1257 ctx.tx[sfAttestationSignerAccount]};
1258 PublicKey
const pk{ctx.tx[sfPublicKey]};
1261 auto const [signersList, quorum, slTer] =
1262 getSignersListAndQuorum(ctx.view, *sleBridge, ctx.j);
1267 return checkAttestationPublicKey(
1268 ctx.view, signersList, attestationSignerAccount, pk, ctx.j);
1271template <
class TAttestation>
1273attestationDoApply(ApplyContext& ctx)
1275 auto const att = toClaim<TAttestation>(ctx.tx);
1280 STXChainBridge
const bridgeSpec = ctx.tx[sfXChainBridge];
1284 STXChainBridge::ChainType srcChain;
1291 auto const scopeResult = [&]() -> Expected<ScopeResult, TER> {
1296 auto sleBridge = readBridge(ctx.view(), bridgeSpec);
1301 Keylet
const bridgeK{ltBRIDGE, sleBridge->key()};
1302 AccountID const thisDoor = (*sleBridge)[sfAccount];
1306 if (thisDoor == bridgeSpec.lockingChainDoor())
1308 else if (thisDoor == bridgeSpec.issuingChainDoor())
1317 auto [signersList, quorum, slTer] =
1318 getSignersListAndQuorum(ctx.view(), *sleBridge, ctx.journal);
1324 srcChain, std::move(signersList), quorum, thisDoor, bridgeK};
1327 if (!scopeResult.has_value())
1328 return scopeResult.error();
1330 auto const& [srcChain, signersList, quorum, thisDoor, bridgeK] =
1331 scopeResult.value();
1339 return applyClaimAttestations(
1352 Attestations::AttestationCreateAccount>)
1354 return applyCreateAccountAttestations(
1376 auto const account = ctx.
tx[sfAccount];
1377 auto const reward = ctx.
tx[sfSignatureReward];
1378 auto const minAccountCreate = ctx.
tx[~sfMinAccountCreateAmount];
1379 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1381 if (bridgeSpec.lockingChainDoor() == bridgeSpec.issuingChainDoor())
1386 if (bridgeSpec.lockingChainDoor() != account &&
1387 bridgeSpec.issuingChainDoor() != account)
1392 if (
isXRP(bridgeSpec.lockingChainIssue()) !=
1393 isXRP(bridgeSpec.issuingChainIssue()))
1400 if (!
isXRP(reward) || reward.signum() < 0)
1405 if (minAccountCreate &&
1406 ((!
isXRP(*minAccountCreate) || minAccountCreate->signum() <= 0) ||
1407 !
isXRP(bridgeSpec.lockingChainIssue()) ||
1408 !
isXRP(bridgeSpec.issuingChainIssue())))
1413 if (
isXRP(bridgeSpec.issuingChainIssue()))
1422 if (bridgeSpec.issuingChainDoor() != rootAccount)
1431 if (bridgeSpec.issuingChainDoor() !=
1432 bridgeSpec.issuingChainIssue().account)
1438 if (bridgeSpec.lockingChainDoor() == bridgeSpec.lockingChainIssue().account)
1451 auto const account = ctx.
tx[sfAccount];
1452 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1468 if (!
isXRP(bridgeSpec.issue(chainType)))
1470 auto const sleIssuer =
1488 auto const balance = (*sleAcc)[sfBalance];
1489 auto const reserve =
1492 if (balance < reserve)
1502 auto const account =
ctx_.
tx[sfAccount];
1503 auto const bridgeSpec =
ctx_.
tx[sfXChainBridge];
1504 auto const reward =
ctx_.
tx[sfSignatureReward];
1505 auto const minAccountCreate =
ctx_.
tx[~sfMinAccountCreateAmount];
1517 (*sleBridge)[sfAccount] = account;
1518 (*sleBridge)[sfSignatureReward] = reward;
1519 if (minAccountCreate)
1520 (*sleBridge)[sfMinAccountCreateAmount] = *minAccountCreate;
1521 (*sleBridge)[sfXChainBridge] = bridgeSpec;
1522 (*sleBridge)[sfXChainClaimID] = 0;
1523 (*sleBridge)[sfXChainAccountCreateCount] = 0;
1524 (*sleBridge)[sfXChainAccountClaimCount] = 0;
1532 (*sleBridge)[sfOwnerNode] = *page;
1554 auto const account = ctx.
tx[sfAccount];
1555 auto const reward = ctx.
tx[~sfSignatureReward];
1556 auto const minAccountCreate = ctx.
tx[~sfMinAccountCreateAmount];
1557 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1558 bool const clearAccountCreate =
1561 if (!reward && !minAccountCreate && !clearAccountCreate)
1567 if (minAccountCreate && clearAccountCreate)
1573 if (bridgeSpec.lockingChainDoor() != account &&
1574 bridgeSpec.issuingChainDoor() != account)
1579 if (reward && (!
isXRP(*reward) || reward->signum() < 0))
1584 if (minAccountCreate &&
1585 ((!
isXRP(*minAccountCreate) || minAccountCreate->signum() <= 0) ||
1586 !
isXRP(bridgeSpec.lockingChainIssue()) ||
1587 !
isXRP(bridgeSpec.issuingChainIssue())))
1598 auto const account = ctx.
tx[sfAccount];
1599 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1615 auto const account =
ctx_.
tx[sfAccount];
1616 auto const bridgeSpec =
ctx_.
tx[sfXChainBridge];
1617 auto const reward =
ctx_.
tx[~sfSignatureReward];
1618 auto const minAccountCreate =
ctx_.
tx[~sfMinAccountCreateAmount];
1619 bool const clearAccountCreate =
1629 auto const sleBridge =
1635 (*sleBridge)[sfSignatureReward] = *reward;
1636 if (minAccountCreate)
1638 (*sleBridge)[sfMinAccountCreateAmount] = *minAccountCreate;
1640 if (clearAccountCreate &&
1641 sleBridge->isFieldPresent(sfMinAccountCreateAmount))
1643 sleBridge->makeFieldAbsent(sfMinAccountCreateAmount);
1656 auto const amount = ctx.
tx[sfAmount];
1658 if (amount.signum() <= 0 ||
1673 STAmount const& thisChainAmount = ctx.
tx[sfAmount];
1674 auto const claimID = ctx.
tx[sfXChainClaimID];
1676 auto const sleBridge = readBridge(ctx.
view, bridgeSpec);
1687 auto const thisDoor = (*sleBridge)[sfAccount];
1688 bool isLockingChain =
false;
1691 isLockingChain =
true;
1693 isLockingChain =
false;
1722 auto const otherChainAmount = [&]() ->
STAmount {
1731 auto const sleClaimID =
1741 if ((*sleClaimID)[sfAccount] != account)
1758 auto const dst =
ctx_.
tx[sfDestination];
1761 auto const claimID =
ctx_.
tx[sfXChainClaimID];
1780 auto const sleBridge = peekBridge(psb, bridgeSpec);
1781 auto const sleClaimID = psb.
peek(claimIDKeylet);
1783 if (!(sleBridge && sleClaimID && sleAcct))
1786 AccountID const thisDoor = (*sleBridge)[sfAccount];
1800 auto const sendingAmount = [&]() ->
STAmount {
1806 auto const [signersList, quorum, slTer] =
1813 sleClaimID->getFieldArray(sfXChainClaimAttestations)};
1815 auto const claimR = onClaim(
1824 if (!claimR.has_value())
1829 (*sleClaimID)[sfAccount],
1832 (*sleClaimID)[sfSignatureReward],
1836 if (!scopeResult.has_value())
1837 return scopeResult.error();
1839 auto const& [rewardAccounts, rewardPoolSrc, sendingAmount, srcChain, signatureReward] =
1840 scopeResult.value();
1843 auto const r = finalizeClaimHelper(
1855 OnTransferFail::keepClaim,
1856 DepositAuthPolicy::dstCanBypass,
1858 if (!r.isTesSuccess())
1871 auto const maxSpend = [&] {
1872 auto const amount = ctx.
tx[sfAmount];
1873 if (amount.native() && amount.signum() > 0)
1874 return amount.xrp();
1884 auto const amount = ctx.
tx[sfAmount];
1885 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1887 if (amount.signum() <= 0 || !
isLegalNet(amount))
1890 if (amount.issue() != bridgeSpec.lockingChainIssue() &&
1891 amount.issue() != bridgeSpec.issuingChainIssue())
1900 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1901 auto const amount = ctx.
tx[sfAmount];
1903 auto const sleBridge = readBridge(ctx.
view, bridgeSpec);
1909 AccountID const thisDoor = (*sleBridge)[sfAccount];
1912 if (thisDoor == account)
1918 bool isLockingChain =
false;
1920 if (thisDoor == bridgeSpec.lockingChainDoor())
1921 isLockingChain =
true;
1922 else if (thisDoor == bridgeSpec.issuingChainDoor())
1923 isLockingChain =
false;
1930 if (bridgeSpec.lockingChainIssue() != ctx.
tx[sfAmount].issue())
1935 if (bridgeSpec.issuingChainIssue() != ctx.
tx[sfAmount].issue())
1947 auto const account =
ctx_.
tx[sfAccount];
1948 auto const amount =
ctx_.
tx[sfAmount];
1949 auto const bridgeSpec =
ctx_.
tx[sfXChainBridge];
1954 auto const sleBridge = readBridge(psb, bridgeSpec);
1958 auto const dst = (*sleBridge)[sfAccount];
1961 TransferHelperSubmittingAccountInfo submittingAccountInfo{
1964 auto const thTer = transferHelper(
1971 CanCreateDstPolicy::no,
1972 DepositAuthPolicy::normal,
1973 submittingAccountInfo,
1989 auto const reward = ctx.
tx[sfSignatureReward];
2000 auto const account = ctx.
tx[sfAccount];
2001 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
2002 auto const sleBridge = readBridge(ctx.
view, bridgeSpec);
2010 auto const reward = ctx.
tx[sfSignatureReward];
2012 if (reward != (*sleBridge)[sfSignatureReward])
2023 auto const balance = (*sleAcc)[sfBalance];
2024 auto const reserve =
2027 if (balance < reserve)
2037 auto const account =
ctx_.
tx[sfAccount];
2038 auto const bridgeSpec =
ctx_.
tx[sfXChainBridge];
2039 auto const reward =
ctx_.
tx[sfSignatureReward];
2040 auto const otherChainSrc =
ctx_.
tx[sfOtherChainSource];
2046 auto const sleBridge = peekBridge(
ctx_.
view(), bridgeSpec);
2050 std::uint32_t const claimID = (*sleBridge)[sfXChainClaimID] + 1;
2057 (*sleBridge)[sfXChainClaimID] = claimID;
2068 (*sleClaimID)[sfAccount] = account;
2069 (*sleClaimID)[sfXChainBridge] = bridgeSpec;
2070 (*sleClaimID)[sfXChainClaimID] = claimID;
2071 (*sleClaimID)[sfOtherChainSource] = otherChainSrc;
2072 (*sleClaimID)[sfSignatureReward] = reward;
2073 sleClaimID->setFieldArray(
2074 sfXChainClaimAttestations,
STArray{sfXChainClaimAttestations});
2084 (*sleClaimID)[sfOwnerNode] = *page;
2101 return attestationpreflight<Attestations::AttestationClaim>(ctx);
2107 return attestationPreclaim<Attestations::AttestationClaim>(ctx);
2113 return attestationDoApply<Attestations::AttestationClaim>(
ctx_);
2121 return attestationpreflight<Attestations::AttestationCreateAccount>(ctx);
2127 return attestationPreclaim<Attestations::AttestationCreateAccount>(ctx);
2133 return attestationDoApply<Attestations::AttestationCreateAccount>(
ctx_);
2141 auto const amount = ctx.
tx[sfAmount];
2143 if (amount.signum() <= 0 || !amount.native())
2146 auto const reward = ctx.
tx[sfSignatureReward];
2147 if (reward.signum() < 0 || !reward.native())
2150 if (reward.issue() != amount.issue())
2161 STAmount const reward = ctx.
tx[sfSignatureReward];
2163 auto const sleBridge = readBridge(ctx.
view, bridgeSpec);
2169 if (reward != (*sleBridge)[sfSignatureReward])
2175 (*sleBridge)[~sfMinAccountCreateAmount];
2177 if (!minCreateAmount)
2180 if (amount < *minCreateAmount)
2183 if (minCreateAmount->issue() != amount.
issue())
2186 AccountID const thisDoor = (*sleBridge)[sfAccount];
2188 if (thisDoor == account)
2206 if (bridgeSpec.
issue(srcChain) != ctx.
tx[sfAmount].issue())
2229 auto const sleBridge = peekBridge(psb, bridge);
2233 auto const dst = (*sleBridge)[sfAccount];
2236 TransferHelperSubmittingAccountInfo submittingAccountInfo{
2238 STAmount const toTransfer = amount + reward;
2239 auto const thTer = transferHelper(
2246 CanCreateDstPolicy::yes,
2247 DepositAuthPolicy::normal,
2248 submittingAccountInfo,
2254 (*sleBridge)[sfXChainAccountCreateCount] =
2255 (*sleBridge)[sfXChainAccountCreateCount] + 1;
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
beast::Journal const journal
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
virtual void insert(std::shared_ptr< SLE > const &sle)=0
Insert a new state SLE.
std::optional< std::uint64_t > dirInsert(Keylet const &directory, uint256 const &key, std::function< void(std::shared_ptr< SLE > const &)> const &describe)
Insert an entry to a directory.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
static rounding_mode getround()
static rounding_mode setround(rounding_mode mode)
A wrapper which makes credits unavailable to balances.
void apply(RawView &to)
Apply changes to base view.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
void setIssue(Asset const &asset)
Set the Issue for this amount.
Issue const & issue() const
std::uint32_t getFlags() const
static ChainType dstChain(bool wasLockingChainSend)
static ChainType srcChain(bool wasLockingChainSend)
AccountID const & issuingChainDoor() const
Issue const & issuingChainIssue() const
Issue const & lockingChainIssue() const
static ChainType otherChain(ChainType ct)
AccountID const & lockingChainDoor() const
Issue const & issue(ChainType ct) const
static Expected< std::vector< SignerEntry >, NotTEC > deserialize(STObject const &obj, beast::Journal journal, std::string_view annotation)
Class describing the consequences to the account of applying a transaction if the transaction consume...
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static TxConsequences makeTxConsequences(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
void update(std::shared_ptr< SLE > const &sle) override
Indicate changes to a peeked SLE.
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
std::shared_ptr< SLE > peek(Keylet const &k) override
Prepare to modify the SLE associated with key.
void check(bool condition, std::string const &message)
Keylet xChainClaimID(STXChainBridge const &bridge, std::uint64_t seq)
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet page(uint256 const &root, std::uint64_t index=0) noexcept
A page in a directory.
Keylet bridge(STXChainBridge const &bridge, STXChainBridge::ChainType chainType)
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet signers(AccountID const &account) noexcept
A SignerList.
Keylet xChainCreateAccountClaimID(STXChainBridge const &bridge, std::uint64_t seq)
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
std::uint32_t ownerCount(Env const &env, Account const &account)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
STAmount divide(STAmount const &amount, Rate const &rate)
constexpr std::uint32_t tfBridgeModifyMask
bool isXRP(AccountID const &c)
constexpr size_t xbridgeMaxAccountCreateClaims
std::pair< PublicKey, SecretKey > generateKeyPair(KeyType type, Seed const &seed)
Generate a key pair deterministically.
bool isLegalNet(STAmount const &value)
@ lsfAllowTrustLineClawback
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
StrandResult< TInAmt, TOutAmt > flow(PaymentSandbox const &baseView, Strand const &strand, std::optional< TInAmt > const &maxIn, TOutAmt const &out, beast::Journal j)
Request out amount from a strand.
AccountID calcAccountID(PublicKey const &pk)
bool isTefFailure(TER x) noexcept
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
constexpr std::uint32_t tfClearAccountCreateAmount
@ tecXCHAIN_INSUFF_CREATE_AMOUNT
@ tecXCHAIN_CREATE_ACCOUNT_DISABLED
@ tecXCHAIN_CREATE_ACCOUNT_NONXRP_ISSUE
@ tecXCHAIN_PAYMENT_FAILED
@ tecXCHAIN_CLAIM_NO_QUORUM
@ tecXCHAIN_PROOF_UNKNOWN_KEY
@ tecXCHAIN_ACCOUNT_CREATE_PAST
@ tecXCHAIN_BAD_TRANSFER_ISSUE
@ tecXCHAIN_REWARD_MISMATCH
@ tecXCHAIN_SENDING_ACCOUNT_MISMATCH
@ tecXCHAIN_BAD_PUBLIC_KEY_ACCOUNT_PAIR
@ tecXCHAIN_NO_SIGNERS_LIST
@ tecINSUFFICIENT_RESERVE
@ tecXCHAIN_ACCOUNT_CREATE_TOO_MANY
bool isTerRetry(TER x) noexcept
bool isTesSuccess(TER x) noexcept
Unexpected(E(&)[N]) -> Unexpected< E const * >
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
TERSubset< CanCvtToTER > TER
bool isTecClaim(TER x) noexcept
TERSubset< CanCvtToNotTEC > NotTEC
@ temXCHAIN_BRIDGE_BAD_MIN_ACCOUNT_CREATE_AMOUNT
@ temXCHAIN_BRIDGE_BAD_REWARD_AMOUNT
@ temXCHAIN_EQUAL_DOOR_ACCOUNTS
@ temXCHAIN_BRIDGE_NONDOOR_OWNER
@ temXCHAIN_BRIDGE_BAD_ISSUES
XRPAmount accountReserve(std::size_t ownerCount) const
Returns the account reserve given the owner count, in drops.
A pair of SHAMap key and LedgerEntryType.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.