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
1001 json::Value jvRequest,
1002 unsigned apiVersion,
1003 NetworkOPs::FailHard failType,
1004 Role role,
1005 std::chrono::seconds validatedLedgerAge,
1006 Application& app)
1007{
1008 using namespace detail;
1009
1010 auto j = app.getJournal("RPCHandler");
1011 JLOG(j.debug()) << "transactionSign: " << jvRequest;
1012
1013 // Add and amend fields based on the transaction type.
1014 SigningForParams signForParams;
1015 TransactionPreProcessResult const preprocResult =
1016 transactionPreProcessImpl(jvRequest, role, signForParams, validatedLedgerAge, app);
1017
1018 if (!preprocResult.second)
1019 return preprocResult.first;
1020
1022 // Make sure the STTx makes a legitimate Transaction.
1024 transactionConstructImpl(preprocResult.second, ledger->rules(), app);
1025
1026 if (!txn.second)
1027 return txn.first;
1028
1029 return transactionFormatResultImpl(txn.second, apiVersion);
1030}
1031
1037 json::Value jvRequest,
1038 unsigned apiVersion,
1039 NetworkOPs::FailHard failType,
1040 Role role,
1041 std::chrono::seconds validatedLedgerAge,
1042 Application& app,
1043 ProcessTransactionFn const& processTransaction)
1044{
1045 using namespace detail;
1046
1047 auto const& ledger = app.getOpenLedger().current();
1048 auto j = app.getJournal("RPCHandler");
1049 JLOG(j.debug()) << "transactionSubmit: " << jvRequest;
1050
1051 // Add and amend fields based on the transaction type.
1052 SigningForParams signForParams;
1053 TransactionPreProcessResult const preprocResult =
1054 transactionPreProcessImpl(jvRequest, role, signForParams, validatedLedgerAge, app);
1055
1056 if (!preprocResult.second)
1057 return preprocResult.first;
1058
1059 // Make sure the STTx makes a legitimate Transaction.
1061 transactionConstructImpl(preprocResult.second, ledger->rules(), app);
1062
1063 if (!txn.second)
1064 return txn.first;
1065
1066 // Finally, submit the transaction.
1067 try
1068 {
1069 // FIXME: For performance, should use async interface
1070 processTransaction(txn.second, isUnlimited(role), true, failType);
1071 }
1072 catch (std::exception&)
1073 {
1074 return rpc::makeError(RpcInternal, "Exception occurred during transaction submission.");
1075 }
1076
1077 return transactionFormatResultImpl(txn.second, apiVersion);
1078}
1079
1080namespace detail {
1081// There are a some field checks shared by transactionSignFor
1082// and transactionSubmitMultiSigned. Gather them together here.
1083static json::Value
1085{
1086 if (!jvRequest.isMember(jss::tx_json))
1087 return rpc::missingFieldError(jss::tx_json);
1088
1089 json::Value const& txJson(jvRequest[jss::tx_json]);
1090
1091 if (!txJson.isObject())
1092 return rpc::invalidFieldMessage(jss::tx_json);
1093
1094 // There are a couple of additional fields we need to check before
1095 // we serialize. If we serialize first then we generate less useful
1096 // error messages.
1097 if (!txJson.isMember(jss::Sequence))
1098 return rpc::missingFieldError("tx_json.Sequence");
1099
1100 if (!txJson.isMember(sfSigningPubKey.getJsonName()))
1101 return rpc::missingFieldError("tx_json.SigningPubKey");
1102
1103 // Multi-signing into a signature_target object field is fine,
1104 // because it means the signature is not for the transaction
1105 // Account.
1106 if (!jvRequest.isMember(jss::signature_target) &&
1107 !txJson[sfSigningPubKey.getJsonName()].asString().empty())
1108 {
1109 return rpc::makeError(
1110 RpcInvalidParams, "When multi-signing 'tx_json.SigningPubKey' must be empty.");
1111 }
1112
1113 return json::Value();
1114}
1115
1116// Sort and validate an stSigners array.
1117//
1118// Returns a null json::Value if there are no errors.
1119static json::Value
1120sortAndValidateSigners(STArray& signers, AccountID const& signingForID)
1121{
1122 if (signers.empty())
1123 return rpc::makeParamError("Signers array may not be empty.");
1124
1125 // Signers must be sorted by Account.
1126 std::ranges::sort(signers, [](STObject const& a, STObject const& b) {
1127 return (a[sfAccount] < b[sfAccount]);
1128 });
1129
1130 // Signers may not contain any duplicates.
1131 auto const dupIter = std::ranges::adjacent_find(
1132 signers,
1133 [](STObject const& a, STObject const& b) { return (a[sfAccount] == b[sfAccount]); });
1134
1135 if (dupIter != signers.end())
1136 {
1138 err << "Duplicate Signers:Signer:Account entries (" << toBase58((*dupIter)[sfAccount])
1139 << ") are not allowed.";
1140 return rpc::makeParamError(err.str());
1141 }
1142
1143 // An account may not sign for itself.
1144 if (signers.end() != std::ranges::find_if(signers, [&signingForID](STObject const& elem) {
1145 return elem[sfAccount] == signingForID;
1146 }))
1147 {
1149 err << "A Signer may not be the transaction's Account (" << toBase58(signingForID) << ").";
1150 return rpc::makeParamError(err.str());
1151 }
1152 return {};
1153}
1154
1155} // namespace detail
1156
1162 json::Value jvRequest,
1163 unsigned apiVersion,
1164 NetworkOPs::FailHard failType,
1165 Role role,
1166 std::chrono::seconds validatedLedgerAge,
1167 Application& app)
1168{
1169 auto const& ledger = app.getOpenLedger().current();
1170 auto j = app.getJournal("RPCHandler");
1171 JLOG(j.debug()) << "transactionSignFor: " << jvRequest;
1172
1173 // Verify presence of the signer's account field.
1174 char const accountField[] = "account";
1175
1176 if (!jvRequest.isMember(accountField))
1177 return rpc::missingFieldError(accountField);
1178
1179 // Turn the signer's account into an AccountID for multi-sign.
1180 auto const signerAccountID = parseBase58<AccountID>(jvRequest[accountField].asString());
1181 if (!signerAccountID)
1182 {
1184 }
1185
1186 if (!jvRequest.isMember(jss::tx_json))
1187 return rpc::missingFieldError(jss::tx_json);
1188
1189 {
1190 json::Value& txJson(jvRequest[jss::tx_json]);
1191
1192 if (!txJson.isObject())
1193 return rpc::objectFieldError(jss::tx_json);
1194
1195 if (auto checkResult =
1197 !checkResult)
1198 {
1199 return std::move(checkResult).error();
1200 }
1201
1202 // If the tx_json.SigningPubKey field is missing, insert an empty one,
1203 // in order for the `checkMultiSignFields` to not return an error
1204 // for non-multisign transactions.
1205 if (!txJson.isMember(sfSigningPubKey.getJsonName()))
1206 txJson[sfSigningPubKey.getJsonName()] = "";
1207 }
1208
1209 // When multi-signing, the "Sequence" and "SigningPubKey" fields must
1210 // be passed in by the caller.
1211 using namespace detail;
1212 {
1213 json::Value err = checkMultiSignFields(jvRequest);
1214 if (rpc::containsError(err))
1215 return err;
1216 }
1217
1218 // Add and amend fields based on the transaction type.
1219 SigningForParams signForParams(*signerAccountID);
1220
1221 TransactionPreProcessResult const preprocResult =
1222 transactionPreProcessImpl(jvRequest, role, signForParams, validatedLedgerAge, app);
1223
1224 if (!preprocResult.second)
1225 return preprocResult.first;
1226
1227 XRPL_ASSERT(
1228 signForParams.validMultiSign(), "xrpl::rpc::transactionSignFor : valid multi-signature");
1229
1230 {
1231 SLE::const_pointer const accountState = ledger->read(keylet::account(*signerAccountID));
1232 // Make sure the account and secret belong together.
1233 auto const err =
1234 acctMatchesPubKey(accountState, *signerAccountID, signForParams.getPublicKey());
1235
1236 if (err != RpcSuccess)
1237 return rpcError(err);
1238 }
1239
1240 // Inject the newly generated signature into tx_json.Signers.
1241 auto& sttx = preprocResult.second;
1242 {
1243 // Make the signer object that we'll inject.
1244 STObject signer = STObject::makeInnerObject(sfSigner);
1245 signer[sfAccount] = *signerAccountID;
1246 signer.setFieldVL(sfTxnSignature, signForParams.getSignature());
1247 signer.setFieldVL(sfSigningPubKey, signForParams.getPublicKey().slice());
1248
1249 STObject& sigTarget = [&]() -> STObject& {
1250 auto const target = signForParams.getSignatureTarget();
1251 if (target)
1252 return sttx->peekFieldObject(*target);
1253 return *sttx;
1254 }();
1255 // If there is not yet a Signers array, make one.
1256 if (!sigTarget.isFieldPresent(sfSigners))
1257 sigTarget.setFieldArray(sfSigners, {});
1258
1259 auto& signers = sigTarget.peekFieldArray(sfSigners);
1260 signers.emplaceBack(std::move(signer));
1261
1262 // The array must be sorted and validated.
1263 // For delegated transactions, the delegate account is
1264 // the one forbidden from appearing in its own Signers array.
1265 auto err = sortAndValidateSigners(signers, sttx->getInitiator());
1266 if (rpc::containsError(err))
1267 return err;
1268 }
1269
1270 // Make sure the STTx makes a legitimate Transaction.
1272 transactionConstructImpl(sttx, ledger->rules(), app);
1273
1274 if (!txn.second)
1275 return txn.first;
1276
1277 return transactionFormatResultImpl(txn.second, apiVersion);
1278}
1279
1285 json::Value jvRequest,
1286 unsigned apiVersion,
1287 NetworkOPs::FailHard failType,
1288 Role role,
1289 std::chrono::seconds validatedLedgerAge,
1290 Application& app,
1291 ProcessTransactionFn const& processTransaction)
1292{
1293 auto const& ledger = app.getOpenLedger().current();
1294 auto j = app.getJournal("RPCHandler");
1295 JLOG(j.debug()) << "transactionSubmitMultiSigned: " << jvRequest;
1296
1297 // When multi-signing, the "Sequence" and "SigningPubKey" fields must
1298 // be passed in by the caller.
1299 using namespace detail;
1300 {
1301 json::Value err = checkMultiSignFields(jvRequest);
1302 if (rpc::containsError(err))
1303 return err;
1304 }
1305
1306 json::Value& txJson(jvRequest["tx_json"]);
1307
1308 auto [txJsonResult, srcAddressID] = checkTxJsonFields(
1309 txJson,
1310 role,
1311 true,
1312 validatedLedgerAge,
1313 app.config(),
1314 app.getFeeTrack(),
1315 getAPIVersionNumber(jvRequest, app.config().betaRpcApi));
1316
1317 if (rpc::containsError(txJsonResult))
1318 return std::move(txJsonResult);
1319
1320 SLE::const_pointer const sle = ledger->read(keylet::account(srcAddressID));
1321
1322 if (!sle)
1323 {
1324 // If did not find account, error.
1325 JLOG(j.debug()) << "transactionSubmitMultiSigned: Failed to find source account "
1326 << "in current ledger: " << toBase58(srcAddressID);
1327
1329 }
1330
1331 {
1332 json::Value err =
1333 checkFee(jvRequest, role, false, app.config(), app.getFeeTrack(), app.getTxQ(), app);
1334
1335 if (rpc::containsError(err))
1336 return err;
1337
1338 err = checkPayment(jvRequest, txJson, srcAddressID, role, app, false);
1339
1340 if (rpc::containsError(err))
1341 return err;
1342 }
1343
1344 // Grind through the JSON in tx_json to produce a STTx.
1346 {
1347 STParsedJSONObject parsedTxJson("tx_json", txJson);
1348 if (!parsedTxJson.object)
1349 {
1350 json::Value jvResult;
1351 jvResult["error"] = parsedTxJson.error["error"];
1352 jvResult["error_code"] = parsedTxJson.error["error_code"];
1353 jvResult["error_message"] = parsedTxJson.error["error_message"];
1354 return jvResult;
1355 }
1356 try
1357 {
1358 stTx = std::make_shared<STTx>(std::move(parsedTxJson.object.value()));
1359 }
1360 catch (STObject::FieldErr const& err)
1361 {
1362 return rpc::makeError(RpcInvalidParams, err.what());
1363 }
1364 catch (std::exception& ex)
1365 {
1366 std::string const reason(ex.what());
1367 return rpc::makeError(
1368 RpcInternal, "Exception while serializing transaction: " + reason);
1369 }
1370 std::string reason;
1371 if (!passesLocalChecks(*stTx, reason))
1372 return rpc::makeError(RpcInvalidParams, reason);
1373 }
1374
1375 // Validate the fields in the serialized transaction.
1376 {
1377 // We now have the transaction text serialized and in the right format.
1378 // Verify the values of select fields.
1379 //
1380 // The SigningPubKey must be present but empty.
1381 if (!stTx->getFieldVL(sfSigningPubKey).empty())
1382 {
1384 err << "Invalid " << sfSigningPubKey.fieldName
1385 << " field. Field must be empty when multi-signing.";
1386 return rpc::makeError(RpcInvalidParams, err.str());
1387 }
1388
1389 // There may not be a TxnSignature field.
1390 if (stTx->isFieldPresent(sfTxnSignature))
1392
1393 // The Fee field must be in XRP and greater than zero.
1394 auto const fee = stTx->getFieldAmount(sfFee);
1395
1396 if (!isLegalNet(fee))
1397 {
1399 err << "Invalid " << sfFee.fieldName << " field. Fees must be specified in XRP.";
1400 return rpc::makeError(RpcInvalidParams, err.str());
1401 }
1402 if (fee <= STAmount{0})
1403 {
1405 err << "Invalid " << sfFee.fieldName << " field. Fees must be greater than zero.";
1406 return rpc::makeError(RpcInvalidParams, err.str());
1407 }
1408 }
1409
1410 // Verify that the Signers field is present.
1411 if (!stTx->isFieldPresent(sfSigners))
1412 return rpc::missingFieldError("tx_json.Signers");
1413
1414 // If the Signers field is present the SField guarantees it to be an array.
1415 // Get a reference to the Signers array so we can verify and sort it.
1416 auto& signers = stTx->peekFieldArray(sfSigners);
1417
1418 if (signers.empty())
1419 return rpc::makeParamError("tx_json.Signers array may not be empty.");
1420
1421 // The Signers array may only contain Signer objects.
1422 if (std::ranges::find_if_not(signers, [](STObject const& obj) {
1423 return (
1424 // A Signer object always contains these fields and no
1425 // others.
1426 obj.isFieldPresent(sfAccount) && obj.isFieldPresent(sfSigningPubKey) &&
1427 obj.isFieldPresent(sfTxnSignature) && obj.getCount() == 3);
1428 }) != signers.end())
1429 {
1430 return rpc::makeParamError("Signers array may only contain Signer entries.");
1431 }
1432
1433 // The array must be sorted and validated.
1434 // For delegated transactions, getInitiator() returns sfDelegate,
1435 // that account is the one forbidden from appearing in its own Signers array.
1436 auto err = sortAndValidateSigners(signers, stTx->getInitiator());
1437 if (rpc::containsError(err))
1438 return err;
1439
1440 // Make sure the SerializedTransaction makes a legitimate Transaction.
1442 transactionConstructImpl(stTx, ledger->rules(), app);
1443
1444 if (!txn.second)
1445 return txn.first;
1446
1447 // Finally, submit the transaction.
1448 try
1449 {
1450 // FIXME: For performance, should use async interface
1451 processTransaction(txn.second, isUnlimited(role), true, failType);
1452 }
1453 catch (std::exception&)
1454 {
1455 return rpc::makeError(RpcInternal, "Exception occurred during transaction submission.");
1456 }
1457
1458 return transactionFormatResultImpl(txn.second, apiVersion);
1459}
1460
1461} // namespace xrpl::rpc
T adjacent_find(T... args)
Represents a JSON value.
Definition json_value.h:117
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:117
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Definition base_uint.h:525
Like std::vector<char> but better.
Definition Buffer.h:19
bool standalone() const
SOTemplate const * findSOTemplateBySField(SField const &sField) const
static InnerObjectFormats const & getInstance()
A currency issued by an account.
Definition Issue.h:18
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:37
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:53
Slice slice() const noexcept
Definition PublicKey.h:115
Rules controlling protocol behavior.
Definition Rules.h:40
static SField const & getField(int fieldCode)
Definition SField.cpp:116
constexpr bool holds() const noexcept
Definition STAmount.h:478
constexpr TIss const & get() const
bool native() const noexcept
Definition STAmount.h:471
Asset const & asset() const
Definition STAmount.h:496
AccountID const & getIssuer() const
Definition STAmount.h:516
std::shared_ptr< STLedgerEntry const > const_pointer
void setFieldVL(SField const &field, Blob const &)
Definition STObject.cpp:791
STArray & peekFieldArray(SField const &field)
Definition STObject.cpp:481
void setFieldArray(SField const &field, STArray const &v)
Definition STObject.cpp:833
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:464
int getCount() const
Definition STObject.h:1019
static STObject makeInnerObject(SField const &name)
Definition STObject.cpp:79
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:543
static constexpr std::size_t kMaxMultiSigners
Definition STTx.h:47
A secret key.
Definition SecretKey.h:24
constexpr std::uint32_t value() const
Definition SeqProxy.h:80
Slice slice() const noexcept
Definition Serializer.h:45
Blob getData() const
Definition Serializer.h:182
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:28
std::shared_ptr< Transaction > pointer
Definition Transaction.h:57
Transaction Queue.
Definition TxQ.h:58
Metrics getMetrics(OpenView const &view) const
Returns fee metrics in reference fee level units.
Definition TxQ.cpp:1750
SeqProxy nextQueuableSeq(SLE::const_ref sleAccount) const
Return the next sequence that would go in the TxQ for an account.
Definition TxQ.cpp:1590
json::Value jsonClipped() const
Definition XRPAmount.h:210
std::optional< std::reference_wrapper< SField const > > const & getSignatureTarget() const
SigningForParams(AccountID const &multiSigningAcctID)
PublicKey const & getPublicKey() const
SigningForParams(SigningForParams const &rhs)=delete
void moveMultiSignature(Buffer &&multiSignature)
std::optional< std::reference_wrapper< SField const > > signatureTarget_
void setSignatureTarget(std::optional< std::reference_wrapper< SField const > > const &field)
AccountID const *const multiSigningAcctID_
std::optional< PublicKey > multiSignPublicKey_
void setPublicKey(PublicKey const &multiSignPublicKey)
AccountID const & getSigner() const
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.
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:198
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 TransactionPreProcessResult transactionPreProcessImpl(json::Value &params, Role role, SigningForParams &signingArgs, std::chrono::seconds validatedLedgerAge, Application &app)
static ErrorCodeI acctMatchesPubKey(SLE::const_pointer accountState, AccountID const &accountID, PublicKey const &publicKey)
static json::Value transactionFormatResultImpl(Transaction::pointer tpTrans, unsigned apiVersion)
static std::pair< json::Value, Transaction::pointer > transactionConstructImpl(std::shared_ptr< STTx const > const &stTx, Rules const &rules, Application &app)
static std::expected< void, json::Value > checkNetworkID(json::Value const &txJson, uint32_t appNetworkId)
static json::Value checkMultiSignFields(json::Value const &jvRequest)
static json::Value checkPayment(json::Value const &params, json::Value &txJson, AccountID const &srcAddressID, Role const role, Application &app, bool doPath)
static json::Value sortAndValidateSigners(STArray &signers, AccountID const &signingForID)
static constexpr int kDefaultAutoFillFeeMultiplier
static constexpr int kDefaultAutoFillFeeDivisor
API version numbers used in later API versions.
Definition ApiVersion.h:36
bool containsError(json::Value const &json)
Returns true if the json contains an rpc error specification.
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)
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.
std::function< void( std::shared_ptr< Transaction > &transaction, bool bUnlimited, bool bLocal, NetworkOPs::FailHard failType)> ProcessTransactionFn
void insertDeliverMax(json::Value &txJson, TxType txnType, unsigned int apiVersion)
Copy Amount field to DeliverMax field in transaction output JSON.
Definition DeliverMax.cpp:9
static XRPAmount getTxFee(Application const &app, Config const &config, json::Value tx)
std::string invalidFieldMessage(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:231
unsigned int getAPIVersionNumber(json::Value const &jv, bool betaEnabled)
Retrieve the api version number from the json value.
Definition ApiVersion.h:100
json::Value invalidFieldError(std::string const &name)
Definition ErrorCodes.h:285
std::string expectedFieldMessage(std::string const &name, std::string const &type)
Definition ErrorCodes.h:297
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 missingFieldMessage(std::string const &name)
Definition ErrorCodes.h:237
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 transactionSign(json::Value jvRequest, unsigned apiVersion, NetworkOPs::FailHard failType, Role role, std::chrono::seconds validatedLedgerAge, Application &app)
Returns a json::ValueType::Object.
json::Value missingFieldError(std::string const &name)
Definition ErrorCodes.h:243
json::Value makeError(ErrorCodeI code)
Returns a new json object that reflects the error code.
json::Value objectFieldError(std::string const &name)
Definition ErrorCodes.h:261
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.
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.
ErrorCodeI
Definition ErrorCodes.h:23
@ RpcBadSecret
Definition ErrorCodes.h:81
@ RpcInternal
Definition ErrorCodes.h:113
@ RpcDelegateActNotFound
Definition ErrorCodes.h:106
@ RpcSrcActMalformed
Definition ErrorCodes.h:103
@ RpcAlreadySingleSig
Definition ErrorCodes.h:75
@ RpcSigningMalformed
Definition ErrorCodes.h:101
@ RpcSuccess
Definition ErrorCodes.h:27
@ RpcNotSynced
Definition ErrorCodes.h:50
@ RpcHighFee
Definition ErrorCodes.h:41
@ RpcMasterDisabled
Definition ErrorCodes.h:57
@ RpcDomainMalformed
Definition ErrorCodes.h:141
@ RpcSrcActMissing
Definition ErrorCodes.h:104
@ RpcInvalidParams
Definition ErrorCodes.h:67
@ RpcTooBusy
Definition ErrorCodes.h:39
@ RpcAlreadyMultisig
Definition ErrorCodes.h:74
@ RpcNoCurrent
Definition ErrorCodes.h:48
@ RpcSrcActNotFound
Definition ErrorCodes.h:105
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:36
@ SigGoodOnly
Signature is good, but local checks fail.
Definition apply.h:32
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:13
std::pair< Validity, std::string > checkValidity(HashRouter &router, STTx const &tx, Rules const &rules)
Checks transaction signature and local checks.
Definition apply.cpp:36
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:616
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:95
XRPAmount toDrops(FeeLevel< T > const &level, XRPAmount baseFee)
Definition TxQ.h:1003
bool transResultInfo(TER code, std::string &token, std::string &text)
Definition TER.cpp:236
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:651
void logicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
bool passesLocalChecks(STTx const &tx, std::string &)
Definition STTx.cpp:847
Slice makeSlice(std::array< T, N > const &a)
Definition Slice.h:228
json::Value rpcError(ErrorCodeI iError)
Definition RPCErr.cpp:13
Role
Indicates the level of administrative permission to grant.
Definition Role.h:27
bool amountFromJsonNoThrow(STAmount &result, json::Value const &jvSource)
FeeLevel< std::uint64_t > FeeLevel64
Definition Units.h:443
AccountID calcAccountID(PublicKey const &pk)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
@ temUNCERTAIN
Definition TER.h:111
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:95
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:11
BaseUInt< 256 > uint256
Definition base_uint.h:580
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:52
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.
TransactionPreProcessResult & operator=(TransactionPreProcessResult const &)=delete
TransactionPreProcessResult(std::shared_ptr< STTx > &&st)
TransactionPreProcessResult(TransactionPreProcessResult const &)=delete
TransactionPreProcessResult & operator=(TransactionPreProcessResult &&)=delete
TransactionPreProcessResult(TransactionPreProcessResult &&rhs)=default
T unexpected(T... args)
T what(T... args)