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>
24#include <xrpld/ledger/ApplyView.h>
25#include <xrpld/ledger/PaymentSandbox.h>
26#include <xrpld/ledger/View.h>
28#include <xrpl/basics/Log.h>
29#include <xrpl/basics/Number.h>
30#include <xrpl/basics/chrono.h>
31#include <xrpl/beast/utility/Journal.h>
32#include <xrpl/beast/utility/instrumentation.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())
227 "ripple::claimHelper : invalid inputs");
232 rewardAccounts.push_back(a.rewardAccount);
235 if (weight >= quorum)
236 return rewardAccounts;
272struct OnNewAttestationResult
280template <
class TAttestation>
281[[nodiscard]] OnNewAttestationResult
283 XChainAttestationsBase<TAttestation>& attestations,
284 ReadView
const& view,
285 typename TAttestation::TSignedAttestation
const* attBegin,
286 typename TAttestation::TSignedAttestation
const* attEnd,
291 bool changed =
false;
292 for (
auto att = attBegin; att != attEnd; ++att)
294 if (checkAttestationPublicKey(
297 att->attestationSignerAccount,
308 auto const& claimSigningAccount = att->attestationSignerAccount;
310 attestations.begin(),
313 return a.keyAccount == claimSigningAccount;
315 i != attestations.end())
319 *i = TAttestation{*att};
324 attestations.emplace_back(*att);
329 auto r = claimHelper(
332 typename TAttestation::MatchFields{*attBegin},
339 return {std::nullopt, changed};
341 return {std::move(r.value()), changed};
347Expected<std::vector<AccountID>,
TER>
349 XChainClaimAttestations& attestations,
350 ReadView
const& view,
351 STAmount
const& sendingAmount,
352 bool wasLockingChainSend,
357 XChainClaimAttestation::MatchFields toMatch{
358 sendingAmount, wasLockingChainSend, std::nullopt};
360 attestations, view, toMatch, CheckDst::ignore, quorum, signersList, j);
363enum class CanCreateDstPolicy {
no,
yes };
365enum class DepositAuthPolicy { normal, dstCanBypass };
369struct TransferHelperSubmittingAccountInfo
372 STAmount preFeeBalance;
373 STAmount postFeeBalance;
406 CanCreateDstPolicy canCreate,
407 DepositAuthPolicy depositAuthPolicy,
409 submittingAccountInfo,
416 if (
auto sleDst = psb.read(dstK))
426 bool const canBypassDepositAuth = dst == claimOwner &&
427 depositAuthPolicy == DepositAuthPolicy::dstCanBypass;
429 if (!canBypassDepositAuth && (sleDst->getFlags() &
lsfDepositAuth) &&
435 else if (!amt.native() || canCreate == CanCreateDstPolicy::no)
443 XRPL_ASSERT(sleSrc,
"ripple::transferHelper : non-null source account");
448 auto const ownerCount = sleSrc->getFieldU32(sfOwnerCount);
449 auto const reserve = psb.fees().accountReserve(ownerCount);
451 auto const availableBalance = [&]() -> STAmount {
452 STAmount
const curBal = (*sleSrc)[sfBalance];
456 if (!submittingAccountInfo ||
457 submittingAccountInfo->account != src ||
458 submittingAccountInfo->postFeeBalance != curBal)
460 return submittingAccountInfo->preFeeBalance;
463 if (availableBalance < amt + reserve)
469 auto sleDst = psb.peek(dstK);
472 if (canCreate == CanCreateDstPolicy::no)
477 if (amt < psb.fees().accountReserve(0))
479 JLOG(j.
trace()) <<
"Insufficient payment to create account.";
485 psb.rules().enabled(featureDeletableAccounts) ? psb.seq() : 1};
487 sleDst = std::make_shared<SLE>(dstK);
488 sleDst->setAccountID(sfAccount, dst);
489 sleDst->setFieldU32(sfSequence, seqno);
494 (*sleSrc)[sfBalance] = (*sleSrc)[sfBalance] - amt;
495 (*sleDst)[sfBalance] = (*sleDst)[sfBalance] + amt;
502 auto const result =
flow(
517 if (
auto const r = result.result();
528enum class OnTransferFail {
535struct FinalizeClaimHelperResult
556 if ((!mainFundsTer || *mainFundsTer ==
tesSUCCESS) &&
565 return *mainFundsTer;
574 if (mainFundsTer && mainFundsTer !=
tesSUCCESS)
575 return *mainFundsTer;
612FinalizeClaimHelperResult
614 PaymentSandbox& outerSb,
615 STXChainBridge
const& bridgeSpec,
619 STAmount
const& sendingAmount,
621 STAmount
const& rewardPool,
624 Keylet
const& claimIDKeylet,
625 OnTransferFail onTransferFail,
626 DepositAuthPolicy depositAuthPolicy,
629 FinalizeClaimHelperResult result;
633 STAmount
const thisChainAmount = [&] {
634 STAmount r = sendingAmount;
635 r.setIssue(bridgeSpec.issue(dstChain));
638 auto const& thisDoor = bridgeSpec.door(dstChain);
641 PaymentSandbox innerSb{&outerSb};
652 result.mainFundsTer = transferHelper(
659 CanCreateDstPolicy::yes,
665 onTransferFail == OnTransferFail::keepClaim)
671 result.rewardTer = [&]() ->
TER {
672 if (rewardAccounts.empty())
678 STAmount
const share = [&] {
679 auto const round_mode =
680 innerSb.rules().enabled(fixXChainRewardRounding)
685 STAmount
const den{rewardAccounts.size()};
686 return divide(rewardPool, den, rewardPool.issue());
688 STAmount distributed = rewardPool.zeroed();
689 for (
auto const& rewardAccount : rewardAccounts)
691 auto const thTer = transferHelper(
699 CanCreateDstPolicy::no,
700 DepositAuthPolicy::normal,
708 distributed += share;
714 if (distributed > rewardPool)
721 (onTransferFail == OnTransferFail::keepClaim ||
733 innerSb.apply(outerSb);
737 if (
auto const sleClaimID = outerSb.peek(claimIDKeylet))
739 auto const cidOwner = (*sleClaimID)[sfAccount];
743 auto const page = (*sleClaimID)[sfOwnerNode];
744 if (!outerSb.dirRemove(
748 <<
"Unable to delete xchain seq number from owner.";
754 outerSb.erase(sleClaimID);
773getSignersListAndQuorum(
774 ReadView
const& view,
775 SLE const& sleBridge,
781 AccountID const thisDoor = sleBridge[sfAccount];
782 auto const sleDoor = [&] {
return view.read(
keylet::account(thisDoor)); }();
794 q = (*sleS)[sfSignerQuorum];
803 for (
auto const& as : *accountSigners)
805 r[as.account] = as.weight;
811template <
class R,
class F>
813readOrpeekBridge(F&& getter, STXChainBridge
const& bridgeSpec)
816 if (
auto r = getter(bridgeSpec, ct))
818 if ((*r)[sfXChainBridge] == bridgeSpec)
829peekBridge(ApplyView& v, STXChainBridge
const& bridgeSpec)
831 return readOrpeekBridge<SLE>(
838readBridge(ReadView
const& v, STXChainBridge
const& bridgeSpec)
840 return readOrpeekBridge<SLE const>(
850template <
class TIter>
852applyClaimAttestations(
857 STXChainBridge
const& bridgeSpec,
863 if (attBegin == attEnd)
866 PaymentSandbox psb(&view);
868 auto const claimIDKeylet =
873 OnNewAttestationResult newAttResult;
874 STAmount rewardAmount;
878 auto const scopeResult = [&]() -> Expected<ScopeResult, TER> {
883 auto const sleClaimID = psb.peek(claimIDKeylet);
890 for (
auto att = attBegin; att != attEnd; ++att)
892 if (!signersList.
contains(att->attestationSignerAccount))
902 AccountID const otherChainSource = (*sleClaimID)[sfOtherChainSource];
903 if (attBegin->sendingAccount != otherChainSource)
915 if (attDstChain != dstChain)
921 XChainClaimAttestations curAtts{
922 sleClaimID->getFieldArray(sfXChainClaimAttestations)};
924 auto const newAttResult = onNewAttestations(
928 &atts[0] + atts.
size(),
934 sleClaimID->setFieldArray(
935 sfXChainClaimAttestations, curAtts.toSTArray());
936 psb.update(sleClaimID);
940 (*sleClaimID)[sfSignatureReward],
941 (*sleClaimID)[sfAccount]};
944 if (!scopeResult.has_value())
945 return scopeResult.error();
947 auto const& [newAttResult, rewardAmount, cidOwner] = scopeResult.value();
948 auto const& [rewardAccounts, attListChanged] = newAttResult;
949 if (rewardAccounts && attBegin->dst)
951 auto const r = finalizeClaimHelper(
957 attBegin->sendingAmount,
963 OnTransferFail::keepClaim,
964 DepositAuthPolicy::normal,
967 auto const rTer = r.ter();
979template <
class TIter>
981applyCreateAccountAttestations(
988 STXChainBridge
const& bridgeSpec,
989 Keylet
const& bridgeK,
995 if (attBegin == attEnd)
998 PaymentSandbox psb(&view);
1000 auto const claimCountResult = [&]() -> Expected<std::uint64_t, TER> {
1001 auto const sleBridge = psb.peek(bridgeK);
1005 return (*sleBridge)[sfXChainAccountClaimCount];
1008 if (!claimCountResult.has_value())
1009 return claimCountResult.error();
1013 if (attBegin->createCount <= claimCount)
1030 if (attDstChain != dstChain)
1036 auto const claimIDKeylet =
1041 OnNewAttestationResult newAttResult;
1043 XChainCreateAccountAttestations curAtts;
1046 auto const scopeResult = [&]() -> Expected<ScopeResult, TER> {
1054 auto const sleClaimID = psb.peek(claimIDKeylet);
1055 bool createCID =
false;
1060 auto const sleDoor = psb.peek(doorK);
1065 auto const balance = (*sleDoor)[sfBalance];
1066 auto const reserve =
1067 psb.fees().accountReserve((*sleDoor)[sfOwnerCount] + 1);
1069 if (balance < reserve)
1075 for (
auto att = attBegin; att != attEnd; ++att)
1077 if (!signersList.
contains(att->attestationSignerAccount))
1086 XChainCreateAccountAttestations curAtts = [&] {
1088 return XChainCreateAccountAttestations{
1089 sleClaimID->getFieldArray(
1090 sfXChainCreateAccountAttestations)};
1091 return XChainCreateAccountAttestations{};
1094 auto const newAttResult = onNewAttestations(
1098 &atts[0] + atts.
size(),
1109 sleClaimID->setFieldArray(
1110 sfXChainCreateAccountAttestations, curAtts.toSTArray());
1111 psb.update(sleClaimID);
1113 return ScopeResult{newAttResult, createCID, curAtts};
1116 if (!scopeResult.has_value())
1117 return scopeResult.error();
1119 auto const& [attResult, createCID, curAtts] = scopeResult.value();
1120 auto const& [rewardAccounts, attListChanged] = attResult;
1123 if (rewardAccounts && claimCount + 1 == attBegin->createCount)
1125 auto const r = finalizeClaimHelper(
1131 attBegin->sendingAmount,
1133 attBegin->rewardAmount,
1137 OnTransferFail::removeClaim,
1138 DepositAuthPolicy::normal,
1141 auto const rTer = r.ter();
1151 auto const sleBridge = psb.peek(bridgeK);
1154 (*sleBridge)[sfXChainAccountClaimCount] = attBegin->createCount;
1155 psb.update(sleBridge);
1159 auto const createdSleClaimID = std::make_shared<SLE>(claimIDKeylet);
1160 (*createdSleClaimID)[sfAccount] = doorAccount;
1161 (*createdSleClaimID)[sfXChainBridge] = bridgeSpec;
1162 (*createdSleClaimID)[sfXChainAccountCreateCount] =
1163 attBegin->createCount;
1164 createdSleClaimID->setFieldArray(
1165 sfXChainCreateAccountAttestations, curAtts.toSTArray());
1168 auto const page = psb.dirInsert(
1174 (*createdSleClaimID)[sfOwnerNode] = *
page;
1176 auto const sleDoor = psb.peek(doorK);
1182 psb.insert(createdSleClaimID);
1183 psb.update(sleDoor);
1191template <
class TAttestation>
1193toClaim(STTx
const& tx)
1196 std::is_same_v<TAttestation, Attestations::AttestationClaim> ||
1197 std::is_same_v<TAttestation, Attestations::AttestationCreateAccount>);
1202 o.setAccountID(sfAccount, o[sfOtherChainSource]);
1203 return TAttestation(o);
1208 return std::nullopt;
1211template <
class TAttestation>
1213attestationPreflight(PreflightContext
const& ctx)
1215 if (!ctx.rules.enabled(featureXChainBridge))
1227 auto const att = toClaim<TAttestation>(ctx.tx);
1231 STXChainBridge
const bridgeSpec = ctx.tx[sfXChainBridge];
1232 if (!att->verify(bridgeSpec))
1234 if (!att->validAmounts())
1237 if (att->sendingAmount.signum() <= 0)
1239 auto const expectedIssue =
1241 if (att->sendingAmount.issue() != expectedIssue)
1247template <
class TAttestation>
1249attestationPreclaim(PreclaimContext
const& ctx)
1251 auto const att = toClaim<TAttestation>(ctx.tx);
1255 STXChainBridge
const bridgeSpec = ctx.tx[sfXChainBridge];
1256 auto const sleBridge = readBridge(ctx.view, bridgeSpec);
1262 AccountID const attestationSignerAccount{
1263 ctx.tx[sfAttestationSignerAccount]};
1264 PublicKey
const pk{ctx.tx[sfPublicKey]};
1267 auto const [signersList, quorum, slTer] =
1268 getSignersListAndQuorum(ctx.view, *sleBridge, ctx.j);
1273 return checkAttestationPublicKey(
1274 ctx.view, signersList, attestationSignerAccount, pk, ctx.j);
1277template <
class TAttestation>
1279attestationDoApply(ApplyContext& ctx)
1281 auto const att = toClaim<TAttestation>(ctx.tx);
1286 STXChainBridge
const bridgeSpec = ctx.tx[sfXChainBridge];
1290 STXChainBridge::ChainType srcChain;
1297 auto const scopeResult = [&]() -> Expected<ScopeResult, TER> {
1302 auto sleBridge = readBridge(ctx.view(), bridgeSpec);
1307 Keylet
const bridgeK{ltBRIDGE, sleBridge->key()};
1308 AccountID const thisDoor = (*sleBridge)[sfAccount];
1312 if (thisDoor == bridgeSpec.lockingChainDoor())
1314 else if (thisDoor == bridgeSpec.issuingChainDoor())
1323 auto [signersList, quorum, slTer] =
1324 getSignersListAndQuorum(ctx.view(), *sleBridge, ctx.journal);
1330 srcChain, std::move(signersList), quorum, thisDoor, bridgeK};
1333 if (!scopeResult.has_value())
1334 return scopeResult.error();
1336 auto const& [srcChain, signersList, quorum, thisDoor, bridgeK] =
1337 scopeResult.value();
1340 std::is_same_v<TAttestation, Attestations::AttestationClaim> ||
1341 std::is_same_v<TAttestation, Attestations::AttestationCreateAccount>);
1343 if constexpr (std::is_same_v<TAttestation, Attestations::AttestationClaim>)
1345 return applyClaimAttestations(
1358 Attestations::AttestationCreateAccount>)
1360 return applyCreateAccountAttestations(
1391 auto const account = ctx.
tx[sfAccount];
1392 auto const reward = ctx.
tx[sfSignatureReward];
1393 auto const minAccountCreate = ctx.
tx[~sfMinAccountCreateAmount];
1394 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1396 if (bridgeSpec.lockingChainDoor() == bridgeSpec.issuingChainDoor())
1401 if (bridgeSpec.lockingChainDoor() != account &&
1402 bridgeSpec.issuingChainDoor() != account)
1407 if (
isXRP(bridgeSpec.lockingChainIssue()) !=
1408 isXRP(bridgeSpec.issuingChainIssue()))
1415 if (!
isXRP(reward) || reward.signum() < 0)
1420 if (minAccountCreate &&
1421 ((!
isXRP(*minAccountCreate) || minAccountCreate->signum() <= 0) ||
1422 !
isXRP(bridgeSpec.lockingChainIssue()) ||
1423 !
isXRP(bridgeSpec.issuingChainIssue())))
1428 if (
isXRP(bridgeSpec.issuingChainIssue()))
1437 if (bridgeSpec.issuingChainDoor() != rootAccount)
1446 if (bridgeSpec.issuingChainDoor() !=
1447 bridgeSpec.issuingChainIssue().account)
1453 if (bridgeSpec.lockingChainDoor() == bridgeSpec.lockingChainIssue().account)
1466 auto const account = ctx.
tx[sfAccount];
1467 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1483 if (!
isXRP(bridgeSpec.issue(chainType)))
1485 auto const sleIssuer =
1503 auto const balance = (*sleAcc)[sfBalance];
1504 auto const reserve =
1507 if (balance < reserve)
1517 auto const account =
ctx_.
tx[sfAccount];
1518 auto const bridgeSpec =
ctx_.
tx[sfXChainBridge];
1519 auto const reward =
ctx_.
tx[sfSignatureReward];
1520 auto const minAccountCreate =
ctx_.
tx[~sfMinAccountCreateAmount];
1530 auto const sleBridge = std::make_shared<SLE>(bridgeKeylet);
1532 (*sleBridge)[sfAccount] = account;
1533 (*sleBridge)[sfSignatureReward] = reward;
1534 if (minAccountCreate)
1535 (*sleBridge)[sfMinAccountCreateAmount] = *minAccountCreate;
1536 (*sleBridge)[sfXChainBridge] = bridgeSpec;
1537 (*sleBridge)[sfXChainClaimID] = 0;
1538 (*sleBridge)[sfXChainAccountCreateCount] = 0;
1539 (*sleBridge)[sfXChainAccountClaimCount] = 0;
1547 (*sleBridge)[sfOwnerNode] = *page;
1572 auto const account = ctx.
tx[sfAccount];
1573 auto const reward = ctx.
tx[~sfSignatureReward];
1574 auto const minAccountCreate = ctx.
tx[~sfMinAccountCreateAmount];
1575 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1576 bool const clearAccountCreate =
1579 if (!reward && !minAccountCreate && !clearAccountCreate)
1585 if (minAccountCreate && clearAccountCreate)
1591 if (bridgeSpec.lockingChainDoor() != account &&
1592 bridgeSpec.issuingChainDoor() != account)
1597 if (reward && (!
isXRP(*reward) || reward->signum() < 0))
1602 if (minAccountCreate &&
1603 ((!
isXRP(*minAccountCreate) || minAccountCreate->signum() <= 0) ||
1604 !
isXRP(bridgeSpec.lockingChainIssue()) ||
1605 !
isXRP(bridgeSpec.issuingChainIssue())))
1616 auto const account = ctx.
tx[sfAccount];
1617 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1633 auto const account =
ctx_.
tx[sfAccount];
1634 auto const bridgeSpec =
ctx_.
tx[sfXChainBridge];
1635 auto const reward =
ctx_.
tx[~sfSignatureReward];
1636 auto const minAccountCreate =
ctx_.
tx[~sfMinAccountCreateAmount];
1637 bool const clearAccountCreate =
1647 auto const sleBridge =
1653 (*sleBridge)[sfSignatureReward] = *reward;
1654 if (minAccountCreate)
1656 (*sleBridge)[sfMinAccountCreateAmount] = *minAccountCreate;
1658 if (clearAccountCreate &&
1659 sleBridge->isFieldPresent(sfMinAccountCreateAmount))
1661 sleBridge->makeFieldAbsent(sfMinAccountCreateAmount);
1683 auto const amount = ctx.
tx[sfAmount];
1685 if (amount.signum() <= 0 ||
1700 STAmount const& thisChainAmount = ctx.
tx[sfAmount];
1701 auto const claimID = ctx.
tx[sfXChainClaimID];
1703 auto const sleBridge = readBridge(ctx.
view, bridgeSpec);
1714 auto const thisDoor = (*sleBridge)[sfAccount];
1715 bool isLockingChain =
false;
1718 isLockingChain =
true;
1720 isLockingChain =
false;
1749 auto const otherChainAmount = [&]() ->
STAmount {
1758 auto const sleClaimID =
1768 if ((*sleClaimID)[sfAccount] != account)
1785 auto const dst =
ctx_.
tx[sfDestination];
1788 auto const claimID =
ctx_.
tx[sfXChainClaimID];
1807 auto const sleBridge = peekBridge(psb, bridgeSpec);
1808 auto const sleClaimID = psb.
peek(claimIDKeylet);
1810 if (!(sleBridge && sleClaimID && sleAcct))
1813 AccountID const thisDoor = (*sleBridge)[sfAccount];
1827 auto const sendingAmount = [&]() ->
STAmount {
1833 auto const [signersList, quorum, slTer] =
1840 sleClaimID->getFieldArray(sfXChainClaimAttestations)};
1842 auto const claimR = onClaim(
1851 if (!claimR.has_value())
1856 (*sleClaimID)[sfAccount],
1859 (*sleClaimID)[sfSignatureReward],
1863 if (!scopeResult.has_value())
1864 return scopeResult.error();
1866 auto const& [rewardAccounts, rewardPoolSrc, sendingAmount, srcChain, signatureReward] =
1867 scopeResult.value();
1870 auto const r = finalizeClaimHelper(
1882 OnTransferFail::keepClaim,
1883 DepositAuthPolicy::dstCanBypass,
1885 if (!r.isTesSuccess())
1898 auto const maxSpend = [&] {
1899 auto const amount = ctx.
tx[sfAmount];
1900 if (amount.native() && amount.signum() > 0)
1901 return amount.xrp();
1920 auto const amount = ctx.
tx[sfAmount];
1921 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1923 if (amount.signum() <= 0 || !
isLegalNet(amount))
1926 if (amount.issue() != bridgeSpec.lockingChainIssue() &&
1927 amount.issue() != bridgeSpec.issuingChainIssue())
1936 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1937 auto const amount = ctx.
tx[sfAmount];
1939 auto const sleBridge = readBridge(ctx.
view, bridgeSpec);
1945 AccountID const thisDoor = (*sleBridge)[sfAccount];
1948 if (thisDoor == account)
1954 bool isLockingChain =
false;
1956 if (thisDoor == bridgeSpec.lockingChainDoor())
1957 isLockingChain =
true;
1958 else if (thisDoor == bridgeSpec.issuingChainDoor())
1959 isLockingChain =
false;
1966 if (bridgeSpec.lockingChainIssue() != ctx.
tx[sfAmount].issue())
1971 if (bridgeSpec.issuingChainIssue() != ctx.
tx[sfAmount].issue())
1983 auto const account =
ctx_.
tx[sfAccount];
1984 auto const amount =
ctx_.
tx[sfAmount];
1985 auto const bridgeSpec =
ctx_.
tx[sfXChainBridge];
1990 auto const sleBridge = readBridge(psb, bridgeSpec);
1994 auto const dst = (*sleBridge)[sfAccount];
1997 TransferHelperSubmittingAccountInfo submittingAccountInfo{
2000 auto const thTer = transferHelper(
2007 CanCreateDstPolicy::no,
2008 DepositAuthPolicy::normal,
2009 submittingAccountInfo,
2034 auto const reward = ctx.
tx[sfSignatureReward];
2045 auto const account = ctx.
tx[sfAccount];
2046 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
2047 auto const sleBridge = readBridge(ctx.
view, bridgeSpec);
2055 auto const reward = ctx.
tx[sfSignatureReward];
2057 if (reward != (*sleBridge)[sfSignatureReward])
2068 auto const balance = (*sleAcc)[sfBalance];
2069 auto const reserve =
2072 if (balance < reserve)
2082 auto const account =
ctx_.
tx[sfAccount];
2083 auto const bridgeSpec =
ctx_.
tx[sfXChainBridge];
2084 auto const reward =
ctx_.
tx[sfSignatureReward];
2085 auto const otherChainSrc =
ctx_.
tx[sfOtherChainSource];
2091 auto const sleBridge = peekBridge(
ctx_.
view(), bridgeSpec);
2095 std::uint32_t const claimID = (*sleBridge)[sfXChainClaimID] + 1;
2099 (*sleBridge)[sfXChainClaimID] = claimID;
2105 auto const sleClaimID = std::make_shared<SLE>(claimIDKeylet);
2107 (*sleClaimID)[sfAccount] = account;
2108 (*sleClaimID)[sfXChainBridge] = bridgeSpec;
2109 (*sleClaimID)[sfXChainClaimID] = claimID;
2110 (*sleClaimID)[sfOtherChainSource] = otherChainSrc;
2111 (*sleClaimID)[sfSignatureReward] = reward;
2112 sleClaimID->setFieldArray(
2113 sfXChainClaimAttestations,
STArray{sfXChainClaimAttestations});
2123 (*sleClaimID)[sfOwnerNode] = *page;
2140 return attestationPreflight<Attestations::AttestationClaim>(ctx);
2146 return attestationPreclaim<Attestations::AttestationClaim>(ctx);
2152 return attestationDoApply<Attestations::AttestationClaim>(
ctx_);
2160 return attestationPreflight<Attestations::AttestationCreateAccount>(ctx);
2166 return attestationPreclaim<Attestations::AttestationCreateAccount>(ctx);
2172 return attestationDoApply<Attestations::AttestationCreateAccount>(
ctx_);
2189 auto const amount = ctx.
tx[sfAmount];
2191 if (amount.signum() <= 0 || !amount.native())
2194 auto const reward = ctx.
tx[sfSignatureReward];
2195 if (reward.signum() < 0 || !reward.native())
2198 if (reward.issue() != amount.issue())
2209 STAmount const reward = ctx.
tx[sfSignatureReward];
2211 auto const sleBridge = readBridge(ctx.
view, bridgeSpec);
2217 if (reward != (*sleBridge)[sfSignatureReward])
2223 (*sleBridge)[~sfMinAccountCreateAmount];
2225 if (!minCreateAmount)
2228 if (amount < *minCreateAmount)
2231 if (minCreateAmount->issue() != amount.
issue())
2234 AccountID const thisDoor = (*sleBridge)[sfAccount];
2236 if (thisDoor == account)
2254 if (bridgeSpec.
issue(srcChain) != ctx.
tx[sfAmount].issue())
2277 auto const sleBridge = peekBridge(psb, bridge);
2281 auto const dst = (*sleBridge)[sfAccount];
2284 TransferHelperSubmittingAccountInfo submittingAccountInfo{
2286 STAmount const toTransfer = amount + reward;
2287 auto const thTer = transferHelper(
2294 CanCreateDstPolicy::yes,
2295 DepositAuthPolicy::normal,
2296 submittingAccountInfo,
2302 (*sleBridge)[sfXChainAccountCreateCount] =
2303 (*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 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.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
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
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
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.
static bool adjustOwnerCount(ApplyContext &ctx, int count)
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
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
constexpr std::uint32_t tfUniversalMask
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.