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(
516 if (
auto const r = result.result();
527enum class OnTransferFail {
534struct FinalizeClaimHelperResult
555 if ((!mainFundsTer || *mainFundsTer ==
tesSUCCESS) &&
564 return *mainFundsTer;
573 if (mainFundsTer && mainFundsTer !=
tesSUCCESS)
574 return *mainFundsTer;
611FinalizeClaimHelperResult
613 PaymentSandbox& outerSb,
614 STXChainBridge
const& bridgeSpec,
618 STAmount
const& sendingAmount,
620 STAmount
const& rewardPool,
623 Keylet
const& claimIDKeylet,
624 OnTransferFail onTransferFail,
625 DepositAuthPolicy depositAuthPolicy,
628 FinalizeClaimHelperResult result;
632 STAmount
const thisChainAmount = [&] {
633 STAmount r = sendingAmount;
634 r.setIssue(bridgeSpec.issue(dstChain));
637 auto const& thisDoor = bridgeSpec.door(dstChain);
640 PaymentSandbox innerSb{&outerSb};
651 result.mainFundsTer = transferHelper(
658 CanCreateDstPolicy::yes,
664 onTransferFail == OnTransferFail::keepClaim)
670 result.rewardTer = [&]() ->
TER {
671 if (rewardAccounts.empty())
677 STAmount
const share = [&] {
678 auto const round_mode =
679 innerSb.rules().enabled(fixXChainRewardRounding)
684 STAmount
const den{rewardAccounts.size()};
685 return divide(rewardPool, den, rewardPool.issue());
687 STAmount distributed = rewardPool.zeroed();
688 for (
auto const& rewardAccount : rewardAccounts)
690 auto const thTer = transferHelper(
698 CanCreateDstPolicy::no,
699 DepositAuthPolicy::normal,
707 distributed += share;
713 if (distributed > rewardPool)
720 (onTransferFail == OnTransferFail::keepClaim ||
732 innerSb.apply(outerSb);
736 if (
auto const sleClaimID = outerSb.peek(claimIDKeylet))
738 auto const cidOwner = (*sleClaimID)[sfAccount];
742 auto const page = (*sleClaimID)[sfOwnerNode];
743 if (!outerSb.dirRemove(
747 <<
"Unable to delete xchain seq number from owner.";
753 outerSb.erase(sleClaimID);
772getSignersListAndQuorum(
773 ReadView
const& view,
774 SLE const& sleBridge,
780 AccountID const thisDoor = sleBridge[sfAccount];
781 auto const sleDoor = [&] {
return view.read(
keylet::account(thisDoor)); }();
793 q = (*sleS)[sfSignerQuorum];
802 for (
auto const& as : *accountSigners)
804 r[as.account] = as.weight;
810template <
class R,
class F>
812readOrpeekBridge(F&& getter, STXChainBridge
const& bridgeSpec)
815 if (
auto r = getter(bridgeSpec, ct))
817 if ((*r)[sfXChainBridge] == bridgeSpec)
828peekBridge(ApplyView& v, STXChainBridge
const& bridgeSpec)
830 return readOrpeekBridge<SLE>(
837readBridge(ReadView
const& v, STXChainBridge
const& bridgeSpec)
839 return readOrpeekBridge<SLE const>(
849template <
class TIter>
851applyClaimAttestations(
856 STXChainBridge
const& bridgeSpec,
862 if (attBegin == attEnd)
865 PaymentSandbox psb(&view);
867 auto const claimIDKeylet =
872 OnNewAttestationResult newAttResult;
873 STAmount rewardAmount;
877 auto const scopeResult = [&]() -> Expected<ScopeResult, TER> {
882 auto const sleClaimID = psb.peek(claimIDKeylet);
889 for (
auto att = attBegin; att != attEnd; ++att)
891 if (!signersList.
contains(att->attestationSignerAccount))
901 AccountID const otherChainSource = (*sleClaimID)[sfOtherChainSource];
902 if (attBegin->sendingAccount != otherChainSource)
914 if (attDstChain != dstChain)
920 XChainClaimAttestations curAtts{
921 sleClaimID->getFieldArray(sfXChainClaimAttestations)};
923 auto const newAttResult = onNewAttestations(
927 &atts[0] + atts.
size(),
933 sleClaimID->setFieldArray(
934 sfXChainClaimAttestations, curAtts.toSTArray());
935 psb.update(sleClaimID);
939 (*sleClaimID)[sfSignatureReward],
940 (*sleClaimID)[sfAccount]};
943 if (!scopeResult.has_value())
944 return scopeResult.error();
946 auto const& [newAttResult, rewardAmount, cidOwner] = scopeResult.value();
947 auto const& [rewardAccounts, attListChanged] = newAttResult;
948 if (rewardAccounts && attBegin->dst)
950 auto const r = finalizeClaimHelper(
956 attBegin->sendingAmount,
962 OnTransferFail::keepClaim,
963 DepositAuthPolicy::normal,
966 auto const rTer = r.ter();
978template <
class TIter>
980applyCreateAccountAttestations(
987 STXChainBridge
const& bridgeSpec,
988 Keylet
const& bridgeK,
994 if (attBegin == attEnd)
997 PaymentSandbox psb(&view);
999 auto const claimCountResult = [&]() -> Expected<std::uint64_t, TER> {
1000 auto const sleBridge = psb.peek(bridgeK);
1004 return (*sleBridge)[sfXChainAccountClaimCount];
1007 if (!claimCountResult.has_value())
1008 return claimCountResult.error();
1012 if (attBegin->createCount <= claimCount)
1029 if (attDstChain != dstChain)
1035 auto const claimIDKeylet =
1040 OnNewAttestationResult newAttResult;
1042 XChainCreateAccountAttestations curAtts;
1045 auto const scopeResult = [&]() -> Expected<ScopeResult, TER> {
1053 auto const sleClaimID = psb.peek(claimIDKeylet);
1054 bool createCID =
false;
1059 auto const sleDoor = psb.peek(doorK);
1064 auto const balance = (*sleDoor)[sfBalance];
1065 auto const reserve =
1066 psb.fees().accountReserve((*sleDoor)[sfOwnerCount] + 1);
1068 if (balance < reserve)
1074 for (
auto att = attBegin; att != attEnd; ++att)
1076 if (!signersList.
contains(att->attestationSignerAccount))
1085 XChainCreateAccountAttestations curAtts = [&] {
1087 return XChainCreateAccountAttestations{
1088 sleClaimID->getFieldArray(
1089 sfXChainCreateAccountAttestations)};
1090 return XChainCreateAccountAttestations{};
1093 auto const newAttResult = onNewAttestations(
1097 &atts[0] + atts.
size(),
1108 sleClaimID->setFieldArray(
1109 sfXChainCreateAccountAttestations, curAtts.toSTArray());
1110 psb.update(sleClaimID);
1112 return ScopeResult{newAttResult, createCID, curAtts};
1115 if (!scopeResult.has_value())
1116 return scopeResult.error();
1118 auto const& [attResult, createCID, curAtts] = scopeResult.value();
1119 auto const& [rewardAccounts, attListChanged] = attResult;
1122 if (rewardAccounts && claimCount + 1 == attBegin->createCount)
1124 auto const r = finalizeClaimHelper(
1130 attBegin->sendingAmount,
1132 attBegin->rewardAmount,
1136 OnTransferFail::removeClaim,
1137 DepositAuthPolicy::normal,
1140 auto const rTer = r.ter();
1150 auto const sleBridge = psb.peek(bridgeK);
1153 (*sleBridge)[sfXChainAccountClaimCount] = attBegin->createCount;
1154 psb.update(sleBridge);
1158 auto const createdSleClaimID = std::make_shared<SLE>(claimIDKeylet);
1159 (*createdSleClaimID)[sfAccount] = doorAccount;
1160 (*createdSleClaimID)[sfXChainBridge] = bridgeSpec;
1161 (*createdSleClaimID)[sfXChainAccountCreateCount] =
1162 attBegin->createCount;
1163 createdSleClaimID->setFieldArray(
1164 sfXChainCreateAccountAttestations, curAtts.toSTArray());
1167 auto const page = psb.dirInsert(
1173 (*createdSleClaimID)[sfOwnerNode] = *
page;
1175 auto const sleDoor = psb.peek(doorK);
1181 psb.insert(createdSleClaimID);
1182 psb.update(sleDoor);
1190template <
class TAttestation>
1192toClaim(STTx
const& tx)
1195 std::is_same_v<TAttestation, Attestations::AttestationClaim> ||
1196 std::is_same_v<TAttestation, Attestations::AttestationCreateAccount>);
1201 o.setAccountID(sfAccount, o[sfOtherChainSource]);
1202 return TAttestation(o);
1207 return std::nullopt;
1210template <
class TAttestation>
1212attestationPreflight(PreflightContext
const& ctx)
1214 if (!ctx.rules.enabled(featureXChainBridge))
1226 auto const att = toClaim<TAttestation>(ctx.tx);
1230 STXChainBridge
const bridgeSpec = ctx.tx[sfXChainBridge];
1231 if (!att->verify(bridgeSpec))
1233 if (!att->validAmounts())
1236 if (att->sendingAmount.signum() <= 0)
1238 auto const expectedIssue =
1240 if (att->sendingAmount.issue() != expectedIssue)
1246template <
class TAttestation>
1248attestationPreclaim(PreclaimContext
const& ctx)
1250 auto const att = toClaim<TAttestation>(ctx.tx);
1254 STXChainBridge
const bridgeSpec = ctx.tx[sfXChainBridge];
1255 auto const sleBridge = readBridge(ctx.view, bridgeSpec);
1261 AccountID const attestationSignerAccount{
1262 ctx.tx[sfAttestationSignerAccount]};
1263 PublicKey
const pk{ctx.tx[sfPublicKey]};
1266 auto const [signersList, quorum, slTer] =
1267 getSignersListAndQuorum(ctx.view, *sleBridge, ctx.j);
1272 return checkAttestationPublicKey(
1273 ctx.view, signersList, attestationSignerAccount, pk, ctx.j);
1276template <
class TAttestation>
1278attestationDoApply(ApplyContext& ctx)
1280 auto const att = toClaim<TAttestation>(ctx.tx);
1285 STXChainBridge
const bridgeSpec = ctx.tx[sfXChainBridge];
1289 STXChainBridge::ChainType srcChain;
1296 auto const scopeResult = [&]() -> Expected<ScopeResult, TER> {
1301 auto sleBridge = readBridge(ctx.view(), bridgeSpec);
1306 Keylet
const bridgeK{ltBRIDGE, sleBridge->key()};
1307 AccountID const thisDoor = (*sleBridge)[sfAccount];
1311 if (thisDoor == bridgeSpec.lockingChainDoor())
1313 else if (thisDoor == bridgeSpec.issuingChainDoor())
1322 auto [signersList, quorum, slTer] =
1323 getSignersListAndQuorum(ctx.view(), *sleBridge, ctx.journal);
1329 srcChain, std::move(signersList), quorum, thisDoor, bridgeK};
1332 if (!scopeResult.has_value())
1333 return scopeResult.error();
1335 auto const& [srcChain, signersList, quorum, thisDoor, bridgeK] =
1336 scopeResult.value();
1339 std::is_same_v<TAttestation, Attestations::AttestationClaim> ||
1340 std::is_same_v<TAttestation, Attestations::AttestationCreateAccount>);
1342 if constexpr (std::is_same_v<TAttestation, Attestations::AttestationClaim>)
1344 return applyClaimAttestations(
1357 Attestations::AttestationCreateAccount>)
1359 return applyCreateAccountAttestations(
1390 auto const account = ctx.
tx[sfAccount];
1391 auto const reward = ctx.
tx[sfSignatureReward];
1392 auto const minAccountCreate = ctx.
tx[~sfMinAccountCreateAmount];
1393 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1395 if (bridgeSpec.lockingChainDoor() == bridgeSpec.issuingChainDoor())
1400 if (bridgeSpec.lockingChainDoor() != account &&
1401 bridgeSpec.issuingChainDoor() != account)
1406 if (
isXRP(bridgeSpec.lockingChainIssue()) !=
1407 isXRP(bridgeSpec.issuingChainIssue()))
1414 if (!
isXRP(reward) || reward.signum() < 0)
1419 if (minAccountCreate &&
1420 ((!
isXRP(*minAccountCreate) || minAccountCreate->signum() <= 0) ||
1421 !
isXRP(bridgeSpec.lockingChainIssue()) ||
1422 !
isXRP(bridgeSpec.issuingChainIssue())))
1427 if (
isXRP(bridgeSpec.issuingChainIssue()))
1436 if (bridgeSpec.issuingChainDoor() != rootAccount)
1445 if (bridgeSpec.issuingChainDoor() !=
1446 bridgeSpec.issuingChainIssue().account)
1452 if (bridgeSpec.lockingChainDoor() == bridgeSpec.lockingChainIssue().account)
1465 auto const account = ctx.
tx[sfAccount];
1466 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1482 if (!
isXRP(bridgeSpec.issue(chainType)))
1484 auto const sleIssuer =
1502 auto const balance = (*sleAcc)[sfBalance];
1503 auto const reserve =
1506 if (balance < reserve)
1516 auto const account =
ctx_.
tx[sfAccount];
1517 auto const bridgeSpec =
ctx_.
tx[sfXChainBridge];
1518 auto const reward =
ctx_.
tx[sfSignatureReward];
1519 auto const minAccountCreate =
ctx_.
tx[~sfMinAccountCreateAmount];
1529 auto const sleBridge = std::make_shared<SLE>(bridgeKeylet);
1531 (*sleBridge)[sfAccount] = account;
1532 (*sleBridge)[sfSignatureReward] = reward;
1533 if (minAccountCreate)
1534 (*sleBridge)[sfMinAccountCreateAmount] = *minAccountCreate;
1535 (*sleBridge)[sfXChainBridge] = bridgeSpec;
1536 (*sleBridge)[sfXChainClaimID] = 0;
1537 (*sleBridge)[sfXChainAccountCreateCount] = 0;
1538 (*sleBridge)[sfXChainAccountClaimCount] = 0;
1546 (*sleBridge)[sfOwnerNode] = *page;
1571 auto const account = ctx.
tx[sfAccount];
1572 auto const reward = ctx.
tx[~sfSignatureReward];
1573 auto const minAccountCreate = ctx.
tx[~sfMinAccountCreateAmount];
1574 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1575 bool const clearAccountCreate =
1578 if (!reward && !minAccountCreate && !clearAccountCreate)
1584 if (minAccountCreate && clearAccountCreate)
1590 if (bridgeSpec.lockingChainDoor() != account &&
1591 bridgeSpec.issuingChainDoor() != account)
1596 if (reward && (!
isXRP(*reward) || reward->signum() < 0))
1601 if (minAccountCreate &&
1602 ((!
isXRP(*minAccountCreate) || minAccountCreate->signum() <= 0) ||
1603 !
isXRP(bridgeSpec.lockingChainIssue()) ||
1604 !
isXRP(bridgeSpec.issuingChainIssue())))
1615 auto const account = ctx.
tx[sfAccount];
1616 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1632 auto const account =
ctx_.
tx[sfAccount];
1633 auto const bridgeSpec =
ctx_.
tx[sfXChainBridge];
1634 auto const reward =
ctx_.
tx[~sfSignatureReward];
1635 auto const minAccountCreate =
ctx_.
tx[~sfMinAccountCreateAmount];
1636 bool const clearAccountCreate =
1646 auto const sleBridge =
1652 (*sleBridge)[sfSignatureReward] = *reward;
1653 if (minAccountCreate)
1655 (*sleBridge)[sfMinAccountCreateAmount] = *minAccountCreate;
1657 if (clearAccountCreate &&
1658 sleBridge->isFieldPresent(sfMinAccountCreateAmount))
1660 sleBridge->makeFieldAbsent(sfMinAccountCreateAmount);
1682 auto const amount = ctx.
tx[sfAmount];
1684 if (amount.signum() <= 0 ||
1699 STAmount const& thisChainAmount = ctx.
tx[sfAmount];
1700 auto const claimID = ctx.
tx[sfXChainClaimID];
1702 auto const sleBridge = readBridge(ctx.
view, bridgeSpec);
1713 auto const thisDoor = (*sleBridge)[sfAccount];
1714 bool isLockingChain =
false;
1717 isLockingChain =
true;
1719 isLockingChain =
false;
1748 auto const otherChainAmount = [&]() ->
STAmount {
1757 auto const sleClaimID =
1767 if ((*sleClaimID)[sfAccount] != account)
1784 auto const dst =
ctx_.
tx[sfDestination];
1787 auto const claimID =
ctx_.
tx[sfXChainClaimID];
1806 auto const sleBridge = peekBridge(psb, bridgeSpec);
1807 auto const sleClaimID = psb.
peek(claimIDKeylet);
1809 if (!(sleBridge && sleClaimID && sleAcct))
1812 AccountID const thisDoor = (*sleBridge)[sfAccount];
1826 auto const sendingAmount = [&]() ->
STAmount {
1832 auto const [signersList, quorum, slTer] =
1839 sleClaimID->getFieldArray(sfXChainClaimAttestations)};
1841 auto const claimR = onClaim(
1850 if (!claimR.has_value())
1855 (*sleClaimID)[sfAccount],
1858 (*sleClaimID)[sfSignatureReward],
1862 if (!scopeResult.has_value())
1863 return scopeResult.error();
1865 auto const& [rewardAccounts, rewardPoolSrc, sendingAmount, srcChain, signatureReward] =
1866 scopeResult.value();
1869 auto const r = finalizeClaimHelper(
1881 OnTransferFail::keepClaim,
1882 DepositAuthPolicy::dstCanBypass,
1884 if (!r.isTesSuccess())
1897 auto const maxSpend = [&] {
1898 auto const amount = ctx.
tx[sfAmount];
1899 if (amount.native() && amount.signum() > 0)
1900 return amount.xrp();
1919 auto const amount = ctx.
tx[sfAmount];
1920 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1922 if (amount.signum() <= 0 || !
isLegalNet(amount))
1925 if (amount.issue() != bridgeSpec.lockingChainIssue() &&
1926 amount.issue() != bridgeSpec.issuingChainIssue())
1935 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
1936 auto const amount = ctx.
tx[sfAmount];
1938 auto const sleBridge = readBridge(ctx.
view, bridgeSpec);
1944 AccountID const thisDoor = (*sleBridge)[sfAccount];
1947 if (thisDoor == account)
1953 bool isLockingChain =
false;
1955 if (thisDoor == bridgeSpec.lockingChainDoor())
1956 isLockingChain =
true;
1957 else if (thisDoor == bridgeSpec.issuingChainDoor())
1958 isLockingChain =
false;
1965 if (bridgeSpec.lockingChainIssue() != ctx.
tx[sfAmount].issue())
1970 if (bridgeSpec.issuingChainIssue() != ctx.
tx[sfAmount].issue())
1982 auto const account =
ctx_.
tx[sfAccount];
1983 auto const amount =
ctx_.
tx[sfAmount];
1984 auto const bridgeSpec =
ctx_.
tx[sfXChainBridge];
1989 auto const sleBridge = readBridge(psb, bridgeSpec);
1993 auto const dst = (*sleBridge)[sfAccount];
1996 TransferHelperSubmittingAccountInfo submittingAccountInfo{
1999 auto const thTer = transferHelper(
2006 CanCreateDstPolicy::no,
2007 DepositAuthPolicy::normal,
2008 submittingAccountInfo,
2033 auto const reward = ctx.
tx[sfSignatureReward];
2044 auto const account = ctx.
tx[sfAccount];
2045 auto const bridgeSpec = ctx.
tx[sfXChainBridge];
2046 auto const sleBridge = readBridge(ctx.
view, bridgeSpec);
2054 auto const reward = ctx.
tx[sfSignatureReward];
2056 if (reward != (*sleBridge)[sfSignatureReward])
2067 auto const balance = (*sleAcc)[sfBalance];
2068 auto const reserve =
2071 if (balance < reserve)
2081 auto const account =
ctx_.
tx[sfAccount];
2082 auto const bridgeSpec =
ctx_.
tx[sfXChainBridge];
2083 auto const reward =
ctx_.
tx[sfSignatureReward];
2084 auto const otherChainSrc =
ctx_.
tx[sfOtherChainSource];
2090 auto const sleBridge = peekBridge(
ctx_.
view(), bridgeSpec);
2094 std::uint32_t const claimID = (*sleBridge)[sfXChainClaimID] + 1;
2098 (*sleBridge)[sfXChainClaimID] = claimID;
2104 auto const sleClaimID = std::make_shared<SLE>(claimIDKeylet);
2106 (*sleClaimID)[sfAccount] = account;
2107 (*sleClaimID)[sfXChainBridge] = bridgeSpec;
2108 (*sleClaimID)[sfXChainClaimID] = claimID;
2109 (*sleClaimID)[sfOtherChainSource] = otherChainSrc;
2110 (*sleClaimID)[sfSignatureReward] = reward;
2111 sleClaimID->setFieldArray(
2112 sfXChainClaimAttestations,
STArray{sfXChainClaimAttestations});
2122 (*sleClaimID)[sfOwnerNode] = *page;
2139 return attestationPreflight<Attestations::AttestationClaim>(ctx);
2145 return attestationPreclaim<Attestations::AttestationClaim>(ctx);
2151 return attestationDoApply<Attestations::AttestationClaim>(
ctx_);
2159 return attestationPreflight<Attestations::AttestationCreateAccount>(ctx);
2165 return attestationPreclaim<Attestations::AttestationCreateAccount>(ctx);
2171 return attestationDoApply<Attestations::AttestationCreateAccount>(
ctx_);
2188 auto const amount = ctx.
tx[sfAmount];
2190 if (amount.signum() <= 0 || !amount.native())
2193 auto const reward = ctx.
tx[sfSignatureReward];
2194 if (reward.signum() < 0 || !reward.native())
2197 if (reward.issue() != amount.issue())
2208 STAmount const reward = ctx.
tx[sfSignatureReward];
2210 auto const sleBridge = readBridge(ctx.
view, bridgeSpec);
2216 if (reward != (*sleBridge)[sfSignatureReward])
2222 (*sleBridge)[~sfMinAccountCreateAmount];
2224 if (!minCreateAmount)
2227 if (amount < *minCreateAmount)
2230 if (minCreateAmount->issue() != amount.
issue())
2233 AccountID const thisDoor = (*sleBridge)[sfAccount];
2235 if (thisDoor == account)
2253 if (bridgeSpec.
issue(srcChain) != ctx.
tx[sfAmount].issue())
2276 auto const sleBridge = peekBridge(psb, bridge);
2280 auto const dst = (*sleBridge)[sfAccount];
2283 TransferHelperSubmittingAccountInfo submittingAccountInfo{
2285 STAmount const toTransfer = amount + reward;
2286 auto const thTer = transferHelper(
2293 CanCreateDstPolicy::yes,
2294 DepositAuthPolicy::normal,
2295 submittingAccountInfo,
2301 (*sleBridge)[sfXChainAccountCreateCount] =
2302 (*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)
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
constexpr std::uint32_t tfUniversalMask
Unexpected(E(&)[N]) -> Unexpected< E const * >
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
TERSubset< CanCvtToTER > TER
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.