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())
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},
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{
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};
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);
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)
1202 o.setAccountID(sfAccount, o[sfOtherChainSource]);
1203 return TAttestation(o);
1211template <
class TAttestation>
1213attestationpreflight(PreflightContext
const& ctx)
1218 auto const att = toClaim<TAttestation>(ctx.tx);
1222 STXChainBridge
const bridgeSpec = ctx.tx[sfXChainBridge];
1223 if (!att->verify(bridgeSpec))
1225 if (!att->validAmounts())
1228 if (att->sendingAmount.signum() <= 0)
1230 auto const expectedIssue =
1232 if (att->sendingAmount.issue() != expectedIssue)
1238template <
class TAttestation>
1240attestationPreclaim(PreclaimContext
const& ctx)
1242 auto const att = toClaim<TAttestation>(ctx.tx);
1246 STXChainBridge
const bridgeSpec = ctx.tx[sfXChainBridge];
1247 auto const sleBridge = readBridge(ctx.view, bridgeSpec);
1253 AccountID const attestationSignerAccount{
1254 ctx.tx[sfAttestationSignerAccount]};
1255 PublicKey
const pk{ctx.tx[sfPublicKey]};
1258 auto const [signersList, quorum, slTer] =
1259 getSignersListAndQuorum(ctx.view, *sleBridge, ctx.j);
1264 return checkAttestationPublicKey(
1265 ctx.view, signersList, attestationSignerAccount, pk, ctx.j);
1268template <
class TAttestation>
1270attestationDoApply(ApplyContext& ctx)
1272 auto const att = toClaim<TAttestation>(ctx.tx);
1277 STXChainBridge
const bridgeSpec = ctx.tx[sfXChainBridge];
1281 STXChainBridge::ChainType srcChain;
1288 auto const scopeResult = [&]() -> Expected<ScopeResult, TER> {
1293 auto sleBridge = readBridge(ctx.view(), bridgeSpec);
1298 Keylet
const bridgeK{ltBRIDGE, sleBridge->key()};
1299 AccountID const thisDoor = (*sleBridge)[sfAccount];
1303 if (thisDoor == bridgeSpec.lockingChainDoor())
1305 else if (thisDoor == bridgeSpec.issuingChainDoor())
1314 auto [signersList, quorum, slTer] =
1315 getSignersListAndQuorum(ctx.view(), *sleBridge, ctx.journal);
1321 srcChain, std::move(signersList), quorum, thisDoor, bridgeK};
1324 if (!scopeResult.has_value())
1325 return scopeResult.error();
1327 auto const& [srcChain, signersList, quorum, thisDoor, bridgeK] =
1328 scopeResult.value();
1336 return applyClaimAttestations(
1349 Attestations::AttestationCreateAccount>)
1351 return applyCreateAccountAttestations(
1373 auto const account = ctx.
tx[sfAccount];
1374 auto const reward = ctx.
tx[sfSignatureReward];
1375 auto const minAccountCreate = ctx.
tx[~sfMinAccountCreateAmount];
1376 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1378 if (bridgeSpec.lockingChainDoor() == bridgeSpec.issuingChainDoor())
1383 if (bridgeSpec.lockingChainDoor() != account &&
1384 bridgeSpec.issuingChainDoor() != account)
1389 if (
isXRP(bridgeSpec.lockingChainIssue()) !=
1390 isXRP(bridgeSpec.issuingChainIssue()))
1397 if (!
isXRP(reward) || reward.signum() < 0)
1402 if (minAccountCreate &&
1403 ((!
isXRP(*minAccountCreate) || minAccountCreate->signum() <= 0) ||
1404 !
isXRP(bridgeSpec.lockingChainIssue()) ||
1405 !
isXRP(bridgeSpec.issuingChainIssue())))
1410 if (
isXRP(bridgeSpec.issuingChainIssue()))
1419 if (bridgeSpec.issuingChainDoor() != rootAccount)
1428 if (bridgeSpec.issuingChainDoor() !=
1429 bridgeSpec.issuingChainIssue().account)
1435 if (bridgeSpec.lockingChainDoor() == bridgeSpec.lockingChainIssue().account)
1448 auto const account = ctx.
tx[sfAccount];
1449 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1465 if (!
isXRP(bridgeSpec.issue(chainType)))
1467 auto const sleIssuer =
1485 auto const balance = (*sleAcc)[sfBalance];
1486 auto const reserve =
1489 if (balance < reserve)
1499 auto const account =
ctx_.
tx[sfAccount];
1500 auto const bridgeSpec =
ctx_.
tx[sfXChainBridge];
1501 auto const reward =
ctx_.
tx[sfSignatureReward];
1502 auto const minAccountCreate =
ctx_.
tx[~sfMinAccountCreateAmount];
1514 (*sleBridge)[sfAccount] = account;
1515 (*sleBridge)[sfSignatureReward] = reward;
1516 if (minAccountCreate)
1517 (*sleBridge)[sfMinAccountCreateAmount] = *minAccountCreate;
1518 (*sleBridge)[sfXChainBridge] = bridgeSpec;
1519 (*sleBridge)[sfXChainClaimID] = 0;
1520 (*sleBridge)[sfXChainAccountCreateCount] = 0;
1521 (*sleBridge)[sfXChainAccountClaimCount] = 0;
1529 (*sleBridge)[sfOwnerNode] = *page;
1551 auto const account = ctx.
tx[sfAccount];
1552 auto const reward = ctx.
tx[~sfSignatureReward];
1553 auto const minAccountCreate = ctx.
tx[~sfMinAccountCreateAmount];
1554 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1555 bool const clearAccountCreate =
1558 if (!reward && !minAccountCreate && !clearAccountCreate)
1564 if (minAccountCreate && clearAccountCreate)
1570 if (bridgeSpec.lockingChainDoor() != account &&
1571 bridgeSpec.issuingChainDoor() != account)
1576 if (reward && (!
isXRP(*reward) || reward->signum() < 0))
1581 if (minAccountCreate &&
1582 ((!
isXRP(*minAccountCreate) || minAccountCreate->signum() <= 0) ||
1583 !
isXRP(bridgeSpec.lockingChainIssue()) ||
1584 !
isXRP(bridgeSpec.issuingChainIssue())))
1595 auto const account = ctx.
tx[sfAccount];
1596 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1612 auto const account =
ctx_.
tx[sfAccount];
1613 auto const bridgeSpec =
ctx_.
tx[sfXChainBridge];
1614 auto const reward =
ctx_.
tx[~sfSignatureReward];
1615 auto const minAccountCreate =
ctx_.
tx[~sfMinAccountCreateAmount];
1616 bool const clearAccountCreate =
1626 auto const sleBridge =
1632 (*sleBridge)[sfSignatureReward] = *reward;
1633 if (minAccountCreate)
1635 (*sleBridge)[sfMinAccountCreateAmount] = *minAccountCreate;
1637 if (clearAccountCreate &&
1638 sleBridge->isFieldPresent(sfMinAccountCreateAmount))
1640 sleBridge->makeFieldAbsent(sfMinAccountCreateAmount);
1653 auto const amount = ctx.
tx[sfAmount];
1655 if (amount.signum() <= 0 ||
1670 STAmount const& thisChainAmount = ctx.
tx[sfAmount];
1671 auto const claimID = ctx.
tx[sfXChainClaimID];
1673 auto const sleBridge = readBridge(ctx.
view, bridgeSpec);
1684 auto const thisDoor = (*sleBridge)[sfAccount];
1685 bool isLockingChain =
false;
1688 isLockingChain =
true;
1690 isLockingChain =
false;
1719 auto const otherChainAmount = [&]() ->
STAmount {
1728 auto const sleClaimID =
1738 if ((*sleClaimID)[sfAccount] != account)
1755 auto const dst =
ctx_.
tx[sfDestination];
1758 auto const claimID =
ctx_.
tx[sfXChainClaimID];
1777 auto const sleBridge = peekBridge(psb, bridgeSpec);
1778 auto const sleClaimID = psb.
peek(claimIDKeylet);
1780 if (!(sleBridge && sleClaimID && sleAcct))
1783 AccountID const thisDoor = (*sleBridge)[sfAccount];
1797 auto const sendingAmount = [&]() ->
STAmount {
1803 auto const [signersList, quorum, slTer] =
1810 sleClaimID->getFieldArray(sfXChainClaimAttestations)};
1812 auto const claimR = onClaim(
1821 if (!claimR.has_value())
1826 (*sleClaimID)[sfAccount],
1829 (*sleClaimID)[sfSignatureReward],
1833 if (!scopeResult.has_value())
1834 return scopeResult.error();
1836 auto const& [rewardAccounts, rewardPoolSrc, sendingAmount, srcChain, signatureReward] =
1837 scopeResult.value();
1840 auto const r = finalizeClaimHelper(
1852 OnTransferFail::keepClaim,
1853 DepositAuthPolicy::dstCanBypass,
1855 if (!r.isTesSuccess())
1868 auto const maxSpend = [&] {
1869 auto const amount = ctx.
tx[sfAmount];
1870 if (amount.native() && amount.signum() > 0)
1871 return amount.xrp();
1881 auto const amount = ctx.
tx[sfAmount];
1882 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1884 if (amount.signum() <= 0 || !
isLegalNet(amount))
1887 if (amount.issue() != bridgeSpec.lockingChainIssue() &&
1888 amount.issue() != bridgeSpec.issuingChainIssue())
1897 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1898 auto const amount = ctx.
tx[sfAmount];
1900 auto const sleBridge = readBridge(ctx.
view, bridgeSpec);
1906 AccountID const thisDoor = (*sleBridge)[sfAccount];
1909 if (thisDoor == account)
1915 bool isLockingChain =
false;
1917 if (thisDoor == bridgeSpec.lockingChainDoor())
1918 isLockingChain =
true;
1919 else if (thisDoor == bridgeSpec.issuingChainDoor())
1920 isLockingChain =
false;
1927 if (bridgeSpec.lockingChainIssue() != ctx.
tx[sfAmount].issue())
1932 if (bridgeSpec.issuingChainIssue() != ctx.
tx[sfAmount].issue())
1944 auto const account =
ctx_.
tx[sfAccount];
1945 auto const amount =
ctx_.
tx[sfAmount];
1946 auto const bridgeSpec =
ctx_.
tx[sfXChainBridge];
1951 auto const sleBridge = readBridge(psb, bridgeSpec);
1955 auto const dst = (*sleBridge)[sfAccount];
1958 TransferHelperSubmittingAccountInfo submittingAccountInfo{
1961 auto const thTer = transferHelper(
1968 CanCreateDstPolicy::no,
1969 DepositAuthPolicy::normal,
1970 submittingAccountInfo,
1986 auto const reward = ctx.
tx[sfSignatureReward];
1997 auto const account = ctx.
tx[sfAccount];
1998 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1999 auto const sleBridge = readBridge(ctx.
view, bridgeSpec);
2007 auto const reward = ctx.
tx[sfSignatureReward];
2009 if (reward != (*sleBridge)[sfSignatureReward])
2020 auto const balance = (*sleAcc)[sfBalance];
2021 auto const reserve =
2024 if (balance < reserve)
2034 auto const account =
ctx_.
tx[sfAccount];
2035 auto const bridgeSpec =
ctx_.
tx[sfXChainBridge];
2036 auto const reward =
ctx_.
tx[sfSignatureReward];
2037 auto const otherChainSrc =
ctx_.
tx[sfOtherChainSource];
2043 auto const sleBridge = peekBridge(
ctx_.
view(), bridgeSpec);
2047 std::uint32_t const claimID = (*sleBridge)[sfXChainClaimID] + 1;
2051 (*sleBridge)[sfXChainClaimID] = claimID;
2059 (*sleClaimID)[sfAccount] = account;
2060 (*sleClaimID)[sfXChainBridge] = bridgeSpec;
2061 (*sleClaimID)[sfXChainClaimID] = claimID;
2062 (*sleClaimID)[sfOtherChainSource] = otherChainSrc;
2063 (*sleClaimID)[sfSignatureReward] = reward;
2064 sleClaimID->setFieldArray(
2065 sfXChainClaimAttestations,
STArray{sfXChainClaimAttestations});
2075 (*sleClaimID)[sfOwnerNode] = *page;
2092 return attestationpreflight<Attestations::AttestationClaim>(ctx);
2098 return attestationPreclaim<Attestations::AttestationClaim>(ctx);
2104 return attestationDoApply<Attestations::AttestationClaim>(
ctx_);
2112 return attestationpreflight<Attestations::AttestationCreateAccount>(ctx);
2118 return attestationPreclaim<Attestations::AttestationCreateAccount>(ctx);
2124 return attestationDoApply<Attestations::AttestationCreateAccount>(
ctx_);
2132 auto const amount = ctx.
tx[sfAmount];
2134 if (amount.signum() <= 0 || !amount.native())
2137 auto const reward = ctx.
tx[sfSignatureReward];
2138 if (reward.signum() < 0 || !reward.native())
2141 if (reward.issue() != amount.issue())
2152 STAmount const reward = ctx.
tx[sfSignatureReward];
2154 auto const sleBridge = readBridge(ctx.
view, bridgeSpec);
2160 if (reward != (*sleBridge)[sfSignatureReward])
2166 (*sleBridge)[~sfMinAccountCreateAmount];
2168 if (!minCreateAmount)
2171 if (amount < *minCreateAmount)
2174 if (minCreateAmount->issue() != amount.
issue())
2177 AccountID const thisDoor = (*sleBridge)[sfAccount];
2179 if (thisDoor == account)
2197 if (bridgeSpec.
issue(srcChain) != ctx.
tx[sfAmount].issue())
2220 auto const sleBridge = peekBridge(psb, bridge);
2224 auto const dst = (*sleBridge)[sfAccount];
2227 TransferHelperSubmittingAccountInfo submittingAccountInfo{
2229 STAmount const toTransfer = amount + reward;
2230 auto const thTer = transferHelper(
2237 CanCreateDstPolicy::yes,
2238 DepositAuthPolicy::normal,
2239 submittingAccountInfo,
2245 (*sleBridge)[sfXChainAccountCreateCount] =
2246 (*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.