20 #include <ripple/app/ledger/LedgerMaster.h>
21 #include <ripple/app/ledger/OpenLedger.h>
22 #include <ripple/app/main/Application.h>
23 #include <ripple/app/misc/LoadFeeTrack.h>
24 #include <ripple/app/misc/Transaction.h>
25 #include <ripple/app/misc/TxQ.h>
26 #include <ripple/app/paths/Pathfinder.h>
27 #include <ripple/app/tx/apply.h>
28 #include <ripple/basics/Log.h>
29 #include <ripple/basics/mulDiv.h>
30 #include <ripple/json/json_writer.h>
31 #include <ripple/net/RPCErr.h>
32 #include <ripple/protocol/ErrorCodes.h>
33 #include <ripple/protocol/Feature.h>
34 #include <ripple/protocol/STAccount.h>
35 #include <ripple/protocol/STParsedJSON.h>
36 #include <ripple/protocol/Sign.h>
37 #include <ripple/protocol/TxFlags.h>
38 #include <ripple/rpc/impl/LegacyPathFind.h>
39 #include <ripple/rpc/impl/RPCHelpers.h>
40 #include <ripple/rpc/impl/TransactionSign.h>
41 #include <ripple/rpc/impl/Tuning.h>
128 bool const isMasterKey = publicKeyAcctID == accountID;
140 auto const& sle = *accountState;
167 if (tx_json[jss::TransactionType].asString() != jss::Payment)
178 if (!tx_json.
isMember(jss::Destination))
181 auto const dstAccountID =
182 parseBase58<AccountID>(tx_json[jss::Destination].asString());
186 if ((doPath ==
false) && params.
isMember(jss::build_path))
189 "Field 'build_path' not allowed in this context.");
194 "Cannot specify both 'tx_json.Paths' and 'build_path'");
226 std::make_shared<RippleLineCache>(
227 ledger, app.
journal(
"RippleLineCache")),
246 auto j = app.
journal(
"RPCHandler");
247 JLOG(j.debug()) <<
"transactionSign: build_path: "
285 if (!tx_json.
isMember(jss::TransactionType))
291 if (!tx_json.
isMember(jss::Account))
298 auto const srcAddressID =
299 parseBase58<AccountID>(tx_json[jss::Account].asString());
328 ret.
second = *srcAddressID;
361 static transactionPreProcessResult
369 auto j = app.
journal(
"RPCHandler");
377 !(params.
isMember(jss::offline) && params[jss::offline].
asBool());
395 return std::move(txJsonResult);
410 JLOG(j.debug()) <<
"transactionSign: Failed to find source account "
411 <<
"in current ledger: " <<
toBase58(srcAddressID);
443 if (!tx_json.
isMember(jss::Sequence))
445 bool const hasTicketSeq =
447 if (!hasTicketSeq && !sle)
450 <<
"transactionSign: Failed to find source account "
451 <<
"in current ledger: " <<
toBase58(srcAddressID);
455 tx_json[jss::Sequence] =
500 if (!parsed.
object.has_value())
503 err[jss::error] = parsed.
error[jss::error];
504 err[jss::error_code] = parsed.
error[jss::error_code];
505 err[jss::error_message] = parsed.
error[jss::error_message];
514 parsed.
object->setFieldVL(
518 stpTrans = std::make_shared<STTx>(std::move(parsed.
object.value()));
528 "Exception occurred constructing serialized transaction");
547 stpTrans->sign(pk, sk);
565 tpTrans = std::make_shared<Transaction>(stpTrans, reason, app);
566 if (tpTrans->getStatus() !=
NEW)
569 rpcINTERNAL,
"Unable to construct transaction: " + reason);
581 tpTrans->getSTransaction()->add(s);
586 auto sttxNew = std::make_shared<STTx const>(sit);
590 sttxNew->getTransactionID(),
602 std::make_shared<Transaction>(sttxNew, reason, app);
606 if (!tpTransNew->getSTransaction()->isEquivalent(
607 *tpTrans->getSTransaction()))
611 tpTrans = std::move(tpTransNew);
627 ret.
second = std::move(tpTrans);
638 jvResult[jss::tx_blob] =
639 strHex(tpTrans->getSTransaction()->getSerializer().peekData());
648 jvResult[jss::engine_result] = sToken;
649 jvResult[jss::engine_result_code] = tpTrans->getResult();
650 jvResult[jss::engine_result_message] = sHuman;
656 rpcINTERNAL,
"Exception occurred during JSON handling.");
684 if (request.
isMember(jss::fee_mult_max))
686 if (request[jss::fee_mult_max].isInt())
688 mult = request[jss::fee_mult_max].
asInt();
693 jss::fee_mult_max,
"a positive integer"));
700 jss::fee_mult_max,
"a positive integer"));
703 if (request.
isMember(jss::fee_div_max))
705 if (request[jss::fee_div_max].isInt())
707 div = request[jss::fee_div_max].
asInt();
712 jss::fee_div_max,
"a positive integer"));
719 jss::fee_div_max,
"a positive integer"));
732 auto const baseFee = ledger->fees().base;
738 auto const limit = [&]() {
740 auto const result =
mulDiv(feeDefault, mult, div);
742 Throw<std::overflow_error>(
"mulDiv");
743 return result.second;
749 ss <<
"Fee of " << fee <<
" exceeds the requested tx limit of "
769 using namespace detail;
771 auto j = app.
journal(
"RPCHandler");
772 JLOG(j.debug()) <<
"transactionSign: " << jvRequest;
775 SigningForParams signForParams;
777 jvRequest, role, signForParams, validatedLedgerAge, app);
779 if (!preprocResult.second)
780 return preprocResult.first;
807 using namespace detail;
810 auto j = app.
journal(
"RPCHandler");
811 JLOG(j.debug()) <<
"transactionSubmit: " << jvRequest;
814 SigningForParams signForParams;
816 jvRequest, role, signForParams, validatedLedgerAge, app);
818 if (!preprocResult.second)
819 return preprocResult.first;
837 rpcINTERNAL,
"Exception occurred during transaction submission.");
849 if (!jvRequest.
isMember(jss::tx_json))
852 Json::Value const& tx_json(jvRequest[jss::tx_json]);
860 if (!tx_json.
isMember(jss::Sequence))
869 "When multi-signing 'tx_json.SigningPubKey' must be empty.");
888 return (a[sfAccount] < b[sfAccount]);
896 return (a[sfAccount] == b[sfAccount]);
899 if (dupIter != signers.end())
902 err <<
"Duplicate Signers:Signer:Account entries ("
912 [&signingForID](
STObject const& elem) {
913 return elem[sfAccount] == signingForID;
917 err <<
"A Signer may not be the transaction's Account ("
936 auto j = app.
journal(
"RPCHandler");
937 JLOG(j.debug()) <<
"transactionSignFor: " << jvRequest;
940 const char accountField[] =
"account";
942 if (!jvRequest.
isMember(accountField))
946 auto const signerAccountID =
947 parseBase58<AccountID>(jvRequest[accountField].asString());
948 if (!signerAccountID)
954 if (!jvRequest.
isMember(jss::tx_json))
971 using namespace detail;
981 SigningForParams signForParams(
982 *signerAccountID, multiSignPubKey, multiSignature);
985 jvRequest, role, signForParams, validatedLedgerAge, app);
987 if (!preprocResult.second)
988 return preprocResult.first;
1002 auto& sttx = preprocResult.second;
1014 auto& signers = sttx->peekFieldArray(
sfSigners);
1015 signers.emplace_back(std::move(signer));
1044 auto j = app.
journal(
"RPCHandler");
1045 JLOG(j.debug()) <<
"transactionSubmitMultiSigned: " << jvRequest;
1049 using namespace detail;
1068 return std::move(txJsonResult);
1077 <<
"transactionSubmitMultiSigned: Failed to find source account "
1078 <<
"in current ledger: " <<
toBase58(srcAddressID);
1096 err =
checkPayment(jvRequest, tx_json, srcAddressID, role, app,
false);
1106 if (!parsedTx_json.
object)
1109 jvResult[
"error"] = parsedTx_json.
error[
"error"];
1110 jvResult[
"error_code"] = parsedTx_json.
error[
"error_code"];
1111 jvResult[
"error_message"] = parsedTx_json.
error[
"error_message"];
1117 std::make_shared<STTx>(std::move(parsedTx_json.
object.value()));
1128 "Exception while serializing transaction: " + reason);
1145 <<
" field. Field must be empty when multi-signing.";
1154 auto const fee = stpTrans->getFieldAmount(
sfFee);
1160 <<
" field. Fees must be specified in XRP.";
1167 <<
" field. Fees must be greater than zero.";
1173 if (!stpTrans->isFieldPresent(
sfSigners))
1178 auto& signers = stpTrans->peekFieldArray(
sfSigners);
1180 if (signers.empty())
1185 signers.begin(), signers.end(), [](
STObject const& obj) {
1189 obj.isFieldPresent(sfAccount) &&
1190 obj.isFieldPresent(sfSigningPubKey) &&
1191 obj.isFieldPresent(sfTxnSignature) && obj.getCount() == 3);
1192 }) != signers.end())
1195 "Signers array may only contain Signer entries.");
1219 rpcINTERNAL,
"Exception occurred during transaction submission.");
AccountID const *const multiSigningAcctID_
XRPAmount reference_fee
The cost of a reference transaction in drops.
virtual bool checkSigs() const =0
bool amountFromJsonNoThrow(STAmount &result, Json::Value const &jvSource)
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)
transactionPreProcessResult & operator=(transactionPreProcessResult const &)=delete
std::shared_ptr< OpenView const > current() const
Returns a view to the current open ledger.
Json::Value transactionSignFor(Json::Value jvRequest, NetworkOPs::FailHard failType, Role role, std::chrono::seconds validatedLedgerAge, Application &app)
Returns a Json::objectValue.
Json::Value rpcError(int iError)
Issue const & issue() const
std::string missing_field_message(std::string const &name)
Calculates payment paths.
An immutable linear range of bytes.
const SF_ACCOUNT sfRegularKey
PublicKey *const multiSignPublicKey_
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig, bool mustBeFullyCanonical) noexcept
Verify a signature on a message.
void computePathRanks(int maxPaths, std::function< bool(void)> const &continueCallback={})
Compute the rankings of the paths.
unsigned int getAPIVersionNumber(Json::Value const &jv, bool betaEnabled)
Retrieve the api version number from the json value.
const std::string fieldName
const SF_VL sfSigningPubKey
const std::shared_ptr< STTx > second
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
constexpr std::uint32_t tfFullyCanonicalSig
Transaction flags.
static Json::Value checkPayment(Json::Value const ¶ms, Json::Value &tx_json, AccountID const &srcAddressID, Role const role, Application &app, bool doPath)
Slice slice() const noexcept
Like std::vector<char> but better.
Holds the serialized result of parsing an input JSON object.
const SF_UINT32 sfTicketSequence
bool isLegalNet(STAmount const &value)
bool findPaths(int searchLevel, std::function< bool(void)> const &continueCallback={})
void setFieldVL(SField const &field, Blob const &)
void setIssuer(AccountID const &uIssuer)
Json::StaticString const & getJsonName() const
virtual OpenLedger & openLedger()=0
std::optional< STObject > object
The STObject if the parse was successful.
Json::Value transactionSign(Json::Value jvRequest, NetworkOPs::FailHard failType, Role role, std::chrono::seconds validatedLedgerAge, Application &app)
Returns a Json::objectValue.
const Json::StaticString jsonName
static std::pair< Json::Value, Transaction::pointer > transactionConstructImpl(std::shared_ptr< STTx const > const &stpTrans, Rules const &rules, Application &app)
Json::Value object_field_error(std::string const &name)
void forceValidity(HashRouter &router, uint256 const &txid, Validity validity)
Sets the validity of a given transaction in the cache.
transactionPreProcessResult(std::shared_ptr< STTx > &&st)
virtual LoadFeeTrack & getFeeTrack()=0
Json::Value error
On failure, an appropriate set of error values.
void setPublicKey(PublicKey const &multiSignPublicKey)
@ SigGoodOnly
Signature is good, but local checks fail.
static error_code_i acctMatchesPubKey(std::shared_ptr< SLE const > accountState, AccountID const &accountID, PublicKey const &publicKey)
Json::Value missing_field_error(std::string const &name)
AccountID const & getSigner()
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.
static Json::Value transactionFormatResultImpl(Transaction::pointer tpTrans)
std::string expected_field_message(std::string const &name, std::string const &type)
Json::Value transactionSubmit(Json::Value jvRequest, NetworkOPs::FailHard failType, Role role, std::chrono::seconds validatedLedgerAge, Application &app, ProcessTransactionFn const &processTransaction)
Returns a Json::objectValue.
static transactionPreProcessResult transactionPreProcessImpl(Json::Value ¶ms, Role role, SigningForParams &signingArgs, std::chrono::seconds validatedLedgerAge, Application &app)
std::pair< Validity, std::string > checkValidity(HashRouter &router, STTx const &tx, Rules const &rules, Config const &config)
Checks transaction signature and local checks.
bool passesLocalChecks(STObject const &st, std::string &reason)
bool contains_error(Json::Value const &json)
Returns true if the json contains an rpc error specification.
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)
virtual LedgerMaster & getLedgerMaster()=0
Keylet account(AccountID const &id) noexcept
AccountID root.
virtual Config & config()=0
static Json::Value sortAndValidateSigners(STArray &signers, AccountID const &signingForID)
AccountID calcAccountID(PublicKey const &pk)
Manages the current fee schedule.
Slice slice() const noexcept
SeqProxy nextQueuableSeq(std::shared_ptr< SLE const > const &sleAccount) const
Return the next sequence that would go in the TxQ for an account.
bool isMember(const char *key) const
Return true if the object has a member named key.
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
STPathSet getBestPaths(int maxPaths, STPath &fullLiquidityPath, STPathSet const &extraPaths, AccountID const &srcIssuer, std::function< bool(void)> const &continueCallback={})
transactionPreProcessResult(Json::Value &&json)
std::string invalid_field_message(std::string const &name)
const SF_VL sfTxnSignature
constexpr std::uint32_t value() const
bool native() const noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool transResultInfo(TER code, std::string &token, std::string &text)
virtual beast::Journal journal(std::string const &name)=0
@ Valid
Signature and local checks are good / passed.
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &m)
Generate a signature for a message.
Buffer *const multiSignature_
void moveMultiSignature(Buffer &&multiSignature)
std::pair< PublicKey, SecretKey > keypairForSignature(Json::Value const ¶ms, Json::Value &error)
bool isLoadedCluster() const
Json::Value getJson(JsonOptions) const override
bool isSingleSigning() const
T adjacent_find(T... args)
bool isMultiSigning() const
std::shared_ptr< Ledger const > getValidatedLedger()
Rules controlling protocol behavior.
static Json::Value checkMultiSignFields(Json::Value const &jvRequest)
SigningForParams(AccountID const &multiSigningAcctID, PublicKey &multiSignPublicKey, Buffer &multiSignature)
XRPAmount scaleFeeLoad(XRPAmount fee, LoadFeeTrack const &feeTrack, Fees const &fees, bool bUnlimited)
const SF_ACCOUNT sfAccount
std::string strHex(FwdIt begin, FwdIt end)
std::pair< bool, Dest > mulDiv(Source1 value, Dest mul, Source2 div)
Metrics getMetrics(OpenView const &view) const
Returns fee metrics in reference fee level units.
Json::Value make_param_error(std::string const &message)
Returns a new json object that indicates invalid parameters.
static constexpr int defaultAutoFillFeeMultiplier
Json::Value invalid_field_error(std::string const &name)
virtual HashRouter & getHashRouter()=0
XRPAmount toDrops(FeeLevel< T > const &level, XRPAmount baseFee)
static constexpr int defaultAutoFillFeeDivisor
Role
Indicates the level of administrative permission to grant.
Json::Value make_error(error_code_i code)
Returns a new json object that reflects the error code.
constexpr auto maxValidatedLedgerAge
Json::Value jsonClipped() const
Serializer buildMultiSigningData(STObject const &obj, AccountID const &signingID)
Return a Serializer suitable for computing a multisigning TxnSignature.
Json::Value transactionSubmitMultiSigned(Json::Value jvRequest, NetworkOPs::FailHard failType, Role role, std::chrono::seconds validatedLedgerAge, Application &app, ProcessTransactionFn const &processTransaction)
Returns a Json::objectValue.
transactionPreProcessResult()=delete
std::string asString() const
Returns the unquoted string value.