xrpld
Loading...
Searching...
No Matches
TransactionSign.cpp
1#include <xrpld/rpc/detail/TransactionSign.h>
2
3#include <xrpld/app/ledger/OpenLedger.h>
4#include <xrpld/app/main/Application.h>
5#include <xrpld/app/misc/DeliverMax.h>
6#include <xrpld/app/misc/Transaction.h>
7#include <xrpld/app/misc/TxQ.h>
8#include <xrpld/rpc/Role.h>
9#include <xrpld/rpc/detail/AssetCache.h>
10#include <xrpld/rpc/detail/LegacyPathFind.h>
11#include <xrpld/rpc/detail/Pathfinder.h>
12#include <xrpld/rpc/detail/RPCHelpers.h>
13#include <xrpld/rpc/detail/Tuning.h>
14
15#include <xrpl/basics/Blob.h>
16#include <xrpl/basics/Buffer.h>
17#include <xrpl/basics/Log.h>
18#include <xrpl/basics/Number.h>
19#include <xrpl/basics/Slice.h>
20#include <xrpl/basics/base_uint.h>
21#include <xrpl/basics/contract.h>
22#include <xrpl/basics/strHex.h>
23#include <xrpl/beast/utility/instrumentation.h>
24#include <xrpl/core/NetworkIDService.h>
25#include <xrpl/json/json_writer.h>
26#include <xrpl/protocol/AccountID.h>
27#include <xrpl/protocol/ApiVersion.h>
28#include <xrpl/protocol/ErrorCodes.h>
29#include <xrpl/protocol/Feature.h>
30#include <xrpl/protocol/Indexes.h>
31#include <xrpl/protocol/InnerObjectFormats.h>
32#include <xrpl/protocol/Issue.h>
33#include <xrpl/protocol/LedgerFormats.h>
34#include <xrpl/protocol/MPTIssue.h>
35#include <xrpl/protocol/PublicKey.h>
36#include <xrpl/protocol/RPCErr.h>
37#include <xrpl/protocol/SField.h>
38#include <xrpl/protocol/STAmount.h>
39#include <xrpl/protocol/STArray.h>
40#include <xrpl/protocol/STObject.h>
41#include <xrpl/protocol/STParsedJSON.h>
42#include <xrpl/protocol/STPathSet.h>
43#include <xrpl/protocol/STTx.h>
44#include <xrpl/protocol/SecretKey.h>
45#include <xrpl/protocol/Serializer.h>
46#include <xrpl/protocol/Sign.h>
47#include <xrpl/protocol/TER.h>
48#include <xrpl/protocol/Units.h>
49#include <xrpl/protocol/XRPAmount.h>
50#include <xrpl/protocol/jss.h>
51#include <xrpl/server/LoadFeeTrack.h>
52#include <xrpl/tx/apply.h> // Validity::Valid
53#include <xrpl/tx/applySteps.h>
54
55#include <algorithm>
56#include <chrono>
57#include <cstdint>
58#include <exception>
59#include <expected>
60#include <functional>
61#include <memory>
62#include <optional>
63#include <sstream>
64#include <stdexcept>
65#include <utility>
66
67namespace xrpl::RPC {
68namespace detail {
69
70// Used to pass extra parameters used when returning a
71// a SigningFor object.
73{
74private:
79
80public:
82 {
83 }
84
85 SigningForParams(SigningForParams const& rhs) = delete;
86
87 SigningForParams(AccountID const& multiSigningAcctID) : multiSigningAcctID_(&multiSigningAcctID)
88 {
89 }
90
91 [[nodiscard]] bool
93 {
94 return multiSigningAcctID_ != nullptr;
95 }
96
97 [[nodiscard]] bool
99 {
100 return !isMultiSigning();
101 }
102
103 // When multi-signing we should not edit the tx_json fields.
104 [[nodiscard]] bool
106 {
107 return !isMultiSigning();
108 }
109
110 [[nodiscard]] bool
112 {
113 return isMultiSigning() && multiSignPublicKey_ && !multiSignature_.empty();
114 }
115
116 // Don't call this method unless isMultiSigning() returns true.
117 [[nodiscard]] AccountID const&
118 getSigner() const
119 {
120 if (multiSigningAcctID_ == nullptr)
121 logicError("Accessing unknown SigningForParams::getSigner()");
122 return *multiSigningAcctID_;
123 }
124
125 [[nodiscard]] PublicKey const&
127 {
129 logicError("Accessing unknown SigningForParams::getPublicKey()");
130 return *multiSignPublicKey_;
131 }
132
133 [[nodiscard]] Buffer const&
135 {
136 return multiSignature_;
137 }
138
141 {
142 return signatureTarget_;
143 }
144
145 void
146 setPublicKey(PublicKey const& multiSignPublicKey)
147 {
148 multiSignPublicKey_ = multiSignPublicKey;
149 }
150
151 void
156
157 void
158 moveMultiSignature(Buffer&& multiSignature)
159 {
160 multiSignature_ = std::move(multiSignature);
161 }
162};
163
164//------------------------------------------------------------------------------
165
166static ErrorCodeI
168 SLE::const_pointer accountState,
169 AccountID const& accountID,
170 PublicKey const& publicKey)
171{
172 auto const publicKeyAcctID = calcAccountID(publicKey);
173 bool const isMasterKey = publicKeyAcctID == accountID;
174
175 // If we can't get the accountRoot, but the accountIDs match, that's
176 // good enough.
177 if (!accountState)
178 {
179 if (isMasterKey)
180 return RpcSuccess;
181 return RpcBadSecret;
182 }
183
184 // If we *can* get to the accountRoot, check for MASTER_DISABLED.
185 auto const& sle = *accountState;
186 if (isMasterKey)
187 {
188 if (sle.isFlag(lsfDisableMaster))
189 return RpcMasterDisabled;
190 return RpcSuccess;
191 }
192
193 // The last gasp is that we have public Regular key.
194 if ((sle.isFieldPresent(sfRegularKey)) && (publicKeyAcctID == sle.getAccountID(sfRegularKey)))
195 {
196 return RpcSuccess;
197 }
198 return RpcBadSecret;
199}
200
201static json::Value
203 json::Value const& params,
204 json::Value& txJson,
205 AccountID const& srcAddressID,
206 Role const role,
207 Application& app,
208 bool doPath)
209{
210 // Only path find for Payments.
211 if (txJson[jss::TransactionType].asString() != jss::Payment)
212 return json::Value();
213
214 // DeliverMax is an alias to Amount and we use Amount internally
215 if (txJson.isMember(jss::DeliverMax))
216 {
217 if (txJson.isMember(jss::Amount))
218 {
219 if (txJson[jss::DeliverMax] != txJson[jss::Amount])
220 {
221 return RPC::makeError(
222 RpcInvalidParams, "Cannot specify differing 'Amount' and 'DeliverMax'");
223 }
224 }
225 else
226 {
227 txJson[jss::Amount] = txJson[jss::DeliverMax];
228 }
229
230 txJson.removeMember(jss::DeliverMax);
231 }
232
233 if (!txJson.isMember(jss::Amount))
234 return RPC::missingFieldError("tx_json.Amount");
235
236 STAmount amount;
237
238 if (!amountFromJsonNoThrow(amount, txJson[jss::Amount]))
239 return RPC::invalidFieldError("tx_json.Amount");
240
241 if (!txJson.isMember(jss::Destination))
242 return RPC::missingFieldError("tx_json.Destination");
243
244 auto const dstAccountID = parseBase58<AccountID>(txJson[jss::Destination].asString());
245 if (!dstAccountID)
246 return RPC::invalidFieldError("tx_json.Destination");
247
248 if (params.isMember(jss::build_path) &&
249 (!doPath ||
250 (!app.getOpenLedger().current()->rules().enabled(featureMPTokensV2) &&
251 amount.holds<MPTIssue>())))
252 {
253 return RPC::makeError(RpcInvalidParams, "Field 'build_path' not allowed in this context.");
254 }
255
256 if (txJson.isMember(jss::Paths) && params.isMember(jss::build_path))
257 {
258 return RPC::makeError(
259 RpcInvalidParams, "Cannot specify both 'tx_json.Paths' and 'build_path'");
260 }
261
263 if (txJson.isMember(sfDomainID.jsonName))
264 {
265 uint256 num;
266 if (!txJson[sfDomainID.jsonName].isString() ||
267 !num.parseHex(txJson[sfDomainID.jsonName].asString()))
268 {
269 return RPC::makeError(RpcDomainMalformed, "Unable to parse 'DomainID'.");
270 }
271
272 domain = num;
273 }
274
275 if (!txJson.isMember(jss::Paths) && params.isMember(jss::build_path))
276 {
277 STAmount sendMax;
278
279 if (txJson.isMember(jss::SendMax))
280 {
281 if (!amountFromJsonNoThrow(sendMax, txJson[jss::SendMax]))
282 return RPC::invalidFieldError("tx_json.SendMax");
283 }
284 else
285 {
286 // If no SendMax, default to Amount with sender as issuer if Issue.
287 sendMax = amount;
288 sendMax.asset().visit(
289 [&](Issue const&) { sendMax.get<Issue>().account = srcAddressID; },
290 [](MPTIssue const&) {});
291 }
292
293 if (sendMax.native() && amount.native())
294 return RPC::makeError(RpcInvalidParams, "Cannot build XRP to XRP paths.");
295
296 {
297 LegacyPathFind const lpf(isUnlimited(role), app);
298 if (!lpf.isOk())
299 return rpcError(RpcTooBusy);
300
301 STPathSet result;
302
303 if (auto ledger = app.getOpenLedger().current())
304 {
305 Pathfinder pf(
306 std::make_shared<AssetCache>(ledger, app.getJournal("AssetCache")),
307 srcAddressID,
308 *dstAccountID,
309 sendMax.asset(),
310 sendMax.getIssuer(),
311 amount,
312 std::nullopt,
313 domain,
314 app);
315 if (pf.findPaths(app.config().pathSearchOld))
316 {
317 // 4 is the maximum paths
318 pf.computePathRanks(4);
319 STPath fullLiquidityPath;
320 STPathSet const paths;
321 result = pf.getBestPaths(4, fullLiquidityPath, paths, sendMax.getIssuer());
322 }
323 }
324
325 auto j = app.getJournal("RPCHandler");
326 JLOG(j.debug()) << "transactionSign: build_path: "
328
329 if (!result.empty())
330 txJson[jss::Paths] = result.getJson(JsonOptions::Values::None);
331 }
332 }
333 return json::Value();
334}
335
336//------------------------------------------------------------------------------
337
338// Validate (but don't modify) the contents of the tx_json.
339//
340// Returns a pair<json::Value, AccountID>. The json::Value will contain error
341// information if there was an error. On success, the account ID is returned
342// and the json::Value will be empty.
343//
344// This code does not check the "Sequence" field, since the expectations
345// for that field are particularly context sensitive.
348 json::Value const& txJson,
349 Role const role,
350 bool const verify,
351 std::chrono::seconds validatedLedgerAge,
352 Config const& config,
353 LoadFeeTrack const& feeTrack,
354 unsigned apiVersion)
355{
357
358 if (!txJson.isObject())
359 {
360 ret.first = RPC::objectFieldError(jss::tx_json);
361 return ret;
362 }
363
364 if (!txJson.isMember(jss::TransactionType))
365 {
366 ret.first = RPC::missingFieldError("tx_json.TransactionType");
367 return ret;
368 }
369
370 if (!txJson.isMember(jss::Account))
371 {
373 return ret;
374 }
375
376 auto const srcAddressID = parseBase58<AccountID>(txJson[jss::Account].asString());
377
378 if (!srcAddressID)
379 {
381 return ret;
382 }
383
384 // Check for current ledger.
385 if (verify && !config.standalone() && (validatedLedgerAge > Tuning::kMaxValidatedLedgerAge))
386 {
387 if (apiVersion == 1)
388 {
390 }
391 else
392 {
394 }
395 return ret;
396 }
397
398 // Check for load.
399 if (feeTrack.isLoadedCluster() && !isUnlimited(role))
400 {
402 return ret;
403 }
404
405 // It's all good. Return the AccountID.
406 ret.second = *srcAddressID;
407 return ret;
408}
409
410static std::expected<void, json::Value>
411checkNetworkID(json::Value const& txJson, uint32_t appNetworkId)
412{
413 if (appNetworkId > 1024)
414 {
415 if (!txJson.isMember(jss::NetworkID))
416 {
417 return std::unexpected(
419 }
420 if (!txJson[jss::NetworkID].isIntegral() || txJson[jss::NetworkID].asUInt() != appNetworkId)
421 {
422 return std::unexpected(
424 }
425 }
426 return std::expected<void, json::Value>();
427}
428
429//------------------------------------------------------------------------------
430
431// A move-only struct that makes it easy to return either a json::Value or a
432// std::shared_ptr<STTx const> from transactionPreProcessImpl ().
456
457static TransactionPreProcessResult
459 json::Value& params,
460 Role role,
461 SigningForParams& signingArgs,
462 std::chrono::seconds validatedLedgerAge,
463 Application& app)
464{
465 auto j = app.getJournal("RPCHandler");
466
467 json::Value jvResult;
469 if (!keyPair || containsError(jvResult))
470 return jvResult;
471
472 PublicKey const& pk = keyPair->first;
473 SecretKey const& sk = keyPair->second;
474
475 bool const verify = !(params.isMember(jss::offline) && params[jss::offline].asBool());
476
477 auto const signatureTarget =
479 if (params.isMember(jss::signature_target))
480 return SField::getField(params[jss::signature_target].asString());
481 return std::nullopt;
482 }();
483
484 // Make sure the signature target field is valid, if specified, and save the
485 // template for use later
486 auto const signatureTemplate = signatureTarget
488 : nullptr;
489 if (signatureTarget)
490 {
491 if (signatureTemplate == nullptr)
492 { // Invalid target field
493 return RPC::makeError(RpcInvalidParams, signatureTarget->get().getName());
494 }
495 signingArgs.setSignatureTarget(signatureTarget);
496 }
497
498 if (!params.isMember(jss::tx_json))
499 return RPC::missingFieldError(jss::tx_json);
500
501 json::Value& txJson(params[jss::tx_json]);
502
503 // Check tx_json fields, but don't add any.
504 auto [txJsonResult, srcAddressID] = checkTxJsonFields(
505 txJson,
506 role,
507 verify,
508 validatedLedgerAge,
509 app.config(),
510 app.getFeeTrack(),
511 getAPIVersionNumber(params, app.config().betaRpcApi));
512
513 if (RPC::containsError(txJsonResult))
514 return std::move(txJsonResult);
515
516 // This test covers the case where we're offline so the sequence number
517 // cannot be determined locally. If we're offline then the caller must
518 // provide the sequence number.
519 if (!verify && !txJson.isMember(jss::Sequence))
520 return RPC::missingFieldError("tx_json.Sequence");
521
523 if (verify)
524 sle = app.getOpenLedger().current()->read(keylet::account(srcAddressID));
525
526 if (verify && !sle)
527 {
528 // If not offline and did not find account, error.
529 JLOG(j.debug()) << "transactionSign: Failed to find source account "
530 << "in current ledger: " << toBase58(srcAddressID);
531
533 }
534
535 if (signingArgs.editFields())
536 {
537 if (!txJson.isMember(jss::Sequence))
538 {
539 bool const hasTicketSeq = txJson.isMember(sfTicketSequence.jsonName);
540 if (!hasTicketSeq && !sle)
541 {
542 JLOG(j.debug()) << "transactionSign: Failed to find source account "
543 << "in current ledger: " << toBase58(srcAddressID);
544
546 }
547 txJson[jss::Sequence] = hasTicketSeq ? 0 : app.getTxQ().nextQueuableSeq(sle).value();
548 }
549
550 if (!txJson.isMember(jss::NetworkID))
551 {
552 auto const networkId = app.getNetworkIDService().getNetworkID();
553 if (networkId > 1024)
554 txJson[jss::NetworkID] = to_string(networkId);
555 }
556 }
557
558 {
559 json::Value err = checkFee(
560 params,
561 role,
562 verify && signingArgs.editFields(),
563 app.config(),
564 app.getFeeTrack(),
565 app.getTxQ(),
566 app);
567
568 if (RPC::containsError(err))
569 return err;
570 }
571
572 {
574 params, txJson, srcAddressID, role, app, verify && signingArgs.editFields());
575
576 if (RPC::containsError(err))
577 return err;
578 }
579
580 // If multisigning there should not be a single signature and vice versa.
581 if (signingArgs.isMultiSigning())
582 {
583 if (txJson.isMember(jss::TxnSignature))
585
586 // If multisigning then we need to return the public key.
587 signingArgs.setPublicKey(pk);
588 }
589 else if (signingArgs.isSingleSigning())
590 {
591 if (txJson.isMember(jss::Signers))
593 }
594
595 if (verify)
596 {
597 // sle validity is checked above
598 JLOG(j.trace()) << "verify: " << toBase58(calcAccountID(pk)) << " : "
599 << toBase58(srcAddressID);
600
601 // Don't do this test if multisigning or if the signature is going into
602 // an alternate field since the account and secret probably don't belong
603 // together in that case.
604 if (!signingArgs.isMultiSigning() && !signatureTarget)
605 {
606 // Make sure the account and secret belong together.
607 if (txJson.isMember(sfDelegate.jsonName))
608 {
609 // Delegated transaction
610 auto const delegateJson = txJson[sfDelegate.jsonName];
611 auto const ptrDelegatedAddressID = delegateJson.isString()
612 ? parseBase58<AccountID>(delegateJson.asString())
613 : std::nullopt;
614
615 if (!ptrDelegatedAddressID)
616 {
617 return RPC::makeError(
618 RpcSrcActMalformed, RPC::invalidFieldMessage("tx_json.Delegate"));
619 }
620
621 auto delegatedAddressID = *ptrDelegatedAddressID;
622 auto delegatedSle =
623 app.getOpenLedger().current()->read(keylet::account(delegatedAddressID));
624 if (!delegatedSle)
626
627 auto const err = acctMatchesPubKey(delegatedSle, delegatedAddressID, pk);
628
629 if (err != RpcSuccess)
630 return rpcError(err);
631 }
632 else
633 {
634 auto const err = acctMatchesPubKey(sle, srcAddressID, pk);
635
636 if (err != RpcSuccess)
637 return rpcError(err);
638 }
639 }
640 }
641
642 STParsedJSONObject parsed(std::string(jss::tx_json), txJson);
643 if (!parsed.object.has_value())
644 {
645 json::Value err;
646 err[jss::error] = parsed.error[jss::error];
647 err[jss::error_code] = parsed.error[jss::error_code];
648 err[jss::error_message] = parsed.error[jss::error_message];
649 return err;
650 }
651
653 try
654 {
655 // If we're generating a multi-signature the SigningPubKey must be
656 // empty, otherwise it must be the master account's public key.
657 STObject* sigObject = &*parsed.object;
658 if (signatureTarget)
659 {
660 // If the target object doesn't exist, make one.
661 if (!parsed.object->isFieldPresent(*signatureTarget))
662 {
663 parsed.object->setFieldObject(
664 *signatureTarget, STObject{*signatureTemplate, *signatureTarget});
665 }
666 sigObject = &parsed.object->peekFieldObject(*signatureTarget);
667 }
668 sigObject->setFieldVL(
669 sfSigningPubKey, signingArgs.isMultiSigning() ? Slice(nullptr, 0) : pk.slice());
670
671 stTx = std::make_shared<STTx>(std::move(parsed.object.value()));
672 }
673 catch (STObject::FieldErr const& err)
674 {
675 return RPC::makeError(RpcInvalidParams, err.what());
676 }
677 catch (std::exception&)
678 {
679 return RPC::makeError(
680 RpcInternal, "Exception occurred constructing serialized transaction");
681 }
682
683 std::string reason;
684 if (!passesLocalChecks(*stTx, reason))
685 return RPC::makeError(RpcInvalidParams, reason);
686
687 // If multisign then return multiSignature, else set TxnSignature field.
688 if (signingArgs.isMultiSigning())
689 {
690 Serializer const s = buildMultiSigningData(*stTx, signingArgs.getSigner());
691
692 auto multisig = xrpl::sign(pk, sk, s.slice());
693
694 signingArgs.moveMultiSignature(std::move(multisig));
695 }
696 else if (signingArgs.isSingleSigning())
697 {
698 stTx->sign(pk, sk, signatureTarget);
699 }
700
701 return TransactionPreProcessResult{std::move(stTx)};
702}
703
706 std::shared_ptr<STTx const> const& stTx,
707 Rules const& rules,
708 Application& app)
709{
711
712 // Turn the passed in STTx into a Transaction.
713 Transaction::pointer tpTrans;
714 {
715 std::string reason;
716 tpTrans = std::make_shared<Transaction>(stTx, reason, app);
717 if (tpTrans->getStatus() != TransStatus::NEW)
718 {
719 ret.first = RPC::makeError(RpcInternal, "Unable to construct transaction: " + reason);
720 return ret;
721 }
722 }
723 try
724 {
725 // Make sure the Transaction we just built is legit by serializing it
726 // and then de-serializing it. If the result isn't equivalent
727 // to the initial transaction then there's something wrong with the
728 // passed-in STTx.
729 {
730 Serializer s;
731 tpTrans->getSTransaction()->add(s);
732 Blob const transBlob = s.getData();
733 SerialIter sit{makeSlice(transBlob)};
734
735 // Check the signature if that's called for.
736 auto sttxNew = std::make_shared<STTx const>(sit);
737 if (!app.checkSigs())
738 {
740 app.getHashRouter(), sttxNew->getTransactionID(), Validity::SigGoodOnly);
741 }
742 if (checkValidity(app.getHashRouter(), *sttxNew, rules).first != Validity::Valid)
743 {
744 ret.first = RPC::makeError(RpcInternal, "Invalid signature.");
745 return ret;
746 }
747
748 std::string reason;
749 auto tpTransNew = std::make_shared<Transaction>(sttxNew, reason, app);
750
751 if (tpTransNew)
752 {
753 if (!tpTransNew->getSTransaction()->isEquivalent(*tpTrans->getSTransaction()))
754 {
755 tpTransNew.reset();
756 }
757 tpTrans = std::move(tpTransNew);
758 }
759 }
760 }
761 catch (std::exception&)
762 {
763 // Assume that any exceptions are related to transaction sterilization.
764 tpTrans.reset();
765 }
766
767 if (!tpTrans)
768 {
769 ret.first = RPC::makeError(RpcInternal, "Unable to sterilize transaction.");
770 return ret;
771 }
772 ret.second = std::move(tpTrans);
773 return ret;
774}
775
776static json::Value
778{
779 json::Value jvResult;
780 try
781 {
782 if (apiVersion > 1)
783 {
784 jvResult[jss::tx_json] = tpTrans->getJson(JsonOptions::Values::DisableApiPriorV2);
785 jvResult[jss::hash] = to_string(tpTrans->getID());
786 }
787 else
788 {
789 jvResult[jss::tx_json] = tpTrans->getJson(JsonOptions::Values::None);
790 }
791
793 jvResult[jss::tx_json], tpTrans->getSTransaction()->getTxnType(), apiVersion);
794
795 jvResult[jss::tx_blob] = strHex(tpTrans->getSTransaction()->getSerializer().peekData());
796
797 if (temUNCERTAIN != tpTrans->getResult())
798 {
799 std::string sToken;
800 std::string sHuman;
801
802 transResultInfo(tpTrans->getResult(), sToken, sHuman);
803
804 jvResult[jss::engine_result] = sToken;
805 jvResult[jss::engine_result_code] = tpTrans->getResult();
806 jvResult[jss::engine_result_message] = sHuman;
807 }
808 }
809 catch (std::exception&)
810 {
811 jvResult = RPC::makeError(RpcInternal, "Exception occurred during JSON handling.");
812 }
813 return jvResult;
814}
815
816} // namespace detail
817
818//------------------------------------------------------------------------------
819
820[[nodiscard]] static XRPAmount
821getTxFee(Application const& app, Config const& config, json::Value tx)
822{
823 auto const& ledger = app.getOpenLedger().current();
824 // autofilling only needed in this function so that the `STParsedJSONObject`
825 // parsing works properly it should not be modifying the actual `tx` object
826 if (!tx.isMember(jss::Fee))
827 {
828 tx[jss::Fee] = "0";
829 }
830
831 if (!tx.isMember(jss::Sequence))
832 {
833 tx[jss::Sequence] = "0";
834 }
835
836 if (!tx.isMember(jss::SigningPubKey))
837 {
838 tx[jss::SigningPubKey] = "";
839 }
840
841 if (!tx.isMember(jss::TxnSignature))
842 {
843 tx[jss::TxnSignature] = "";
844 }
845
846 if (tx.isMember(jss::Signers))
847 {
848 if (!tx[jss::Signers].isArray())
849 return config.fees.referenceFee;
850
851 if (tx[jss::Signers].size() > STTx::kMaxMultiSigners)
852 return config.fees.referenceFee;
853
854 // check multi-signed signers
855 for (auto& signer : tx[jss::Signers])
856 {
857 if (!signer.isMember(jss::Signer) || !signer[jss::Signer].isObject())
858 return config.fees.referenceFee;
859 if (!signer[jss::Signer].isMember(jss::SigningPubKey))
860 {
861 // autofill SigningPubKey
862 signer[jss::Signer][jss::SigningPubKey] = "";
863 }
864 if (!signer[jss::Signer].isMember(jss::TxnSignature))
865 {
866 // autofill TxnSignature
867 signer[jss::Signer][jss::TxnSignature] = "";
868 }
869 }
870 }
871
872 STParsedJSONObject parsed(std::string(jss::tx_json), tx);
873 if (!parsed.object.has_value())
874 {
875 return config.fees.referenceFee;
876 }
877
878 try
879 {
880 STTx const& stTx = STTx(std::move(parsed.object.value()));
881 std::string reason;
882 if (!passesLocalChecks(stTx, reason))
883 return config.fees.referenceFee;
884
885 return calculateBaseFee(*app.getOpenLedger().current(), stTx);
886 }
887 catch (std::exception& e)
888 {
889 return config.fees.referenceFee;
890 }
891}
892
895 Role const role,
896 Config const& config,
897 LoadFeeTrack const& feeTrack,
898 TxQ const& txQ,
899 Application const& app,
900 json::Value const& tx,
901 int mult,
902 int div)
903{
904 XRPAmount const feeDefault = getTxFee(app, config, tx);
905
906 auto ledger = app.getOpenLedger().current();
907 // Administrative and identified endpoints are exempt from local fees.
908 XRPAmount const loadFee = scaleFeeLoad(feeDefault, feeTrack, ledger->fees(), isUnlimited(role));
909 XRPAmount fee = loadFee;
910 {
911 auto const metrics = txQ.getMetrics(*ledger);
912 auto const baseFee = ledger->fees().base;
913 auto escalatedFee = toDrops(metrics.openLedgerFeeLevel - FeeLevel64(1), baseFee) + 1;
914 fee = std::max(fee, escalatedFee);
915 }
916
917 auto const limit = mulDiv(feeDefault, mult, div);
918 if (!limit)
920
921 if (fee > *limit)
922 {
924 ss << "Fee of " << fee << " exceeds the requested tx limit of " << *limit;
925 return RPC::makeError(RpcHighFee, ss.str());
926 }
927
928 return fee.jsonClipped();
929}
930
933 json::Value& request,
934 Role const role,
935 bool doAutoFill,
936 Config const& config,
937 LoadFeeTrack const& feeTrack,
938 TxQ const& txQ,
939 Application const& app)
940{
941 json::Value& tx(request[jss::tx_json]);
942 if (tx.isMember(jss::Fee))
943 return json::Value();
944
945 if (!doAutoFill)
946 return RPC::missingFieldError("tx_json.Fee");
947
950 if (request.isMember(jss::fee_mult_max))
951 {
952 if (request[jss::fee_mult_max].isInt())
953 {
954 mult = request[jss::fee_mult_max].asInt();
955 if (mult < 0)
956 {
957 return RPC::makeError(
959 RPC::expectedFieldMessage(jss::fee_mult_max, "a positive integer"));
960 }
961 }
962 else
963 {
964 return RPC::makeError(
965 RpcHighFee, RPC::expectedFieldMessage(jss::fee_mult_max, "a positive integer"));
966 }
967 }
968 if (request.isMember(jss::fee_div_max))
969 {
970 if (request[jss::fee_div_max].isInt())
971 {
972 div = request[jss::fee_div_max].asInt();
973 if (div <= 0)
974 {
975 return RPC::makeError(
977 RPC::expectedFieldMessage(jss::fee_div_max, "a positive integer"));
978 }
979 }
980 else
981 {
982 return RPC::makeError(
983 RpcHighFee, RPC::expectedFieldMessage(jss::fee_div_max, "a positive integer"));
984 }
985 }
986
987 auto feeOrError = getCurrentNetworkFee(role, config, feeTrack, txQ, app, tx, mult, div);
988 if (feeOrError.isMember(jss::error))
989 return feeOrError;
990 tx[jss::Fee] = std::move(feeOrError);
991 return json::Value();
992}
993
994//------------------------------------------------------------------------------
995
999 json::Value jvRequest,
1000 unsigned apiVersion,
1001 NetworkOPs::FailHard failType,
1002 Role role,
1003 std::chrono::seconds validatedLedgerAge,
1004 Application& app)
1005{
1006 using namespace detail;
1007
1008 auto j = app.getJournal("RPCHandler");
1009 JLOG(j.debug()) << "transactionSign: " << jvRequest;
1010
1011 // Add and amend fields based on the transaction type.
1012 SigningForParams signForParams;
1013 TransactionPreProcessResult const preprocResult =
1014 transactionPreProcessImpl(jvRequest, role, signForParams, validatedLedgerAge, app);
1015
1016 if (!preprocResult.second)
1017 return preprocResult.first;
1018
1020 // Make sure the STTx makes a legitimate Transaction.
1022 transactionConstructImpl(preprocResult.second, ledger->rules(), app);
1023
1024 if (!txn.second)
1025 return txn.first;
1026
1027 return transactionFormatResultImpl(txn.second, apiVersion);
1028}
1029
1033 json::Value jvRequest,
1034 unsigned apiVersion,
1035 NetworkOPs::FailHard failType,
1036 Role role,
1037 std::chrono::seconds validatedLedgerAge,
1038 Application& app,
1039 ProcessTransactionFn const& processTransaction)
1040{
1041 using namespace detail;
1042
1043 auto const& ledger = app.getOpenLedger().current();
1044 auto j = app.getJournal("RPCHandler");
1045 JLOG(j.debug()) << "transactionSubmit: " << jvRequest;
1046
1047 // Add and amend fields based on the transaction type.
1048 SigningForParams signForParams;
1049 TransactionPreProcessResult const preprocResult =
1050 transactionPreProcessImpl(jvRequest, role, signForParams, validatedLedgerAge, app);
1051
1052 if (!preprocResult.second)
1053 return preprocResult.first;
1054
1055 // Make sure the STTx makes a legitimate Transaction.
1057 transactionConstructImpl(preprocResult.second, ledger->rules(), app);
1058
1059 if (!txn.second)
1060 return txn.first;
1061
1062 // Finally, submit the transaction.
1063 try
1064 {
1065 // FIXME: For performance, should use async interface
1066 processTransaction(txn.second, isUnlimited(role), true, failType);
1067 }
1068 catch (std::exception&)
1069 {
1070 return RPC::makeError(RpcInternal, "Exception occurred during transaction submission.");
1071 }
1072
1073 return transactionFormatResultImpl(txn.second, apiVersion);
1074}
1075
1076namespace detail {
1077// There are a some field checks shared by transactionSignFor
1078// and transactionSubmitMultiSigned. Gather them together here.
1079static json::Value
1081{
1082 if (!jvRequest.isMember(jss::tx_json))
1083 return RPC::missingFieldError(jss::tx_json);
1084
1085 json::Value const& txJson(jvRequest[jss::tx_json]);
1086
1087 if (!txJson.isObject())
1088 return RPC::invalidFieldMessage(jss::tx_json);
1089
1090 // There are a couple of additional fields we need to check before
1091 // we serialize. If we serialize first then we generate less useful
1092 // error messages.
1093 if (!txJson.isMember(jss::Sequence))
1094 return RPC::missingFieldError("tx_json.Sequence");
1095
1096 if (!txJson.isMember(sfSigningPubKey.getJsonName()))
1097 return RPC::missingFieldError("tx_json.SigningPubKey");
1098
1099 // Multi-signing into a signature_target object field is fine,
1100 // because it means the signature is not for the transaction
1101 // Account.
1102 if (!jvRequest.isMember(jss::signature_target) &&
1103 !txJson[sfSigningPubKey.getJsonName()].asString().empty())
1104 {
1105 return RPC::makeError(
1106 RpcInvalidParams, "When multi-signing 'tx_json.SigningPubKey' must be empty.");
1107 }
1108
1109 return json::Value();
1110}
1111
1112// Sort and validate an stSigners array.
1113//
1114// Returns a null json::Value if there are no errors.
1115static json::Value
1116sortAndValidateSigners(STArray& signers, AccountID const& signingForID)
1117{
1118 if (signers.empty())
1119 return RPC::makeParamError("Signers array may not be empty.");
1120
1121 // Signers must be sorted by Account.
1122 std::ranges::sort(signers, [](STObject const& a, STObject const& b) {
1123 return (a[sfAccount] < b[sfAccount]);
1124 });
1125
1126 // Signers may not contain any duplicates.
1127 auto const dupIter = std::ranges::adjacent_find(
1128 signers,
1129 [](STObject const& a, STObject const& b) { return (a[sfAccount] == b[sfAccount]); });
1130
1131 if (dupIter != signers.end())
1132 {
1134 err << "Duplicate Signers:Signer:Account entries (" << toBase58((*dupIter)[sfAccount])
1135 << ") are not allowed.";
1136 return RPC::makeParamError(err.str());
1137 }
1138
1139 // An account may not sign for itself.
1140 if (signers.end() != std::ranges::find_if(signers, [&signingForID](STObject const& elem) {
1141 return elem[sfAccount] == signingForID;
1142 }))
1143 {
1145 err << "A Signer may not be the transaction's Account (" << toBase58(signingForID) << ").";
1146 return RPC::makeParamError(err.str());
1147 }
1148 return {};
1149}
1150
1151} // namespace detail
1152
1156 json::Value jvRequest,
1157 unsigned apiVersion,
1158 NetworkOPs::FailHard failType,
1159 Role role,
1160 std::chrono::seconds validatedLedgerAge,
1161 Application& app)
1162{
1163 auto const& ledger = app.getOpenLedger().current();
1164 auto j = app.getJournal("RPCHandler");
1165 JLOG(j.debug()) << "transactionSignFor: " << jvRequest;
1166
1167 // Verify presence of the signer's account field.
1168 char const accountField[] = "account";
1169
1170 if (!jvRequest.isMember(accountField))
1171 return RPC::missingFieldError(accountField);
1172
1173 // Turn the signer's account into an AccountID for multi-sign.
1174 auto const signerAccountID = parseBase58<AccountID>(jvRequest[accountField].asString());
1175 if (!signerAccountID)
1176 {
1178 }
1179
1180 if (!jvRequest.isMember(jss::tx_json))
1181 return RPC::missingFieldError(jss::tx_json);
1182
1183 {
1184 json::Value& txJson(jvRequest[jss::tx_json]);
1185
1186 if (!txJson.isObject())
1187 return RPC::objectFieldError(jss::tx_json);
1188
1189 if (auto checkResult =
1191 !checkResult)
1192 {
1193 return std::move(checkResult).error();
1194 }
1195
1196 // If the tx_json.SigningPubKey field is missing, insert an empty one,
1197 // in order for the `checkMultiSignFields` to not return an error
1198 // for non-multisign transactions.
1199 if (!txJson.isMember(sfSigningPubKey.getJsonName()))
1200 txJson[sfSigningPubKey.getJsonName()] = "";
1201 }
1202
1203 // When multi-signing, the "Sequence" and "SigningPubKey" fields must
1204 // be passed in by the caller.
1205 using namespace detail;
1206 {
1207 json::Value err = checkMultiSignFields(jvRequest);
1208 if (RPC::containsError(err))
1209 return err;
1210 }
1211
1212 // Add and amend fields based on the transaction type.
1213 SigningForParams signForParams(*signerAccountID);
1214
1215 TransactionPreProcessResult const preprocResult =
1216 transactionPreProcessImpl(jvRequest, role, signForParams, validatedLedgerAge, app);
1217
1218 if (!preprocResult.second)
1219 return preprocResult.first;
1220
1221 XRPL_ASSERT(
1222 signForParams.validMultiSign(), "xrpl::RPC::transactionSignFor : valid multi-signature");
1223
1224 {
1225 SLE::const_pointer const accountState = ledger->read(keylet::account(*signerAccountID));
1226 // Make sure the account and secret belong together.
1227 auto const err =
1228 acctMatchesPubKey(accountState, *signerAccountID, signForParams.getPublicKey());
1229
1230 if (err != RpcSuccess)
1231 return rpcError(err);
1232 }
1233
1234 // Inject the newly generated signature into tx_json.Signers.
1235 auto& sttx = preprocResult.second;
1236 {
1237 // Make the signer object that we'll inject.
1238 STObject signer = STObject::makeInnerObject(sfSigner);
1239 signer[sfAccount] = *signerAccountID;
1240 signer.setFieldVL(sfTxnSignature, signForParams.getSignature());
1241 signer.setFieldVL(sfSigningPubKey, signForParams.getPublicKey().slice());
1242
1243 STObject& sigTarget = [&]() -> STObject& {
1244 auto const target = signForParams.getSignatureTarget();
1245 if (target)
1246 return sttx->peekFieldObject(*target);
1247 return *sttx;
1248 }();
1249 // If there is not yet a Signers array, make one.
1250 if (!sigTarget.isFieldPresent(sfSigners))
1251 sigTarget.setFieldArray(sfSigners, {});
1252
1253 auto& signers = sigTarget.peekFieldArray(sfSigners);
1254 signers.emplaceBack(std::move(signer));
1255
1256 // The array must be sorted and validated.
1257 // For delegated transactions, the delegate account is
1258 // the one forbidden from appearing in its own Signers array.
1259 auto err = sortAndValidateSigners(signers, sttx->getFeePayer());
1260 if (RPC::containsError(err))
1261 return err;
1262 }
1263
1264 // Make sure the STTx makes a legitimate Transaction.
1266 transactionConstructImpl(sttx, ledger->rules(), app);
1267
1268 if (!txn.second)
1269 return txn.first;
1270
1271 return transactionFormatResultImpl(txn.second, apiVersion);
1272}
1273
1277 json::Value jvRequest,
1278 unsigned apiVersion,
1279 NetworkOPs::FailHard failType,
1280 Role role,
1281 std::chrono::seconds validatedLedgerAge,
1282 Application& app,
1283 ProcessTransactionFn const& processTransaction)
1284{
1285 auto const& ledger = app.getOpenLedger().current();
1286 auto j = app.getJournal("RPCHandler");
1287 JLOG(j.debug()) << "transactionSubmitMultiSigned: " << jvRequest;
1288
1289 // When multi-signing, the "Sequence" and "SigningPubKey" fields must
1290 // be passed in by the caller.
1291 using namespace detail;
1292 {
1293 json::Value err = checkMultiSignFields(jvRequest);
1294 if (RPC::containsError(err))
1295 return err;
1296 }
1297
1298 json::Value& txJson(jvRequest["tx_json"]);
1299
1300 auto [txJsonResult, srcAddressID] = checkTxJsonFields(
1301 txJson,
1302 role,
1303 true,
1304 validatedLedgerAge,
1305 app.config(),
1306 app.getFeeTrack(),
1307 getAPIVersionNumber(jvRequest, app.config().betaRpcApi));
1308
1309 if (RPC::containsError(txJsonResult))
1310 return std::move(txJsonResult);
1311
1312 SLE::const_pointer const sle = ledger->read(keylet::account(srcAddressID));
1313
1314 if (!sle)
1315 {
1316 // If did not find account, error.
1317 JLOG(j.debug()) << "transactionSubmitMultiSigned: Failed to find source account "
1318 << "in current ledger: " << toBase58(srcAddressID);
1319
1321 }
1322
1323 {
1324 json::Value err =
1325 checkFee(jvRequest, role, false, app.config(), app.getFeeTrack(), app.getTxQ(), app);
1326
1327 if (RPC::containsError(err))
1328 return err;
1329
1330 err = checkPayment(jvRequest, txJson, srcAddressID, role, app, false);
1331
1332 if (RPC::containsError(err))
1333 return err;
1334 }
1335
1336 // Grind through the JSON in tx_json to produce a STTx.
1338 {
1339 STParsedJSONObject parsedTxJson("tx_json", txJson);
1340 if (!parsedTxJson.object)
1341 {
1342 json::Value jvResult;
1343 jvResult["error"] = parsedTxJson.error["error"];
1344 jvResult["error_code"] = parsedTxJson.error["error_code"];
1345 jvResult["error_message"] = parsedTxJson.error["error_message"];
1346 return jvResult;
1347 }
1348 try
1349 {
1350 stTx = std::make_shared<STTx>(std::move(parsedTxJson.object.value()));
1351 }
1352 catch (STObject::FieldErr const& err)
1353 {
1354 return RPC::makeError(RpcInvalidParams, err.what());
1355 }
1356 catch (std::exception& ex)
1357 {
1358 std::string const reason(ex.what());
1359 return RPC::makeError(
1360 RpcInternal, "Exception while serializing transaction: " + reason);
1361 }
1362 std::string reason;
1363 if (!passesLocalChecks(*stTx, reason))
1364 return RPC::makeError(RpcInvalidParams, reason);
1365 }
1366
1367 // Validate the fields in the serialized transaction.
1368 {
1369 // We now have the transaction text serialized and in the right format.
1370 // Verify the values of select fields.
1371 //
1372 // The SigningPubKey must be present but empty.
1373 if (!stTx->getFieldVL(sfSigningPubKey).empty())
1374 {
1376 err << "Invalid " << sfSigningPubKey.fieldName
1377 << " field. Field must be empty when multi-signing.";
1378 return RPC::makeError(RpcInvalidParams, err.str());
1379 }
1380
1381 // There may not be a TxnSignature field.
1382 if (stTx->isFieldPresent(sfTxnSignature))
1384
1385 // The Fee field must be in XRP and greater than zero.
1386 auto const fee = stTx->getFieldAmount(sfFee);
1387
1388 if (!isLegalNet(fee))
1389 {
1391 err << "Invalid " << sfFee.fieldName << " field. Fees must be specified in XRP.";
1392 return RPC::makeError(RpcInvalidParams, err.str());
1393 }
1394 if (fee <= STAmount{0})
1395 {
1397 err << "Invalid " << sfFee.fieldName << " field. Fees must be greater than zero.";
1398 return RPC::makeError(RpcInvalidParams, err.str());
1399 }
1400 }
1401
1402 // Verify that the Signers field is present.
1403 if (!stTx->isFieldPresent(sfSigners))
1404 return RPC::missingFieldError("tx_json.Signers");
1405
1406 // If the Signers field is present the SField guarantees it to be an array.
1407 // Get a reference to the Signers array so we can verify and sort it.
1408 auto& signers = stTx->peekFieldArray(sfSigners);
1409
1410 if (signers.empty())
1411 return RPC::makeParamError("tx_json.Signers array may not be empty.");
1412
1413 // The Signers array may only contain Signer objects.
1414 if (std::ranges::find_if_not(signers, [](STObject const& obj) {
1415 return (
1416 // A Signer object always contains these fields and no
1417 // others.
1418 obj.isFieldPresent(sfAccount) && obj.isFieldPresent(sfSigningPubKey) &&
1419 obj.isFieldPresent(sfTxnSignature) && obj.getCount() == 3);
1420 }) != signers.end())
1421 {
1422 return RPC::makeParamError("Signers array may only contain Signer entries.");
1423 }
1424
1425 // The array must be sorted and validated.
1426 // For delegated transactions, getFeePayer() returns sfDelegate,
1427 // that account is the one forbidden from appearing in its own Signers array.
1428 auto err = sortAndValidateSigners(signers, stTx->getFeePayer());
1429 if (RPC::containsError(err))
1430 return err;
1431
1432 // Make sure the SerializedTransaction makes a legitimate Transaction.
1434 transactionConstructImpl(stTx, ledger->rules(), app);
1435
1436 if (!txn.second)
1437 return txn.first;
1438
1439 // Finally, submit the transaction.
1440 try
1441 {
1442 // FIXME: For performance, should use async interface
1443 processTransaction(txn.second, isUnlimited(role), true, failType);
1444 }
1445 catch (std::exception&)
1446 {
1447 return RPC::makeError(RpcInternal, "Exception occurred during transaction submission.");
1448 }
1449
1450 return transactionFormatResultImpl(txn.second, apiVersion);
1451}
1452
1453} // namespace xrpl::RPC
T adjacent_find(T... args)
Represents a JSON value.
Definition json_value.h:130
Value removeMember(char const *key)
Remove and return the named member.
bool isObject() const
bool isString() const
const_iterator end() const
std::string asString() const
Returns the unquoted string value.
bool isMember(char const *key) const
Return true if the object has a member named key.
Int asInt() const
virtual Config & config()=0
virtual bool checkSigs() const =0
constexpr auto visit(Visitors &&... visitors) const -> decltype(auto)
Definition Asset.h:107
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Definition base_uint.h:507
Like std::vector<char> but better.
Definition Buffer.h:16
int pathSearchOld
Definition Config.h:181
bool standalone() const
Definition Config.h:316
FeeSetup fees
Definition Config.h:189
bool betaRpcApi
Definition Config.h:272
SOTemplate const * findSOTemplateBySField(SField const &sField) const
static InnerObjectFormats const & getInstance()
A currency issued by an account.
Definition Issue.h:13
Manages the current fee schedule.
bool isLoadedCluster() const
virtual std::uint32_t getNetworkID() const noexcept=0
Get the configured network ID.
std::shared_ptr< OpenView const > current() const
Returns a view to the current open ledger.
Calculates payment paths.
Definition Pathfinder.h:22
STPathSet getBestPaths(int maxPaths, STPath &fullLiquidityPath, STPathSet const &extraPaths, AccountID const &srcIssuer, std::function< bool(void)> const &continueCallback={})
bool findPaths(int searchLevel, std::function< bool(void)> const &continueCallback={})
void computePathRanks(int maxPaths, std::function< bool(void)> const &continueCallback={})
Compute the rankings of the paths.
A public key.
Definition PublicKey.h:42
Slice slice() const noexcept
Definition PublicKey.h:103
void setSignatureTarget(std::optional< std::reference_wrapper< SField const > > const &field)
std::optional< PublicKey > multiSignPublicKey_
AccountID const & getSigner() const
std::optional< std::reference_wrapper< SField const > > const & getSignatureTarget() const
void setPublicKey(PublicKey const &multiSignPublicKey)
PublicKey const & getPublicKey() const
SigningForParams(AccountID const &multiSigningAcctID)
void moveMultiSignature(Buffer &&multiSignature)
std::optional< std::reference_wrapper< SField const > > signatureTarget_
AccountID const *const multiSigningAcctID_
SigningForParams(SigningForParams const &rhs)=delete
Rules controlling protocol behavior.
Definition Rules.h:33
static SField const & getField(int fieldCode)
Definition SField.cpp:116
constexpr bool holds() const noexcept
Definition STAmount.h:460
constexpr TIss const & get() const
bool native() const noexcept
Definition STAmount.h:453
Asset const & asset() const
Definition STAmount.h:478
AccountID const & getIssuer() const
Definition STAmount.h:498
std::shared_ptr< STLedgerEntry const > const_pointer
void setFieldVL(SField const &field, Blob const &)
Definition STObject.cpp:781
STArray & peekFieldArray(SField const &field)
Definition STObject.cpp:471
void setFieldArray(SField const &field, STArray const &v)
Definition STObject.cpp:823
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:454
int getCount() const
Definition STObject.h:1010
static STObject makeInnerObject(SField const &name)
Definition STObject.cpp:74
Holds the serialized result of parsing an input JSON object.
std::optional< STObject > object
The STObject if the parse was successful.
json::Value error
On failure, an appropriate set of error values.
json::Value getJson(JsonOptions) const override
bool empty() const
Definition STPathSet.h:534
static constexpr std::size_t kMaxMultiSigners
Definition STTx.h:34
A secret key.
Definition SecretKey.h:18
constexpr std::uint32_t value() const
Definition SeqProxy.h:62
Slice slice() const noexcept
Definition Serializer.h:44
Blob getData() const
Definition Serializer.h:181
virtual TxQ & getTxQ()=0
virtual beast::Journal getJournal(std::string const &name)=0
virtual OpenLedger & getOpenLedger()=0
virtual NetworkIDService & getNetworkIDService()=0
virtual LoadFeeTrack & getFeeTrack()=0
virtual HashRouter & getHashRouter()=0
An immutable linear range of bytes.
Definition Slice.h:26
std::shared_ptr< Transaction > pointer
Definition Transaction.h:44
Transaction Queue.
Definition TxQ.h:40
Metrics getMetrics(OpenView const &view) const
Returns fee metrics in reference fee level units.
Definition TxQ.cpp:1739
SeqProxy nextQueuableSeq(SLE::const_ref sleAccount) const
Return the next sequence that would go in the TxQ for an account.
Definition TxQ.cpp:1579
json::Value jsonClipped() const
Definition XRPAmount.h:199
T empty(T... args)
T find_if(T... args)
T make_shared(T... args)
T max(T... args)
JSON (JavaScript Object Notation).
Definition json_errors.h:5
STL namespace.
static constexpr int kDefaultAutoFillFeeDivisor
static constexpr int kDefaultAutoFillFeeMultiplier
static std::expected< void, json::Value > checkNetworkID(json::Value const &txJson, uint32_t appNetworkId)
static std::pair< json::Value, AccountID > checkTxJsonFields(json::Value const &txJson, Role const role, bool const verify, std::chrono::seconds validatedLedgerAge, Config const &config, LoadFeeTrack const &feeTrack, unsigned apiVersion)
static ErrorCodeI acctMatchesPubKey(SLE::const_pointer accountState, AccountID const &accountID, PublicKey const &publicKey)
static json::Value checkMultiSignFields(json::Value const &jvRequest)
static json::Value transactionFormatResultImpl(Transaction::pointer tpTrans, unsigned apiVersion)
static json::Value sortAndValidateSigners(STArray &signers, AccountID const &signingForID)
static TransactionPreProcessResult transactionPreProcessImpl(json::Value &params, Role role, SigningForParams &signingArgs, std::chrono::seconds validatedLedgerAge, Application &app)
static std::pair< json::Value, Transaction::pointer > transactionConstructImpl(std::shared_ptr< STTx const > const &stTx, Rules const &rules, Application &app)
static json::Value checkPayment(json::Value const &params, json::Value &txJson, AccountID const &srcAddressID, Role const role, Application &app, bool doPath)
API version numbers used in later API versions.
Definition ApiVersion.h:35
json::Value checkFee(json::Value &request, Role const role, bool doAutoFill, Config const &config, LoadFeeTrack const &feeTrack, TxQ const &txQ, Application const &app)
Fill in the fee on behalf of the client.
std::string missingFieldMessage(std::string const &name)
Definition ErrorCodes.h:225
void insertDeliverMax(json::Value &txJson, TxType txnType, unsigned int apiVersion)
Copy Amount field to DeliverMax field in transaction output JSON.
Definition DeliverMax.cpp:9
std::optional< std::pair< PublicKey, SecretKey > > keypairForSignature(json::Value const &params, json::Value &error, unsigned int apiVersion)
Generates a keypair for signature from RPC parameters.
static XRPAmount getTxFee(Application const &app, Config const &config, json::Value tx)
json::Value objectFieldError(std::string const &name)
Definition ErrorCodes.h:249
json::Value transactionSignFor(json::Value jvRequest, unsigned apiVersion, NetworkOPs::FailHard failType, Role role, std::chrono::seconds validatedLedgerAge, Application &app)
Returns a json::ValueType::Object.
std::string invalidFieldMessage(std::string const &name)
Definition ErrorCodes.h:261
json::Value makeError(ErrorCodeI code)
Returns a new json object that reflects the error code.
json::Value transactionSign(json::Value jvRequest, unsigned apiVersion, NetworkOPs::FailHard failType, Role role, std::chrono::seconds validatedLedgerAge, Application &app)
Returns a json::ValueType::Object.
std::function< void( std::shared_ptr< Transaction > &transaction, bool bUnlimited, bool bLocal, NetworkOPs::FailHard failType)> ProcessTransactionFn
json::Value transactionSubmit(json::Value jvRequest, unsigned apiVersion, NetworkOPs::FailHard failType, Role role, std::chrono::seconds validatedLedgerAge, Application &app, ProcessTransactionFn const &processTransaction)
Returns a json::ValueType::Object.
json::Value transactionSubmitMultiSigned(json::Value jvRequest, unsigned apiVersion, NetworkOPs::FailHard failType, Role role, std::chrono::seconds validatedLedgerAge, Application &app, ProcessTransactionFn const &processTransaction)
Returns a json::ValueType::Object.
json::Value getCurrentNetworkFee(Role const role, Config const &config, LoadFeeTrack const &feeTrack, TxQ const &txQ, Application const &app, json::Value const &tx, int mult, int div)
std::string expectedFieldMessage(std::string const &name, std::string const &type)
Definition ErrorCodes.h:285
unsigned int getAPIVersionNumber(json::Value const &jv, bool betaEnabled)
Retrieve the api version number from the json value.
Definition ApiVersion.h:99
bool containsError(json::Value const &json)
Returns true if the json contains an rpc error specification.
json::Value invalidFieldError(std::string const &name)
Definition ErrorCodes.h:273
json::Value makeParamError(std::string const &message)
Returns a new json object that indicates invalid parameters.
Definition ErrorCodes.h:219
json::Value missingFieldError(std::string const &name)
Definition ErrorCodes.h:231
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:186
ErrorCodeI
Definition ErrorCodes.h:22
@ RpcBadSecret
Definition ErrorCodes.h:80
@ RpcInternal
Definition ErrorCodes.h:112
@ RpcDelegateActNotFound
Definition ErrorCodes.h:105
@ RpcSrcActMalformed
Definition ErrorCodes.h:102
@ RpcAlreadySingleSig
Definition ErrorCodes.h:74
@ RpcSigningMalformed
Definition ErrorCodes.h:100
@ RpcSuccess
Definition ErrorCodes.h:26
@ RpcNotSynced
Definition ErrorCodes.h:49
@ RpcHighFee
Definition ErrorCodes.h:40
@ RpcMasterDisabled
Definition ErrorCodes.h:56
@ RpcDomainMalformed
Definition ErrorCodes.h:140
@ RpcSrcActMissing
Definition ErrorCodes.h:103
@ RpcInvalidParams
Definition ErrorCodes.h:66
@ RpcTooBusy
Definition ErrorCodes.h:38
@ RpcAlreadyMultisig
Definition ErrorCodes.h:73
@ RpcNoCurrent
Definition ErrorCodes.h:47
@ RpcSrcActNotFound
Definition ErrorCodes.h:104
std::optional< std::uint64_t > mulDiv(std::uint64_t value, std::uint64_t mul, std::uint64_t div)
Return value*mul/div accurately.
@ Valid
Signature and local checks are good / passed.
Definition apply.h:25
@ SigGoodOnly
Signature is good, but local checks fail.
Definition apply.h:23
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:10
std::pair< Validity, std::string > checkValidity(HashRouter &router, STTx const &tx, Rules const &rules)
Checks transaction signature and local checks.
Definition apply.cpp:37
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig) noexcept
Verify a signature on a message.
bool isLegalNet(STAmount const &value)
Definition STAmount.h:598
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:93
XRPAmount toDrops(FeeLevel< T > const &level, XRPAmount baseFee)
Definition TxQ.h:830
bool transResultInfo(TER code, std::string &token, std::string &text)
Definition TER.cpp:232
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:633
void logicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
json::Value rpcError(ErrorCodeI iError)
Definition RPCErr.cpp:13
Role
Indicates the level of administrative permission to grant.
Definition Role.h:24
bool amountFromJsonNoThrow(STAmount &result, json::Value const &jvSource)
FeeLevel< std::uint64_t > FeeLevel64
Definition Units.h:428
bool passesLocalChecks(STObject const &st, std::string &)
Definition STTx.cpp:771
AccountID calcAccountID(PublicKey const &pk)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
@ temUNCERTAIN
Definition TER.h:109
XRPAmount scaleFeeLoad(XRPAmount fee, LoadFeeTrack const &feeTrack, Fees const &fees, bool bUnlimited)
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &message)
Generate a signature for a message.
XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Compute only the expected base fee for a transaction.
void forceValidity(HashRouter &router, uint256 const &txid, Validity validity)
Sets the validity of a given transaction in the cache.
Definition apply.cpp:112
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
Definition Role.cpp:115
std::vector< unsigned char > Blob
Storage for linear binary data.
Definition Blob.h:10
BaseUInt< 256 > uint256
Definition base_uint.h:562
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:49
std::enable_if_t< std::is_same_v< T, char >||std::is_same_v< T, unsigned char >, Slice > makeSlice(std::array< T, N > const &a)
Definition Slice.h:215
Serializer buildMultiSigningData(STObject const &obj, AccountID const &signingID)
Return a Serializer suitable for computing a multisigning TxnSignature.
T reset(T... args)
T sort(T... args)
T str(T... args)
XRPAmount referenceFee
The cost of a reference transaction in drops.
Definition Config.h:51
TransactionPreProcessResult & operator=(TransactionPreProcessResult &&)=delete
TransactionPreProcessResult(std::shared_ptr< STTx > &&st)
TransactionPreProcessResult(TransactionPreProcessResult &&rhs)=default
TransactionPreProcessResult & operator=(TransactionPreProcessResult const &)=delete
TransactionPreProcessResult(TransactionPreProcessResult const &)=delete
T unexpected(T... args)
T what(T... args)