diff --git a/src/ripple/app/tx/impl/InvariantCheck.cpp b/src/ripple/app/tx/impl/InvariantCheck.cpp index 8e38f80c2..3cdf14bc6 100644 --- a/src/ripple/app/tx/impl/InvariantCheck.cpp +++ b/src/ripple/app/tx/impl/InvariantCheck.cpp @@ -597,7 +597,8 @@ ValidNewAccountRoot::finalize( return false; } - if ((tt == ttPAYMENT || tt == ttIMPORT || tt == ttGENESIS_MINT || tt == ttREMIT) && + if ((tt == ttPAYMENT || tt == ttIMPORT || tt == ttGENESIS_MINT || + tt == ttREMIT) && result == tesSUCCESS) { std::uint32_t const startingSeq{ diff --git a/src/ripple/app/tx/impl/Remit.cpp b/src/ripple/app/tx/impl/Remit.cpp index 84c0feace..fb1e8d9d3 100644 --- a/src/ripple/app/tx/impl/Remit.cpp +++ b/src/ripple/app/tx/impl/Remit.cpp @@ -18,11 +18,11 @@ //============================================================================== #include +#include #include #include #include #include -#include namespace ripple { TxConsequences @@ -43,7 +43,7 @@ Remit::preflight(PreflightContext const& ctx) JLOG(ctx.j.warn()) << "Malformed transaction: Invalid flags set."; return temINVALID_FLAG; } - + AccountID const dstID = ctx.tx.getAccountID(sfDestination); AccountID const srcID = ctx.tx.getAccountID(sfAccount); @@ -65,8 +65,7 @@ Remit::preflight(PreflightContext const& ctx) // Validate the AmountEntry. if (sEntry.getFName() != sfAmountEntry) { - JLOG(ctx.j.warn()) - << "Malformed: Expected AmountEntry."; + JLOG(ctx.j.warn()) << "Malformed: Expected AmountEntry."; return temMALFORMED; } @@ -88,7 +87,8 @@ Remit::preflight(PreflightContext const& ctx) { if (nativeAlready) { - JLOG(ctx.j.warn()) << "Malformed transaction: Native Currency appears more than once."; + JLOG(ctx.j.warn()) << "Malformed transaction: Native " + "Currency appears more than once."; return temMALFORMED; } @@ -99,13 +99,16 @@ Remit::preflight(PreflightContext const& ctx) auto found = already.find(amount.getCurrency()); if (found == already.end()) { - already.emplace(amount.getCurrency(), std::set{amount.getIssuer()}); + already.emplace( + amount.getCurrency(), + std::set{amount.getIssuer()}); continue; } if (found->second.find(amount.getIssuer()) != found->second.end()) { - JLOG(ctx.j.warn()) << "Malformed transaction: Issued Currency appears more than once."; + JLOG(ctx.j.warn()) << "Malformed transaction: Issued Currency " + "appears more than once."; return temMALFORMED; } @@ -117,8 +120,8 @@ Remit::preflight(PreflightContext const& ctx) if (ctx.tx.isFieldPresent(sfMintURIToken)) { STObject const& mint = const_cast(ctx.tx) - .getField(sfMintURIToken) - .downcast(); + .getField(sfMintURIToken) + .downcast(); // RH TODO: iterate mint fields detect any that shouldnt be there Blob const uri = mint.getFieldVL(sfURI); @@ -175,12 +178,12 @@ Remit::doApply() if (!sleSrcAcc) return terNO_ACCOUNT; - XRPAmount const accountReserve { sb.fees().accountReserve(0) }; - XRPAmount const objectReserve { sb.fees().accountReserve(1) - accountReserve }; - - // amount of native tokens we will transfer to cover reserves for the tls/acc/uritokens created, and - // native tokens listed in amounts - XRPAmount nativeRemit { 0 }; + XRPAmount const accountReserve{sb.fees().accountReserve(0)}; + XRPAmount const objectReserve{sb.fees().accountReserve(1) - accountReserve}; + + // amount of native tokens we will transfer to cover reserves for the + // tls/acc/uritokens created, and native tokens listed in amounts + XRPAmount nativeRemit{0}; AccountID const dstAccID{ctx_.tx[sfDestination]}; auto sleDstAcc = sb.peek(keylet::account(dstAccID)); @@ -189,30 +192,29 @@ Remit::doApply() // Check if the destination has disallowed incoming if (sb.rules().enabled(featureDisallowIncoming) && (flags & lsfDisallowIncomingRemit)) - return tecNO_PERMISSION; - + return tecNO_PERMISSION; + // the destination may require a dest tag - if ((flags & lsfRequireDestTag) && !ctx_.tx.isFieldPresent(sfDestinationTag)) + if ((flags & lsfRequireDestTag) && + !ctx_.tx.isFieldPresent(sfDestinationTag)) { - JLOG(j.warn()) << "Remit: DestinationTag required for this destination."; + JLOG(j.warn()) + << "Remit: DestinationTag required for this destination."; return tecDST_TAG_NEEDED; } - // if the destination doesn't exist, create it. bool const createDst = !sleDstAcc; if (createDst) { // sender will pay the reserve nativeRemit += accountReserve; - + // Create the account. std::uint32_t const seqno{ sb.rules().enabled(featureXahauGenesis) ? sb.info().parentCloseTime.time_since_epoch().count() - : sb.rules().enabled(featureDeletableAccounts) - ? sb.seq() - : 1}; + : sb.rules().enabled(featureDeletableAccounts) ? sb.seq() : 1}; sleDstAcc = std::make_shared(keylet::account(dstAccID)); sleDstAcc->setAccountID(sfAccount, dstAccID); @@ -235,15 +237,14 @@ Remit::doApply() sb.insert(sleDstAcc); } - // if theres a minted uritoken the sender pays for that if (ctx_.tx.isFieldPresent(sfMintURIToken)) { nativeRemit += objectReserve; STObject const& mint = const_cast(ctx_.tx) - .getField(sfMintURIToken) - .downcast(); - + .getField(sfMintURIToken) + .downcast(); + Blob const& mintURI = mint.getFieldVL(sfURI); std::optional mintDigest; @@ -251,17 +252,15 @@ Remit::doApply() mintDigest = mint.getFieldH256(sfDigest); Keylet kl = keylet::uritoken(srcAccID, mintURI); - + // check that it doesn't already exist if (sb.exists(kl)) { - JLOG(j.trace()) - << "Remit: tried to creat duplicate URIToken. Tx: " - << ctx_.tx.getTransactionID(); + JLOG(j.trace()) << "Remit: tried to creat duplicate URIToken. Tx: " + << ctx_.tx.getTransactionID(); return tecDUPLICATE; } - auto sleMint = std::make_shared(kl); sleMint->setAccountID(sfOwner, dstAccID); @@ -272,15 +271,16 @@ Remit::doApply() if (mint.isFieldPresent(sfDigest)) sleMint->setFieldH256(sfDigest, mint.getFieldH256(sfDigest)); - sleMint->setFieldU32(sfFlags, mint.isFieldPresent(sfFlags) ? mint.getFieldU32(sfFlags) : 0); - + sleMint->setFieldU32( + sfFlags, + mint.isFieldPresent(sfFlags) ? mint.getFieldU32(sfFlags) : 0); auto const page = view().dirInsert( keylet::ownerDir(dstAccID), kl, describeOwnerDir(dstAccID)); - JLOG(j_.trace()) - << "Adding URIToken to owner directory " << to_string(kl.key) - << ": " << (page ? "success" : "failure"); + JLOG(j_.trace()) << "Adding URIToken to owner directory " + << to_string(kl.key) << ": " + << (page ? "success" : "failure"); if (!page) return tecDIR_FULL; @@ -289,12 +289,12 @@ Remit::doApply() sb.insert(sleMint); // ensure there is a deletion blocker against the issuer now - sleSrcAcc->setFieldU32(sfFlags, sleSrcAcc->getFlags() | lsfURITokenIssuer); + sleSrcAcc->setFieldU32( + sfFlags, sleSrcAcc->getFlags() | lsfURITokenIssuer); - adjustOwnerCount(sb, sleSrcAcc, 1, j); + adjustOwnerCount(sb, sleDstAcc, 1, j); } - // iterate uritokens if (ctx_.tx.isFieldPresent(sfURITokenIDs)) { @@ -303,28 +303,28 @@ Remit::doApply() { Keylet kl = keylet::unchecked(klRaw); auto sleU = sb.peek(kl); - + // does it exist if (!sleU) { - JLOG(j.warn()) - << "Remit: one or more uritokens did not exist on the source account."; + JLOG(j.warn()) << "Remit: one or more uritokens did not exist " + "on the source account."; return tecUNFUNDED_PAYMENT; } // is it a uritoken? if (sleU->getFieldU16(sfLedgerEntryType) != ltURI_TOKEN) { - JLOG(j.warn()) - << "Remit: one or more supplied URITokenIDs was not actually a uritoken."; + JLOG(j.warn()) << "Remit: one or more supplied URITokenIDs was " + "not actually a uritoken."; return tecNO_ENTRY; } // is it our uritoken? if (sleU->getAccountID(sfOwner) != srcAccID) { - JLOG(j.warn()) - << "Remit: one or more supplied URITokenIDs was not owned by sender."; + JLOG(j.warn()) << "Remit: one or more supplied URITokenIDs was " + "not owned by sender."; return tecNO_PERMISSION; } @@ -340,24 +340,25 @@ Remit::doApply() // remove from sender dir { auto const page = (*sleU)[sfOwnerNode]; - if (!sb.dirRemove(keylet::ownerDir(srcAccID), page, kl.key, true)) + if (!sb.dirRemove( + keylet::ownerDir(srcAccID), page, kl.key, true)) { JLOG(j.fatal()) << "Could not remove URIToken from owner directory"; return tefBAD_LEDGER; } - + adjustOwnerCount(sb, sleSrcAcc, -1, j); } // add to dest dir { - auto const page = - sb.dirInsert(keylet::ownerDir(dstAccID), kl, describeOwnerDir(dstAccID)); + auto const page = sb.dirInsert( + keylet::ownerDir(dstAccID), kl, describeOwnerDir(dstAccID)); - JLOG(j_.trace()) - << "Adding URIToken to owner directory " << to_string(kl.key) - << ": " << (page ? "success" : "failure"); + JLOG(j_.trace()) << "Adding URIToken to owner directory " + << to_string(kl.key) << ": " + << (page ? "success" : "failure"); if (!page) return tecDIR_FULL; @@ -366,7 +367,7 @@ Remit::doApply() adjustOwnerCount(sb, sleDstAcc, 1, j); } - + // change the owner sleU->setAccountID(sfOwner, dstAccID); @@ -374,11 +375,9 @@ Remit::doApply() } } - // iterate trustlines if (ctx_.tx.isFieldPresent(sfAmounts)) { - // process trustline remits STArray const& sEntries(ctx_.tx.getFieldArray(sfAmounts)); for (STObject const& sEntry : sEntries) @@ -386,68 +385,70 @@ Remit::doApply() STAmount const amount = sEntry.getFieldAmount(sfAmount); if (isXRP(amount)) { - // since we have to pay for all the created objects including possibly the account itself - // this is paid right at the end, and only if there is balance enough to cover. + // since we have to pay for all the created objects including + // possibly the account itself this is paid right at the end, + // and only if there is balance enough to cover. nativeRemit += amount.xrp(); continue; } - + AccountID const issuerAccID = amount.getIssuer(); // check permissions if (issuerAccID == srcAccID || issuerAccID == dstAccID) { - // no permission check needed when the issuer sends out or a subscriber sends back - // RH TODO: move this condition into trustTransferAllowed, guarded by an amendment + // no permission check needed when the issuer sends out or a + // subscriber sends back RH TODO: move this condition into + // trustTransferAllowed, guarded by an amendment } - else - if (TER canXfer = - trustTransferAllowed( - sb, - std::vector{srcAccID, dstAccID}, - amount.issue(), - j); canXfer != tesSUCCESS) + else if (TER canXfer = trustTransferAllowed( + sb, + std::vector{srcAccID, dstAccID}, + amount.issue(), + j); + canXfer != tesSUCCESS) return canXfer; - // compute the amount the source will need to send // in remit the sender pays all transfer fees, so that - // the destination can always be assured they got the exact amount specified. - // therefore we need to compute the amount + transfer fee - auto const srcAmt = + // the destination can always be assured they got the exact amount + // specified. therefore we need to compute the amount + transfer fee + auto const srcAmt = issuerAccID != srcAccID && issuerAccID != dstAccID - ? multiply(amount, transferRate(sb, issuerAccID)) - : amount; + ? multiply(amount, transferRate(sb, issuerAccID)) + : amount; auto const dstAmt = amount; - STAmount availableFunds{accountFunds( - sb, srcAccID, srcAmt, fhZERO_IF_FROZEN, j)}; + STAmount availableFunds{ + accountFunds(sb, srcAccID, srcAmt, fhZERO_IF_FROZEN, j)}; if (availableFunds < srcAmt) return tecUNFUNDED_PAYMENT; - // if the target trustline doesn't exist we need to create it and pay its reserve + // if the target trustline doesn't exist we need to create it and + // pay its reserve if (!sb.exists(keylet::line( - issuerAccID == dstAccID - ? srcAccID - : dstAccID, issuerAccID, amount.getCurrency()))) + issuerAccID == dstAccID ? srcAccID : dstAccID, + issuerAccID, + amount.getCurrency()))) nativeRemit += objectReserve; // action the transfer STAmount sentAmt; if (TER result = - rippleSend(sb, srcAccID, dstAccID, dstAmt, sentAmt, j); result != tesSUCCESS) + rippleSend(sb, srcAccID, dstAccID, dstAmt, sentAmt, j); + result != tesSUCCESS) return result; if (sentAmt != srcAmt) return tecINTERNAL; } } - + if (nativeRemit < beast::zero) return tecINTERNAL; - + if (nativeRemit > beast::zero) { // ensure the account can cover the native remit @@ -475,7 +476,7 @@ Remit::doApply() } // apply - sb.update(sleSrcAcc); + sb.update(sleSrcAcc); sb.apply(ctx_.rawView()); return tesSUCCESS; diff --git a/src/ripple/app/tx/impl/URIToken.h b/src/ripple/app/tx/impl/URIToken.h index 159f7fb95..ebea4c187 100644 --- a/src/ripple/app/tx/impl/URIToken.h +++ b/src/ripple/app/tx/impl/URIToken.h @@ -30,11 +30,7 @@ namespace ripple { class URIToken : public Transactor { public: - - bool - inline - static - validateUTF8(std::vector const& u) + bool inline static validateUTF8(std::vector const& u) { // this code is from // https://www.cl.cam.ac.uk/~mgk25/ucs/utf8_check.c @@ -58,10 +54,8 @@ public: { /* 1110XXXX 10Xxxxxx 10xxxxxx */ if ((s[1] & 0xc0) != 0x80 || (s[2] & 0xc0) != 0x80 || - (s[0] == 0xe0 && - (s[1] & 0xe0) == 0x80) || /* overlong? */ - (s[0] == 0xed && - (s[1] & 0xe0) == 0xa0) || /* surrogate? */ + (s[0] == 0xe0 && (s[1] & 0xe0) == 0x80) || /* overlong? */ + (s[0] == 0xed && (s[1] & 0xe0) == 0xa0) || /* surrogate? */ (s[0] == 0xef && s[1] == 0xbf && (s[2] & 0xfe) == 0xbe)) /* U+FFFE or U+FFFF? */ return false; @@ -73,8 +67,7 @@ public: /* 11110XXX 10XXxxxx 10xxxxxx 10xxxxxx */ if ((s[1] & 0xc0) != 0x80 || (s[2] & 0xc0) != 0x80 || (s[3] & 0xc0) != 0x80 || - (s[0] == 0xf0 && - (s[1] & 0xf0) == 0x80) || /* overlong? */ + (s[0] == 0xf0 && (s[1] & 0xf0) == 0x80) || /* overlong? */ (s[0] == 0xf4 && s[1] > 0x8f) || s[0] > 0xf4) /* > U+10FFFF? */ return false; diff --git a/src/ripple/ledger/View.h b/src/ripple/ledger/View.h index dced77af9..96abe4ce2 100644 --- a/src/ripple/ledger/View.h +++ b/src/ripple/ledger/View.h @@ -640,8 +640,7 @@ trustTransferAllowed( { static_assert( std::is_same::value || - std::is_same::value || - std::is_same::value); + std::is_same::value || std::is_same::value); typedef typename std::conditional< std::is_same::value, diff --git a/src/ripple/protocol/impl/InnerObjectFormats.cpp b/src/ripple/protocol/impl/InnerObjectFormats.cpp index d788e06fa..c6d0340c1 100644 --- a/src/ripple/protocol/impl/InnerObjectFormats.cpp +++ b/src/ripple/protocol/impl/InnerObjectFormats.cpp @@ -141,7 +141,7 @@ InnerObjectFormats::InnerObjectFormats() {sfPublicKey, soeREQUIRED}, {sfAccount, soeOPTIONAL}, }); - + add(sfAmountEntry.jsonName.c_str(), sfAmountEntry.getCode(), { @@ -156,7 +156,6 @@ InnerObjectFormats::InnerObjectFormats() {sfDigest, soeOPTIONAL}, {sfFlags, soeOPTIONAL}, }); - } InnerObjectFormats const& diff --git a/src/test/consensus/NegativeUNL_test.cpp b/src/test/consensus/NegativeUNL_test.cpp index 0648cf95d..7e18e28b8 100644 --- a/src/test/consensus/NegativeUNL_test.cpp +++ b/src/test/consensus/NegativeUNL_test.cpp @@ -52,9 +52,7 @@ namespace test { * @param hasToReEnable if expect ToDisable in ledger * @return true if meet all three expectation */ -bool -inline -negUnlSizeTest( +bool inline negUnlSizeTest( std::shared_ptr const& l, size_t size, bool hasToDisable, @@ -77,9 +75,11 @@ negUnlSizeTest( * @param pass if the Tx should be applied successfully * @return true if meet the expectation of apply result */ -bool -inline -applyAndTestResult(jtx::Env& env, ripple::OpenView& view, ripple::STTx const& tx, bool pass) +bool inline applyAndTestResult( + jtx::Env& env, + ripple::OpenView& view, + ripple::STTx const& tx, + bool pass) { auto res = apply(env.app(), view, tx, ApplyFlags::tapNONE, env.journal); if (pass) @@ -1930,7 +1930,6 @@ BEAST_DEFINE_TESTSUITE(NegativeUNLVoteFilterValidations, consensus, ripple); /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// - bool VerifyPubKeyAndSeq( std::shared_ptr const& l, diff --git a/src/test/jtx/utility.h b/src/test/jtx/utility.h index cfcdf676f..cb013a684 100644 --- a/src/test/jtx/utility.h +++ b/src/test/jtx/utility.h @@ -65,5 +65,4 @@ fill_seq(Json::Value& jv, ReadView const& view); } // namespace test } // namespace ripple - #endif