20#include <xrpld/app/ledger/OpenLedger.h>
21#include <xrpld/app/main/Application.h>
22#include <xrpld/app/misc/DeliverMax.h>
23#include <xrpld/app/misc/Transaction.h>
24#include <xrpld/app/misc/TxQ.h>
25#include <xrpld/app/paths/Pathfinder.h>
26#include <xrpld/app/tx/apply.h>
27#include <xrpld/app/tx/applySteps.h>
28#include <xrpld/rpc/detail/LegacyPathFind.h>
29#include <xrpld/rpc/detail/RPCHelpers.h>
30#include <xrpld/rpc/detail/TransactionSign.h>
32#include <xrpl/basics/Log.h>
33#include <xrpl/basics/mulDiv.h>
34#include <xrpl/json/json_writer.h>
35#include <xrpl/protocol/ErrorCodes.h>
36#include <xrpl/protocol/RPCErr.h>
37#include <xrpl/protocol/STParsedJSON.h>
38#include <xrpl/protocol/Sign.h>
39#include <xrpl/protocol/TxFlags.h>
100 LogicError(
"Accessing unknown SigningForParams::getSigner()");
108 LogicError(
"Accessing unknown SigningForParams::getPublicKey()");
140 bool const isMasterKey = publicKeyAcctID == accountID;
152 auto const& sle = *accountState;
161 if ((sle.isFieldPresent(sfRegularKey)) &&
162 (publicKeyAcctID == sle.getAccountID(sfRegularKey)))
179 if (tx_json[jss::TransactionType].asString() != jss::Payment)
183 if (tx_json.
isMember(jss::DeliverMax))
187 if (tx_json[jss::DeliverMax] != tx_json[jss::Amount])
190 "Cannot specify differing 'Amount' and 'DeliverMax'");
193 tx_json[jss::Amount] = tx_json[jss::DeliverMax];
206 if (!tx_json.
isMember(jss::Destination))
209 auto const dstAccountID =
210 parseBase58<AccountID>(tx_json[jss::Destination].asString());
214 if (params.
isMember(jss::build_path) &&
218 "Field 'build_path' not allowed in this context.");
223 "Cannot specify both 'tx_json.Paths' and 'build_path'");
255 std::make_shared<RippleLineCache>(
256 ledger, app.
journal(
"RippleLineCache")),
275 auto j = app.
journal(
"RPCHandler");
276 JLOG(j.debug()) <<
"transactionSign: build_path: "
314 if (!tx_json.
isMember(jss::TransactionType))
320 if (!tx_json.
isMember(jss::Account))
327 auto const srcAddressID =
328 parseBase58<AccountID>(tx_json[jss::Account].asString());
357 ret.
second = *srcAddressID;
390static transactionPreProcessResult
398 auto j = app.
journal(
"RPCHandler");
410 !(params.
isMember(jss::offline) && params[jss::offline].
asBool());
428 return std::move(txJsonResult);
443 JLOG(j.debug()) <<
"transactionSign: Failed to find source account "
444 <<
"in current ledger: " <<
toBase58(srcAddressID);
451 if (!tx_json.
isMember(jss::Sequence))
453 bool const hasTicketSeq =
454 tx_json.
isMember(sfTicketSequence.jsonName);
455 if (!hasTicketSeq && !sle)
458 <<
"transactionSign: Failed to find source account "
459 <<
"in current ledger: " <<
toBase58(srcAddressID);
463 tx_json[jss::Sequence] =
470 if (!tx_json.
isMember(jss::NetworkID))
473 if (networkId > 1024)
474 tx_json[jss::NetworkID] =
to_string(networkId);
508 if (tx_json.
isMember(jss::TxnSignature))
534 if (tx_json.
isMember(sfDelegate.jsonName))
537 auto const delegateJson = tx_json[sfDelegate.jsonName];
538 auto const ptrDelegatedAddressID = delegateJson.
isString()
539 ? parseBase58<AccountID>(delegateJson.asString())
542 if (!ptrDelegatedAddressID)
549 auto delegatedAddressID = *ptrDelegatedAddressID;
572 if (!parsed.
object.has_value())
575 err[jss::error] = parsed.
error[jss::error];
576 err[jss::error_code] = parsed.
error[jss::error_code];
577 err[jss::error_message] = parsed.
error[jss::error_message];
586 parsed.
object->setFieldVL(
590 stTx = std::make_shared<STTx>(std::move(parsed.
object.value()));
600 "Exception occurred constructing serialized transaction");
636 tpTrans = std::make_shared<Transaction>(stTx, reason, app);
637 if (tpTrans->getStatus() !=
NEW)
640 rpcINTERNAL,
"Unable to construct transaction: " + reason);
652 tpTrans->getSTransaction()->add(s);
657 auto sttxNew = std::make_shared<STTx const>(sit);
661 sttxNew->getTransactionID(),
673 std::make_shared<Transaction>(sttxNew, reason, app);
677 if (!tpTransNew->getSTransaction()->isEquivalent(
678 *tpTrans->getSTransaction()))
682 tpTrans = std::move(tpTransNew);
698 ret.
second = std::move(tpTrans);
710 jvResult[jss::tx_json] =
712 jvResult[jss::hash] =
to_string(tpTrans->getID());
718 jvResult[jss::tx_json],
719 tpTrans->getSTransaction()->getTxnType(),
722 jvResult[jss::tx_blob] =
723 strHex(tpTrans->getSTransaction()->getSerializer().peekData());
732 jvResult[jss::engine_result] = sToken;
733 jvResult[jss::engine_result_code] = tpTrans->getResult();
734 jvResult[jss::engine_result_message] = sHuman;
740 rpcINTERNAL,
"Exception occurred during JSON handling.");
761 tx[jss::Sequence] =
"0";
764 if (!tx.
isMember(jss::SigningPubKey))
766 tx[jss::SigningPubKey] =
"";
769 if (!tx.
isMember(jss::TxnSignature))
771 tx[jss::TxnSignature] =
"";
776 if (!tx[jss::Signers].isArray())
780 for (
auto& signer : tx[jss::Signers])
782 if (!signer.isMember(jss::Signer) ||
783 !signer[jss::Signer].isObject())
785 if (!signer[jss::Signer].isMember(jss::SigningPubKey))
788 signer[jss::Signer][jss::SigningPubKey] =
"";
790 if (!signer[jss::Signer].isMember(jss::TxnSignature))
793 signer[jss::Signer][jss::TxnSignature] =
"";
799 if (!parsed.
object.has_value())
835 auto const baseFee = ledger->fees().base;
841 auto const limit =
mulDiv(feeDefault, mult, div);
843 Throw<std::overflow_error>(
"mulDiv");
848 ss <<
"Fee of " << fee <<
" exceeds the requested tx limit of "
875 if (request.
isMember(jss::fee_mult_max))
877 if (request[jss::fee_mult_max].isInt())
879 mult = request[jss::fee_mult_max].
asInt();
884 jss::fee_mult_max,
"a positive integer"));
891 jss::fee_mult_max,
"a positive integer"));
894 if (request.
isMember(jss::fee_div_max))
896 if (request[jss::fee_div_max].isInt())
898 div = request[jss::fee_div_max].
asInt();
903 jss::fee_div_max,
"a positive integer"));
910 jss::fee_div_max,
"a positive integer"));
916 if (feeOrError.isMember(jss::error))
918 tx[jss::Fee] = std::move(feeOrError);
934 using namespace detail;
936 auto j = app.
journal(
"RPCHandler");
937 JLOG(j.debug()) <<
"transactionSign: " << jvRequest;
940 SigningForParams signForParams;
941 transactionPreProcessResult preprocResult = transactionPreProcessImpl(
942 jvRequest, role, signForParams, validatedLedgerAge, app);
944 if (!preprocResult.second)
945 return preprocResult.first;
950 transactionConstructImpl(preprocResult.second, ledger->rules(), app);
969 using namespace detail;
972 auto j = app.
journal(
"RPCHandler");
973 JLOG(j.debug()) <<
"transactionSubmit: " << jvRequest;
976 SigningForParams signForParams;
977 transactionPreProcessResult preprocResult = transactionPreProcessImpl(
978 jvRequest, role, signForParams, validatedLedgerAge, app);
980 if (!preprocResult.second)
981 return preprocResult.first;
985 transactionConstructImpl(preprocResult.second, ledger->rules(), app);
999 rpcINTERNAL,
"Exception occurred during transaction submission.");
1011 if (!jvRequest.
isMember(jss::tx_json))
1014 Json::Value const& tx_json(jvRequest[jss::tx_json]);
1022 if (!tx_json.
isMember(jss::Sequence))
1025 if (!tx_json.
isMember(sfSigningPubKey.getJsonName()))
1028 if (!tx_json[sfSigningPubKey.getJsonName()].
asString().
empty())
1031 "When multi-signing 'tx_json.SigningPubKey' must be empty.");
1042 if (signers.empty())
1050 return (a[sfAccount] < b[sfAccount]);
1058 return (a[sfAccount] == b[sfAccount]);
1061 if (dupIter != signers.end())
1064 err <<
"Duplicate Signers:Signer:Account entries ("
1065 <<
toBase58((*dupIter)[sfAccount]) <<
") are not allowed.";
1070 if (signers.end() !=
1074 [&signingForID](
STObject const& elem) {
1075 return elem[sfAccount] == signingForID;
1079 err <<
"A Signer may not be the transaction's Account ("
1099 auto j = app.
journal(
"RPCHandler");
1100 JLOG(j.debug()) <<
"transactionSignFor: " << jvRequest;
1103 char const accountField[] =
"account";
1105 if (!jvRequest.
isMember(accountField))
1109 auto const signerAccountID =
1110 parseBase58<AccountID>(jvRequest[accountField].asString());
1111 if (!signerAccountID)
1117 if (!jvRequest.
isMember(jss::tx_json))
1128 if (!tx_json.
isMember(sfSigningPubKey.getJsonName()))
1129 tx_json[sfSigningPubKey.getJsonName()] =
"";
1134 using namespace detail;
1136 Json::Value err = checkMultiSignFields(jvRequest);
1142 SigningForParams signForParams(*signerAccountID);
1144 transactionPreProcessResult preprocResult = transactionPreProcessImpl(
1145 jvRequest, role, signForParams, validatedLedgerAge, app);
1147 if (!preprocResult.second)
1148 return preprocResult.first;
1151 signForParams.validMultiSign(),
1152 "ripple::RPC::transactionSignFor : valid multi-signature");
1158 auto const err = acctMatchesPubKey(
1159 account_state, *signerAccountID, signForParams.getPublicKey());
1166 auto& sttx = preprocResult.second;
1170 signer[sfAccount] = *signerAccountID;
1171 signer.
setFieldVL(sfTxnSignature, signForParams.getSignature());
1173 sfSigningPubKey, signForParams.getPublicKey().slice());
1176 if (!sttx->isFieldPresent(sfSigners))
1177 sttx->setFieldArray(sfSigners, {});
1179 auto& signers = sttx->peekFieldArray(sfSigners);
1180 signers.emplace_back(std::move(signer));
1183 auto err = sortAndValidateSigners(signers, (*sttx)[sfAccount]);
1190 transactionConstructImpl(sttx, ledger->rules(), app);
1210 auto j = app.
journal(
"RPCHandler");
1211 JLOG(j.debug()) <<
"transactionSubmitMultiSigned: " << jvRequest;
1215 using namespace detail;
1217 Json::Value err = checkMultiSignFields(jvRequest);
1224 auto [txJsonResult, srcAddressID] = checkTxJsonFields(
1234 return std::move(txJsonResult);
1243 <<
"transactionSubmitMultiSigned: Failed to find source account "
1244 <<
"in current ledger: " <<
toBase58(srcAddressID);
1262 err = checkPayment(jvRequest, tx_json, srcAddressID, role, app,
false);
1272 if (!parsedTx_json.
object)
1275 jvResult[
"error"] = parsedTx_json.
error[
"error"];
1276 jvResult[
"error_code"] = parsedTx_json.
error[
"error_code"];
1277 jvResult[
"error_message"] = parsedTx_json.
error[
"error_message"];
1283 std::make_shared<STTx>(std::move(parsedTx_json.
object.value()));
1294 "Exception while serializing transaction: " + reason);
1307 if (!stTx->getFieldVL(sfSigningPubKey).empty())
1310 err <<
"Invalid " << sfSigningPubKey.fieldName
1311 <<
" field. Field must be empty when multi-signing.";
1316 if (stTx->isFieldPresent(sfTxnSignature))
1320 auto const fee = stTx->getFieldAmount(sfFee);
1325 err <<
"Invalid " << sfFee.fieldName
1326 <<
" field. Fees must be specified in XRP.";
1332 err <<
"Invalid " << sfFee.fieldName
1333 <<
" field. Fees must be greater than zero.";
1339 if (!stTx->isFieldPresent(sfSigners))
1344 auto& signers = stTx->peekFieldArray(sfSigners);
1346 if (signers.empty())
1351 signers.begin(), signers.end(), [](
STObject const& obj) {
1355 obj.isFieldPresent(sfAccount) &&
1356 obj.isFieldPresent(sfSigningPubKey) &&
1357 obj.isFieldPresent(sfTxnSignature) && obj.getCount() == 3);
1358 }) != signers.end())
1361 "Signers array may only contain Signer entries.");
1365 auto err = sortAndValidateSigners(signers, srcAddressID);
1371 transactionConstructImpl(stTx, ledger->rules(), app);
1385 rpcINTERNAL,
"Exception occurred during transaction submission.");
T adjacent_find(T... args)
Value removeMember(char const *key)
Remove and return the named member.
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.
virtual Config & config()=0
virtual LoadFeeTrack & getFeeTrack()=0
virtual OpenLedger & openLedger()=0
virtual beast::Journal journal(std::string const &name)=0
virtual bool checkSigs() const =0
virtual HashRouter & getHashRouter()=0
Like std::vector<char> but better.
std::size_t size() const noexcept
Returns the number of bytes in the buffer.
Manages the current fee schedule.
bool isLoadedCluster() const
std::shared_ptr< OpenView const > current() const
Returns a view to the current open ledger.
Calculates payment paths.
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.
STPathSet getBestPaths(int maxPaths, STPath &fullLiquidityPath, STPathSet const &extraPaths, AccountID const &srcIssuer, std::function< bool(void)> const &continueCallback={})
Slice slice() const noexcept
AccountID const *const multiSigningAcctID_
std::optional< PublicKey > multiSignPublicKey_
SigningForParams(SigningForParams const &rhs)=delete
bool validMultiSign() const
SigningForParams(AccountID const &multiSigningAcctID)
AccountID const & getSigner() const
bool isMultiSigning() const
void moveMultiSignature(Buffer &&multiSignature)
PublicKey const & getPublicKey() const
Buffer const & getSignature() const
bool isSingleSigning() const
void setPublicKey(PublicKey const &multiSignPublicKey)
Rules controlling protocol behavior.
constexpr bool holds() const noexcept
void setIssuer(AccountID const &uIssuer)
Issue const & issue() const
bool native() const noexcept
static STObject makeInnerObject(SField const &name)
void setFieldVL(SField const &field, Blob const &)
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
constexpr std::uint32_t value() const
Slice slice() const noexcept
An immutable linear range of bytes.
Metrics getMetrics(OpenView const &view) const
Returns fee metrics in reference fee level units.
SeqProxy nextQueuableSeq(std::shared_ptr< SLE const > const &sleAccount) const
Return the next sequence that would go in the TxQ for an account.
Json::Value jsonClipped() const
auto constexpr maxValidatedLedgerAge
static int constexpr defaultAutoFillFeeMultiplier
static int constexpr defaultAutoFillFeeDivisor
static Json::Value checkPayment(Json::Value const ¶ms, Json::Value &tx_json, AccountID const &srcAddressID, Role const role, Application &app, bool doPath)
static error_code_i acctMatchesPubKey(std::shared_ptr< SLE const > accountState, AccountID const &accountID, PublicKey const &publicKey)
static std::pair< Json::Value, AccountID > checkTxJsonFields(Json::Value const &tx_json, Role const role, bool const verify, std::chrono::seconds validatedLedgerAge, Config const &config, LoadFeeTrack const &feeTrack, unsigned apiVersion)
static transactionPreProcessResult transactionPreProcessImpl(Json::Value ¶ms, Role role, SigningForParams &signingArgs, std::chrono::seconds validatedLedgerAge, Application &app)
static std::pair< Json::Value, Transaction::pointer > transactionConstructImpl(std::shared_ptr< STTx const > const &stTx, Rules const &rules, Application &app)
static Json::Value checkMultiSignFields(Json::Value const &jvRequest)
static Json::Value sortAndValidateSigners(STArray &signers, AccountID const &signingForID)
static Json::Value transactionFormatResultImpl(Transaction::pointer tpTrans, unsigned apiVersion)
Json::Value transactionSign(Json::Value jvRequest, unsigned apiVersion, NetworkOPs::FailHard failType, Role role, std::chrono::seconds validatedLedgerAge, Application &app)
Returns a Json::objectValue.
bool contains_error(Json::Value const &json)
Returns true if the json contains an rpc error specification.
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::objectValue.
Json::Value make_error(error_code_i code)
Returns a new json object that reflects the error code.
Json::Value invalid_field_error(std::string const &name)
static constexpr std::integral_constant< unsigned, Version > apiVersion
unsigned int getAPIVersionNumber(Json::Value const &jv, bool betaEnabled)
Retrieve the api version number from the json value.
Json::Value make_param_error(std::string const &message)
Returns a new json object that indicates invalid parameters.
std::string missing_field_message(std::string const &name)
std::string invalid_field_message(std::string const &name)
std::string expected_field_message(std::string const &name, std::string const &type)
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::objectValue.
static XRPAmount getTxFee(Application const &app, Config const &config, Json::Value tx)
Json::Value object_field_error(std::string const &name)
void insertDeliverMax(Json::Value &tx_json, TxType txnType, unsigned int apiVersion)
Copy Amount field to DeliverMax field in transaction output JSON.
Json::Value transactionSignFor(Json::Value jvRequest, unsigned apiVersion, NetworkOPs::FailHard failType, Role role, std::chrono::seconds validatedLedgerAge, Application &app)
Returns a Json::objectValue.
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.
Json::Value missing_field_error(std::string const &name)
std::optional< std::pair< PublicKey, SecretKey > > keypairForSignature(Json::Value const ¶ms, Json::Value &error, unsigned int apiVersion)
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
@ rpcDELEGATE_ACT_NOT_FOUND
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig, bool mustBeFullyCanonical=true) noexcept
Verify a signature on a message.
Serializer buildMultiSigningData(STObject const &obj, AccountID const &signingID)
Return a Serializer suitable for computing a multisigning TxnSignature.
XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Compute only the expected base fee for a transaction.
bool isLegalNet(STAmount const &value)
AccountID calcAccountID(PublicKey const &pk)
Json::Value rpcError(int iError)
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &message)
Generate a signature for a message.
std::string strHex(FwdIt begin, FwdIt end)
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
bool amountFromJsonNoThrow(STAmount &result, Json::Value const &jvSource)
void forceValidity(HashRouter &router, uint256 const &txid, Validity validity)
Sets the validity of a given transaction in the cache.
bool passesLocalChecks(STObject const &st, std::string &)
@ Valid
Signature and local checks are good / passed.
@ SigGoodOnly
Signature is good, but local checks fail.
std::string to_string(base_uint< Bits, Tag > const &a)
constexpr std::uint32_t tfFullyCanonicalSig
Transaction flags.
XRPAmount scaleFeeLoad(XRPAmount fee, LoadFeeTrack const &feeTrack, Fees const &fees, bool bUnlimited)
XRPAmount toDrops(FeeLevel< T > const &level, XRPAmount baseFee)
std::optional< std::uint64_t > mulDiv(std::uint64_t value, std::uint64_t mul, std::uint64_t div)
Return value*mul/div accurately.
std::pair< Validity, std::string > checkValidity(HashRouter &router, STTx const &tx, Rules const &rules, Config const &config)
Checks transaction signature and local checks.
bool transResultInfo(TER code, std::string &token, std::string &text)
Role
Indicates the level of administrative permission to grant.
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
XRPAmount reference_fee
The cost of a reference transaction in drops.
transactionPreProcessResult(std::shared_ptr< STTx > &&st)
transactionPreProcessResult & operator=(transactionPreProcessResult const &)=delete
transactionPreProcessResult(transactionPreProcessResult const &)=delete
transactionPreProcessResult(Json::Value &&json)
transactionPreProcessResult()=delete
std::shared_ptr< STTx > const second
transactionPreProcessResult(transactionPreProcessResult &&rhs)=default
transactionPreProcessResult & operator=(transactionPreProcessResult &&)=delete