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 const 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 const 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 Rules const& rules)
465{
466 auto const j = app.getJournal("RPCHandler");
467
468 json::Value jvResult;
470 if (!keyPair || containsError(jvResult))
471 return jvResult;
472
473 PublicKey const& pk = keyPair->first;
474 SecretKey const& sk = keyPair->second;
475
476 bool const verify = !(params.isMember(jss::offline) && params[jss::offline].asBool());
477
478 auto const signatureTarget = [&params] -> std::optional<std::reference_wrapper<SField const>> {
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. Only a field that holds a transaction signature
486 // is a valid target; the signature is bound to that field's role.
487 auto const signatureTemplate = signatureTarget
489 : nullptr;
490 auto const signatureRoleOpt =
491 signatureTarget ? signatureRole(signatureTarget->get()) : SignatureRole::Transaction;
492 if (signatureTarget)
493 {
494 if (!signatureRoleOpt || signatureTemplate == nullptr)
495 { // Invalid target field
496 return rpc::makeError(RpcInvalidParams, signatureTarget->get().getName());
497 }
498 signingArgs.setSignatureTarget(signatureTarget);
499 }
500
501 if (!params.isMember(jss::tx_json))
502 return rpc::missingFieldError(jss::tx_json);
503
504 json::Value& txJson(params[jss::tx_json]);
505
506 // Check tx_json fields, but don't add any.
507 auto [txJsonResult, srcAddressID] = checkTxJsonFields(
508 txJson,
509 role,
510 verify,
511 validatedLedgerAge,
512 app.config(),
513 app.getFeeTrack(),
514 getAPIVersionNumber(params, app.config().betaRpcApi));
515
516 if (rpc::containsError(txJsonResult))
517 return std::move(txJsonResult);
518
519 // This test covers the case where we're offline so the sequence number
520 // cannot be determined locally. If we're offline then the caller must
521 // provide the sequence number.
522 if (!verify && !txJson.isMember(jss::Sequence))
523 return rpc::missingFieldError("tx_json.Sequence");
524
526 if (verify)
527 sle = app.getOpenLedger().current()->read(keylet::account(srcAddressID));
528
529 if (verify && !sle)
530 {
531 // If not offline and did not find account, error.
532 JLOG(j.debug()) << "transactionSign: Failed to find source account "
533 << "in current ledger: " << toBase58(srcAddressID);
534
536 }
537
538 if (signingArgs.editFields())
539 {
540 if (!txJson.isMember(jss::Sequence))
541 {
542 bool const hasTicketSeq = txJson.isMember(sfTicketSequence.jsonName);
543 if (!hasTicketSeq && !sle)
544 {
545 JLOG(j.debug()) << "transactionSign: Failed to find source account "
546 << "in current ledger: " << toBase58(srcAddressID);
547
549 }
550 txJson[jss::Sequence] = hasTicketSeq ? 0 : app.getTxQ().nextQueuableSeq(sle).value();
551 }
552
553 if (!txJson.isMember(jss::NetworkID))
554 {
555 auto const networkId = app.getNetworkIDService().getNetworkID();
556 if (networkId > 1024)
557 txJson[jss::NetworkID] = to_string(networkId);
558 }
559 }
560
561 {
562 json::Value err = checkFee(
563 params,
564 role,
565 verify && signingArgs.editFields(),
566 app.config(),
567 app.getFeeTrack(),
568 app.getTxQ(),
569 app);
570
571 if (rpc::containsError(err))
572 return err;
573 }
574
575 {
577 params, txJson, srcAddressID, role, app, verify && signingArgs.editFields());
578
579 if (rpc::containsError(err))
580 return err;
581 }
582
583 // If multisigning there should not be a single signature and vice versa.
584 if (signingArgs.isMultiSigning())
585 {
586 if (txJson.isMember(jss::TxnSignature))
588
589 // If multisigning then we need to return the public key.
590 signingArgs.setPublicKey(pk);
591 }
592 else if (signingArgs.isSingleSigning())
593 {
594 if (txJson.isMember(jss::Signers))
596 }
597
598 if (verify)
599 {
600 // sle validity is checked above
601 JLOG(j.trace()) << "verify: " << toBase58(calcAccountID(pk)) << " : "
602 << toBase58(srcAddressID);
603
604 // Don't do this test if multisigning or if the signature is going into
605 // an alternate field since the account and secret probably don't belong
606 // together in that case.
607 if (!signingArgs.isMultiSigning() && !signatureTarget)
608 {
609 // Make sure the account and secret belong together.
610 if (txJson.isMember(sfDelegate.jsonName))
611 {
612 // Delegated transaction
613 auto const delegateJson = txJson[sfDelegate.jsonName];
614 auto const ptrDelegatedAddressID = delegateJson.isString()
615 ? parseBase58<AccountID>(delegateJson.asString())
616 : std::nullopt;
617
618 if (!ptrDelegatedAddressID)
619 {
620 return rpc::makeError(
621 RpcSrcActMalformed, rpc::invalidFieldMessage("tx_json.Delegate"));
622 }
623
624 auto const delegatedAddressID = *ptrDelegatedAddressID;
625 auto const delegatedSle =
626 app.getOpenLedger().current()->read(keylet::account(delegatedAddressID));
627 if (!delegatedSle)
629
630 auto const err = acctMatchesPubKey(delegatedSle, delegatedAddressID, pk);
631
632 if (err != RpcSuccess)
633 return rpcError(err);
634 }
635 else
636 {
637 auto const err = acctMatchesPubKey(sle, srcAddressID, pk);
638
639 if (err != RpcSuccess)
640 return rpcError(err);
641 }
642 }
643 }
644
645 STParsedJSONObject parsed(std::string(jss::tx_json), txJson);
646 if (!parsed.object.has_value())
647 {
648 json::Value err;
649 err[jss::error] = parsed.error[jss::error];
650 err[jss::error_code] = parsed.error[jss::error_code];
651 err[jss::error_message] = parsed.error[jss::error_message];
652 return err;
653 }
654
656 try
657 {
658 // If we're generating a multi-signature the SigningPubKey must be
659 // empty, otherwise it must be the master account's public key.
660 STObject* sigObject = &*parsed.object;
661 if (signatureTarget)
662 {
663 // If the target object doesn't exist, make one.
664 if (!parsed.object->isFieldPresent(*signatureTarget))
665 {
666 parsed.object->setFieldObject(
667 *signatureTarget, STObject{*signatureTemplate, *signatureTarget});
668 }
669 sigObject = &parsed.object->peekFieldObject(*signatureTarget);
670 }
671 sigObject->setFieldVL(
672 sfSigningPubKey, signingArgs.isMultiSigning() ? Slice(nullptr, 0) : pk.slice());
673
674 stTx = std::make_shared<STTx>(std::move(parsed.object.value()));
675 }
676 catch (STObject::FieldErr const& err)
677 {
678 return rpc::makeError(RpcInvalidParams, err.what());
679 }
680 catch (std::exception&)
681 {
682 return rpc::makeError(
683 RpcInternal, "Exception occurred constructing serialized transaction");
684 }
685
686 std::string reason;
687 if (!passesLocalChecks(*stTx, reason))
688 return rpc::makeError(RpcInvalidParams, reason);
689
690 // If multisign then return multiSignature, else set TxnSignature field.
691 if (signingArgs.isMultiSigning())
692 {
694 *stTx, signingArgs.getSigner(), signingPrefix(*signatureRoleOpt, true, rules));
695
696 auto multisig = xrpl::sign(pk, sk, s.slice());
697
698 signingArgs.moveMultiSignature(std::move(multisig));
699 }
700 else if (signingArgs.isSingleSigning())
701 {
702 stTx->sign(pk, sk, *signatureRoleOpt, rules);
703 }
704
705 return TransactionPreProcessResult{std::move(stTx)};
706}
707
710 std::shared_ptr<STTx const> const& stTx,
711 Rules const& rules,
712 Application& app)
713{
715
716 // Turn the passed in STTx into a Transaction.
717 Transaction::pointer tpTrans;
718 {
719 std::string reason;
720 tpTrans = std::make_shared<Transaction>(stTx, reason, app);
721 if (tpTrans->getStatus() != TransStatus::NEW)
722 {
723 ret.first = rpc::makeError(RpcInternal, "Unable to construct transaction: " + reason);
724 return ret;
725 }
726 }
727 try
728 {
729 // Make sure the Transaction we just built is legit by serializing it
730 // and then de-serializing it. If the result isn't equivalent
731 // to the initial transaction then there's something wrong with the
732 // passed-in STTx.
733 {
734 Serializer s;
735 tpTrans->getSTransaction()->add(s);
736 Blob const transBlob = s.getData();
737 SerialIter sit{makeSlice(transBlob)};
738
739 // Check the signature if that's called for.
740 auto const sttxNew = std::make_shared<STTx const>(sit);
741 if (!app.checkSigs())
742 {
744 app.getHashRouter(), sttxNew->getTransactionID(), Validity::SigGoodOnly);
745 }
746 if (checkValidity(app.getHashRouter(), *sttxNew, rules).first != Validity::Valid)
747 {
748 ret.first = rpc::makeError(RpcInternal, "Invalid signature.");
749 return ret;
750 }
751
752 std::string reason;
753 auto tpTransNew = std::make_shared<Transaction>(sttxNew, reason, app);
754
755 if (tpTransNew)
756 {
757 if (!tpTransNew->getSTransaction()->isEquivalent(*tpTrans->getSTransaction()))
758 {
759 tpTransNew.reset();
760 }
761 tpTrans = std::move(tpTransNew);
762 }
763 }
764 }
765 catch (std::exception&)
766 {
767 // Assume that any exceptions are related to transaction sterilization.
768 tpTrans.reset();
769 }
770
771 if (!tpTrans)
772 {
773 ret.first = rpc::makeError(RpcInternal, "Unable to sterilize transaction.");
774 return ret;
775 }
776 ret.second = std::move(tpTrans);
777 return ret;
778}
779
780static json::Value
782{
783 json::Value jvResult;
784 try
785 {
786 if (apiVersion > 1)
787 {
788 jvResult[jss::tx_json] = tpTrans->getJson(JsonOptions::Values::DisableApiPriorV2);
789 jvResult[jss::hash] = to_string(tpTrans->getID());
790 }
791 else
792 {
793 jvResult[jss::tx_json] = tpTrans->getJson(JsonOptions::Values::None);
794 }
795
797 jvResult[jss::tx_json], tpTrans->getSTransaction()->getTxnType(), apiVersion);
798
799 jvResult[jss::tx_blob] = strHex(tpTrans->getSTransaction()->getSerializer().peekData());
800
801 if (temUNCERTAIN != tpTrans->getResult())
802 {
803 std::string sToken;
804 std::string sHuman;
805
806 transResultInfo(tpTrans->getResult(), sToken, sHuman);
807
808 jvResult[jss::engine_result] = sToken;
809 jvResult[jss::engine_result_code] = tpTrans->getResult();
810 jvResult[jss::engine_result_message] = sHuman;
811 }
812 }
813 catch (std::exception&)
814 {
815 jvResult = rpc::makeError(RpcInternal, "Exception occurred during JSON handling.");
816 }
817 return jvResult;
818}
819
820} // namespace detail
821
822//------------------------------------------------------------------------------
823
824[[nodiscard]] static XRPAmount
825getTxFee(Application const& app, Config const& config, json::Value tx)
826{
827 auto const& ledger = app.getOpenLedger().current();
828 // autofilling only needed in this function so that the `STParsedJSONObject`
829 // parsing works properly it should not be modifying the actual `tx` object
830 if (!tx.isMember(jss::Fee))
831 {
832 tx[jss::Fee] = "0";
833 }
834
835 if (!tx.isMember(jss::Sequence))
836 {
837 tx[jss::Sequence] = "0";
838 }
839
840 if (!tx.isMember(jss::SigningPubKey))
841 {
842 tx[jss::SigningPubKey] = "";
843 }
844
845 if (!tx.isMember(jss::TxnSignature))
846 {
847 tx[jss::TxnSignature] = "";
848 }
849
850 if (tx.isMember(jss::Signers))
851 {
852 if (!tx[jss::Signers].isArray())
853 return config.fees.referenceFee;
854
855 if (tx[jss::Signers].size() > STTx::kMaxMultiSigners)
856 return config.fees.referenceFee;
857
858 // check multi-signed signers
859 for (auto& signer : tx[jss::Signers])
860 {
861 if (!signer.isMember(jss::Signer) || !signer[jss::Signer].isObject())
862 return config.fees.referenceFee;
863 if (!signer[jss::Signer].isMember(jss::SigningPubKey))
864 {
865 // autofill SigningPubKey
866 signer[jss::Signer][jss::SigningPubKey] = "";
867 }
868 if (!signer[jss::Signer].isMember(jss::TxnSignature))
869 {
870 // autofill TxnSignature
871 signer[jss::Signer][jss::TxnSignature] = "";
872 }
873 }
874 }
875
876 STParsedJSONObject parsed(std::string(jss::tx_json), tx);
877 if (!parsed.object.has_value())
878 {
879 return config.fees.referenceFee;
880 }
881
882 try
883 {
884 STTx const& stTx = STTx(std::move(parsed.object.value()));
885 std::string reason;
886 if (!passesLocalChecks(stTx, reason))
887 return config.fees.referenceFee;
888
889 // This fee is only a suggestion returned to the caller, so fall back to
890 // the reference fee as the other failure paths in this function do.
891 return calculateBaseFee(*app.getOpenLedger().current(), stTx)
892 .value_or(config.fees.referenceFee);
893 }
894 catch (std::exception& e)
895 {
896 return config.fees.referenceFee;
897 }
898}
899
902 Role const role,
903 Config const& config,
904 LoadFeeTrack const& feeTrack,
905 TxQ const& txQ,
906 Application const& app,
907 json::Value const& tx,
908 int mult,
909 int div)
910{
911 XRPAmount const feeDefault = getTxFee(app, config, tx);
912
913 auto const ledger = app.getOpenLedger().current();
914 // Administrative and identified endpoints are exempt from local fees.
915 XRPAmount const loadFee = scaleFeeLoad(feeDefault, feeTrack, ledger->fees(), isUnlimited(role));
916 XRPAmount fee = loadFee;
917 {
918 auto const metrics = txQ.getMetrics(*ledger);
919 auto const baseFee = ledger->fees().base;
920 auto const escalatedFee = toDrops(metrics.openLedgerFeeLevel - FeeLevel64(1), baseFee) + 1;
921 fee = std::max(fee, escalatedFee);
922 }
923
924 auto const limit = mulDiv(feeDefault, mult, div);
925 if (!limit)
927
928 if (fee > *limit)
929 {
931 ss << "Fee of " << fee << " exceeds the requested tx limit of " << *limit;
932 return rpc::makeError(RpcHighFee, ss.str());
933 }
934
935 return fee.jsonClipped();
936}
937
940 json::Value& request,
941 Role const role,
942 bool doAutoFill,
943 Config const& config,
944 LoadFeeTrack const& feeTrack,
945 TxQ const& txQ,
946 Application const& app)
947{
948 json::Value& tx(request[jss::tx_json]);
949 if (tx.isMember(jss::Fee))
950 return json::Value();
951
952 if (!doAutoFill)
953 return rpc::missingFieldError("tx_json.Fee");
954
957 if (request.isMember(jss::fee_mult_max))
958 {
959 if (request[jss::fee_mult_max].isInt())
960 {
961 mult = request[jss::fee_mult_max].asInt();
962 if (mult < 0)
963 {
964 return rpc::makeError(
966 rpc::expectedFieldMessage(jss::fee_mult_max, "a positive integer"));
967 }
968 }
969 else
970 {
971 return rpc::makeError(
972 RpcHighFee, rpc::expectedFieldMessage(jss::fee_mult_max, "a positive integer"));
973 }
974 }
975 if (request.isMember(jss::fee_div_max))
976 {
977 if (request[jss::fee_div_max].isInt())
978 {
979 div = request[jss::fee_div_max].asInt();
980 if (div <= 0)
981 {
982 return rpc::makeError(
984 rpc::expectedFieldMessage(jss::fee_div_max, "a positive integer"));
985 }
986 }
987 else
988 {
989 return rpc::makeError(
990 RpcHighFee, rpc::expectedFieldMessage(jss::fee_div_max, "a positive integer"));
991 }
992 }
993
994 auto feeOrError = getCurrentNetworkFee(role, config, feeTrack, txQ, app, tx, mult, div);
995 if (feeOrError.isMember(jss::error))
996 return feeOrError;
997 tx[jss::Fee] = std::move(feeOrError);
998 return json::Value();
999}
1000
1001//------------------------------------------------------------------------------
1002
1008 json::Value jvRequest,
1009 unsigned apiVersion,
1010 NetworkOPs::FailHard failType,
1011 Role role,
1012 std::chrono::seconds validatedLedgerAge,
1013 Application& app)
1014{
1015 using namespace detail;
1016
1017 // Sign and verify against the same ruleset: a ledger close in between
1018 // could change the signing prefix of an alternate signature field.
1020 auto const j = app.getJournal("RPCHandler");
1021 JLOG(j.debug()) << "transactionSign: " << jvRequest;
1022
1023 // Add and amend fields based on the transaction type.
1024 SigningForParams signForParams;
1025 TransactionPreProcessResult const preprocResult = transactionPreProcessImpl(
1026 jvRequest, role, signForParams, validatedLedgerAge, app, ledger->rules());
1027
1028 if (!preprocResult.second)
1029 return preprocResult.first;
1030
1031 // Make sure the STTx makes a legitimate Transaction.
1033 transactionConstructImpl(preprocResult.second, ledger->rules(), app);
1034
1035 if (!txn.second)
1036 return txn.first;
1037
1038 return transactionFormatResultImpl(txn.second, apiVersion);
1039}
1040
1046 json::Value jvRequest,
1047 unsigned apiVersion,
1048 NetworkOPs::FailHard failType,
1049 Role role,
1050 std::chrono::seconds validatedLedgerAge,
1051 Application& app,
1052 ProcessTransactionFn const& processTransaction)
1053{
1054 using namespace detail;
1055
1056 auto const& ledger = app.getOpenLedger().current();
1057 auto const j = app.getJournal("RPCHandler");
1058 JLOG(j.debug()) << "transactionSubmit: " << jvRequest;
1059
1060 // Add and amend fields based on the transaction type.
1061 SigningForParams signForParams;
1062 TransactionPreProcessResult const preprocResult = transactionPreProcessImpl(
1063 jvRequest, role, signForParams, validatedLedgerAge, app, ledger->rules());
1064
1065 if (!preprocResult.second)
1066 return preprocResult.first;
1067
1068 // Make sure the STTx makes a legitimate Transaction.
1070 transactionConstructImpl(preprocResult.second, ledger->rules(), app);
1071
1072 if (!txn.second)
1073 return txn.first;
1074
1075 // Finally, submit the transaction.
1076 try
1077 {
1078 // FIXME: For performance, should use async interface
1079 processTransaction(txn.second, isUnlimited(role), true, failType);
1080 }
1081 catch (std::exception&)
1082 {
1083 return rpc::makeError(RpcInternal, "Exception occurred during transaction submission.");
1084 }
1085
1086 return transactionFormatResultImpl(txn.second, apiVersion);
1087}
1088
1089namespace detail {
1090// There are a some field checks shared by transactionSignFor
1091// and transactionSubmitMultiSigned. Gather them together here.
1092static json::Value
1094{
1095 if (!jvRequest.isMember(jss::tx_json))
1096 return rpc::missingFieldError(jss::tx_json);
1097
1098 json::Value const& txJson(jvRequest[jss::tx_json]);
1099
1100 if (!txJson.isObject())
1101 return rpc::invalidFieldMessage(jss::tx_json);
1102
1103 // There are a couple of additional fields we need to check before
1104 // we serialize. If we serialize first then we generate less useful
1105 // error messages.
1106 if (!txJson.isMember(jss::Sequence))
1107 return rpc::missingFieldError("tx_json.Sequence");
1108
1109 if (!txJson.isMember(sfSigningPubKey.getJsonName()))
1110 return rpc::missingFieldError("tx_json.SigningPubKey");
1111
1112 // Multi-signing into a signature_target object field is fine,
1113 // because it means the signature is not for the transaction
1114 // Account.
1115 if (!jvRequest.isMember(jss::signature_target) &&
1116 !txJson[sfSigningPubKey.getJsonName()].asString().empty())
1117 {
1118 return rpc::makeError(
1119 RpcInvalidParams, "When multi-signing 'tx_json.SigningPubKey' must be empty.");
1120 }
1121
1122 return json::Value();
1123}
1124
1125// Sort and validate an stSigners array.
1126//
1127// Returns a null json::Value if there are no errors.
1128static json::Value
1129sortAndValidateSigners(STArray& signers, AccountID const& signingForID)
1130{
1131 if (signers.empty())
1132 return rpc::makeParamError("Signers array may not be empty.");
1133
1134 // Signers must be sorted by Account.
1135 std::ranges::sort(signers, [](STObject const& a, STObject const& b) {
1136 return (a[sfAccount] < b[sfAccount]);
1137 });
1138
1139 // Signers may not contain any duplicates.
1140 auto const dupIter = std::ranges::adjacent_find(
1141 signers,
1142 [](STObject const& a, STObject const& b) { return (a[sfAccount] == b[sfAccount]); });
1143
1144 if (dupIter != signers.end())
1145 {
1147 err << "Duplicate Signers:Signer:Account entries (" << toBase58((*dupIter)[sfAccount])
1148 << ") are not allowed.";
1149 return rpc::makeParamError(err.str());
1150 }
1151
1152 // An account may not sign for itself.
1153 if (signers.end() != std::ranges::find_if(signers, [&signingForID](STObject const& elem) {
1154 return elem[sfAccount] == signingForID;
1155 }))
1156 {
1158 err << "A Signer may not be the transaction's Account (" << toBase58(signingForID) << ").";
1159 return rpc::makeParamError(err.str());
1160 }
1161 return {};
1162}
1163
1164} // namespace detail
1165
1171 json::Value jvRequest,
1172 unsigned apiVersion,
1173 NetworkOPs::FailHard failType,
1174 Role role,
1175 std::chrono::seconds validatedLedgerAge,
1176 Application& app)
1177{
1178 auto const& ledger = app.getOpenLedger().current();
1179 auto const j = app.getJournal("RPCHandler");
1180 JLOG(j.debug()) << "transactionSignFor: " << jvRequest;
1181
1182 // Verify presence of the signer's account field.
1183 char const accountField[] = "account";
1184
1185 if (!jvRequest.isMember(accountField))
1186 return rpc::missingFieldError(accountField);
1187
1188 // Turn the signer's account into an AccountID for multi-sign.
1189 auto const signerAccountID = parseBase58<AccountID>(jvRequest[accountField].asString());
1190 if (!signerAccountID)
1191 {
1193 }
1194
1195 if (!jvRequest.isMember(jss::tx_json))
1196 return rpc::missingFieldError(jss::tx_json);
1197
1198 {
1199 json::Value& txJson(jvRequest[jss::tx_json]);
1200
1201 if (!txJson.isObject())
1202 return rpc::objectFieldError(jss::tx_json);
1203
1204 if (auto checkResult =
1206 !checkResult)
1207 {
1208 return std::move(checkResult).error();
1209 }
1210
1211 // If the tx_json.SigningPubKey field is missing, insert an empty one,
1212 // in order for the `checkMultiSignFields` to not return an error
1213 // for non-multisign transactions.
1214 if (!txJson.isMember(sfSigningPubKey.getJsonName()))
1215 txJson[sfSigningPubKey.getJsonName()] = "";
1216 }
1217
1218 // When multi-signing, the "Sequence" and "SigningPubKey" fields must
1219 // be passed in by the caller.
1220 using namespace detail;
1221 {
1222 json::Value err = checkMultiSignFields(jvRequest);
1223 if (rpc::containsError(err))
1224 return err;
1225 }
1226
1227 // Add and amend fields based on the transaction type.
1228 SigningForParams signForParams(*signerAccountID);
1229
1230 TransactionPreProcessResult const preprocResult = transactionPreProcessImpl(
1231 jvRequest, role, signForParams, validatedLedgerAge, app, ledger->rules());
1232
1233 if (!preprocResult.second)
1234 return preprocResult.first;
1235
1236 XRPL_ASSERT(
1237 signForParams.validMultiSign(), "xrpl::rpc::transactionSignFor : valid multi-signature");
1238
1239 {
1240 SLE::const_pointer const accountState = ledger->read(keylet::account(*signerAccountID));
1241 // Make sure the account and secret belong together.
1242 auto const err =
1243 acctMatchesPubKey(accountState, *signerAccountID, signForParams.getPublicKey());
1244
1245 if (err != RpcSuccess)
1246 return rpcError(err);
1247 }
1248
1249 // Inject the newly generated signature into tx_json.Signers.
1250 auto& sttx = preprocResult.second;
1251 {
1252 // Make the signer object that we'll inject.
1253 STObject signer = STObject::makeInnerObject(sfSigner);
1254 signer[sfAccount] = *signerAccountID;
1255 signer.setFieldVL(sfTxnSignature, signForParams.getSignature());
1256 signer.setFieldVL(sfSigningPubKey, signForParams.getPublicKey().slice());
1257
1258 STObject& sigTarget = [&] -> STObject& {
1259 auto const target = signForParams.getSignatureTarget();
1260 if (target)
1261 return sttx->peekFieldObject(*target);
1262 return *sttx;
1263 }();
1264 // If there is not yet a Signers array, make one.
1265 if (!sigTarget.isFieldPresent(sfSigners))
1266 sigTarget.setFieldArray(sfSigners, {});
1267
1268 auto& signers = sigTarget.peekFieldArray(sfSigners);
1269 signers.emplaceBack(std::move(signer));
1270
1271 // The array must be sorted and validated.
1272 // For delegated transactions, the delegate account is
1273 // the one forbidden from appearing in its own Signers array.
1274 auto err = sortAndValidateSigners(signers, sttx->getInitiator());
1275 if (rpc::containsError(err))
1276 return err;
1277 }
1278
1279 // Make sure the STTx makes a legitimate Transaction.
1281 transactionConstructImpl(sttx, ledger->rules(), app);
1282
1283 if (!txn.second)
1284 return txn.first;
1285
1286 return transactionFormatResultImpl(txn.second, apiVersion);
1287}
1288
1294 json::Value jvRequest,
1295 unsigned apiVersion,
1296 NetworkOPs::FailHard failType,
1297 Role role,
1298 std::chrono::seconds validatedLedgerAge,
1299 Application& app,
1300 ProcessTransactionFn const& processTransaction)
1301{
1302 auto const& ledger = app.getOpenLedger().current();
1303 auto const j = app.getJournal("RPCHandler");
1304 JLOG(j.debug()) << "transactionSubmitMultiSigned: " << jvRequest;
1305
1306 // When multi-signing, the "Sequence" and "SigningPubKey" fields must
1307 // be passed in by the caller.
1308 using namespace detail;
1309 {
1310 json::Value err = checkMultiSignFields(jvRequest);
1311 if (rpc::containsError(err))
1312 return err;
1313 }
1314
1315 json::Value& txJson(jvRequest["tx_json"]);
1316
1317 auto [txJsonResult, srcAddressID] = checkTxJsonFields(
1318 txJson,
1319 role,
1320 true,
1321 validatedLedgerAge,
1322 app.config(),
1323 app.getFeeTrack(),
1324 getAPIVersionNumber(jvRequest, app.config().betaRpcApi));
1325
1326 if (rpc::containsError(txJsonResult))
1327 return std::move(txJsonResult);
1328
1329 SLE::const_pointer const sle = ledger->read(keylet::account(srcAddressID));
1330
1331 if (!sle)
1332 {
1333 // If did not find account, error.
1334 JLOG(j.debug()) << "transactionSubmitMultiSigned: Failed to find source account "
1335 << "in current ledger: " << toBase58(srcAddressID);
1336
1338 }
1339
1340 {
1341 json::Value err =
1342 checkFee(jvRequest, role, false, app.config(), app.getFeeTrack(), app.getTxQ(), app);
1343
1344 if (rpc::containsError(err))
1345 return err;
1346
1347 err = checkPayment(jvRequest, txJson, srcAddressID, role, app, false);
1348
1349 if (rpc::containsError(err))
1350 return err;
1351 }
1352
1353 // Grind through the JSON in tx_json to produce a STTx.
1355 {
1356 STParsedJSONObject parsedTxJson("tx_json", txJson);
1357 if (!parsedTxJson.object)
1358 {
1359 json::Value jvResult;
1360 jvResult["error"] = parsedTxJson.error["error"];
1361 jvResult["error_code"] = parsedTxJson.error["error_code"];
1362 jvResult["error_message"] = parsedTxJson.error["error_message"];
1363 return jvResult;
1364 }
1365 try
1366 {
1367 stTx = std::make_shared<STTx>(std::move(parsedTxJson.object.value()));
1368 }
1369 catch (STObject::FieldErr const& err)
1370 {
1371 return rpc::makeError(RpcInvalidParams, err.what());
1372 }
1373 catch (std::exception& ex)
1374 {
1375 std::string const reason(ex.what());
1376 return rpc::makeError(
1377 RpcInternal, "Exception while serializing transaction: " + reason);
1378 }
1379 std::string reason;
1380 if (!passesLocalChecks(*stTx, reason))
1381 return rpc::makeError(RpcInvalidParams, reason);
1382 }
1383
1384 // Validate the fields in the serialized transaction.
1385 {
1386 // We now have the transaction text serialized and in the right format.
1387 // Verify the values of select fields.
1388 //
1389 // The SigningPubKey must be present but empty.
1390 if (!stTx->getFieldVL(sfSigningPubKey).empty())
1391 {
1393 err << "Invalid " << sfSigningPubKey.fieldName
1394 << " field. Field must be empty when multi-signing.";
1395 return rpc::makeError(RpcInvalidParams, err.str());
1396 }
1397
1398 // There may not be a TxnSignature field.
1399 if (stTx->isFieldPresent(sfTxnSignature))
1401
1402 // The Fee field must be in XRP and greater than zero.
1403 auto const fee = stTx->getFieldAmount(sfFee);
1404
1405 if (!isLegalNet(fee))
1406 {
1408 err << "Invalid " << sfFee.fieldName << " field. Fees must be specified in XRP.";
1409 return rpc::makeError(RpcInvalidParams, err.str());
1410 }
1411 if (fee <= STAmount{0})
1412 {
1414 err << "Invalid " << sfFee.fieldName << " field. Fees must be greater than zero.";
1415 return rpc::makeError(RpcInvalidParams, err.str());
1416 }
1417 }
1418
1419 // Verify that the Signers field is present.
1420 if (!stTx->isFieldPresent(sfSigners))
1421 return rpc::missingFieldError("tx_json.Signers");
1422
1423 // If the Signers field is present the SField guarantees it to be an array.
1424 // Get a reference to the Signers array so we can verify and sort it.
1425 auto& signers = stTx->peekFieldArray(sfSigners);
1426
1427 if (signers.empty())
1428 return rpc::makeParamError("tx_json.Signers array may not be empty.");
1429
1430 // The Signers array may only contain Signer objects.
1431 if (std::ranges::find_if_not(signers, [](STObject const& obj) {
1432 return (
1433 // A Signer object always contains these fields and no
1434 // others.
1435 obj.isFieldPresent(sfAccount) && obj.isFieldPresent(sfSigningPubKey) &&
1436 obj.isFieldPresent(sfTxnSignature) && obj.getCount() == 3);
1437 }) != signers.end())
1438 {
1439 return rpc::makeParamError("Signers array may only contain Signer entries.");
1440 }
1441
1442 // The array must be sorted and validated.
1443 // For delegated transactions, getInitiator() returns sfDelegate,
1444 // that account is the one forbidden from appearing in its own Signers array.
1445 auto err = sortAndValidateSigners(signers, stTx->getInitiator());
1446 if (rpc::containsError(err))
1447 return err;
1448
1449 // Make sure the SerializedTransaction makes a legitimate Transaction.
1451 transactionConstructImpl(stTx, ledger->rules(), app);
1452
1453 if (!txn.second)
1454 return txn.first;
1455
1456 // Finally, submit the transaction.
1457 try
1458 {
1459 // FIXME: For performance, should use async interface
1460 processTransaction(txn.second, isUnlimited(role), true, failType);
1461 }
1462 catch (std::exception&)
1463 {
1464 return rpc::makeError(RpcInternal, "Exception occurred during transaction submission.");
1465 }
1466
1467 return transactionFormatResultImpl(txn.second, apiVersion);
1468}
1469
1470} // namespace xrpl::rpc
T adjacent_find(T... args)
Represents a JSON value.
Definition json_value.h:121
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:526
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
void computePathRanks(int maxPaths, std::function< bool()> const &continueCallback={})
Compute the rankings of the paths.
bool findPaths(int searchLevel, std::function< bool()> const &continueCallback={})
STPathSet getBestPaths(int maxPaths, STPath &fullLiquidityPath, STPathSet const &extraPaths, AccountID const &srcIssuer, std::function< bool()> const &continueCallback={})
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:108
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:1018
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:630
static constexpr std::size_t kMaxMultiSigners
Definition STTx.h:49
A secret key.
Definition SecretKey.h:24
constexpr std::uint32_t value() const
Definition SeqProxy.h:80
Slice slice() const noexcept
Definition Serializer.h:141
Blob getData() const
Definition Serializer.h:278
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:59
Metrics getMetrics(OpenView const &view) const
Returns fee metrics in reference fee level units.
Definition TxQ.cpp:2070
SeqProxy nextQueuableSeq(SLE::ConstRef sleAccount) const
Return the next sequence that would go in the TxQ for an account.
Definition TxQ.cpp:1904
json::Value jsonClipped() const
Definition XRPAmount.h:203
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:233
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 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 TransactionPreProcessResult transactionPreProcessImpl(json::Value &params, Role role, SigningForParams &signingArgs, std::chrono::seconds validatedLedgerAge, Application &app, Rules const &rules)
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
The api_version numbers this server serves.
Definition ApiVersion.h:26
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< SignatureRole > signatureRole(SField const &sigField)
The role that signs into the given field.
std::optional< std::uint64_t > mulDiv(std::uint64_t value, std::uint64_t mul, std::uint64_t div)
Return value*mul/div accurately.
std::expected< XRPAmount, TER > calculateBaseFee(ReadView const &view, STTx const &tx)
Compute only the expected base fee for a transaction.
@ 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.
HashPrefix signingPrefix(SignatureRole role, bool multiSigning, Rules const &rules)
The hash prefix that binds a transaction signature to the role that made it.
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:62
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:1011
bool transResultInfo(TER code, std::string &token, std::string &text)
Definition TER.cpp:244
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
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:850
Slice makeSlice(std::array< T, N > const &a)
Definition Slice.h:228
void forceValidity(HashRouter &router, UInt256 const &txid, Validity validity)
Sets the validity of a given transaction in the cache.
Definition apply.cpp:141
json::Value rpcError(ErrorCodeI iError)
Definition RPCErr.cpp:13
Role
Indicates the level of administrative permission to grant.
Definition Role.h:27
BaseUInt< 256 > UInt256
Definition base_uint.h:581
bool amountFromJsonNoThrow(STAmount &result, json::Value const &jvSource)
@ Transaction
The transaction's own signature, in sfTxnSignature or sfSigners.
Definition Sign.h:27
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.
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
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:52
Serializer buildMultiSigningData(STObject const &obj, AccountID const &signingID, HashPrefix prefix)
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)