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;
168 if (tx_json[jss::TransactionType].asString() != jss::Payment)
179 if (!tx_json.
isMember(jss::Destination))
182 auto const dstAccountID =
183 parseBase58<AccountID>(tx_json[jss::Destination].asString());
187 if ((doPath ==
false) && params.
isMember(jss::build_path))
190 "Field 'build_path' not allowed in this context.");
195 "Cannot specify both 'tx_json.Paths' and 'build_path'");
226 std::make_shared<RippleLineCache>(ledger),
245 auto j = app.
journal(
"RPCHandler");
246 JLOG(j.debug()) <<
"transactionSign: build_path: "
283 if (!tx_json.
isMember(jss::TransactionType))
289 if (!tx_json.
isMember(jss::Account))
296 auto const srcAddressID =
297 parseBase58<AccountID>(tx_json[jss::Account].asString());
323 ret.
second = *srcAddressID;
360 static transactionPreProcessResult
369 auto j = app.
journal(
"RPCHandler");
377 !(params.
isMember(jss::offline) && params[jss::offline].
asBool());
394 return std::move(txJsonResult);
408 JLOG(j.debug()) <<
"transactionSign: Failed to find source account "
409 <<
"in current ledger: " <<
toBase58(srcAddressID);
442 if (!tx_json.
isMember(jss::Sequence))
447 <<
"transactionSign: Failed to find source account "
448 <<
"in current ledger: " <<
toBase58(srcAddressID);
458 for (
auto const& tx : queued)
462 else if (tx.first > seq)
465 tx_json[jss::Sequence] = seq;
509 if (parsed.
object == boost::none)
512 err[jss::error] = parsed.
error[jss::error];
513 err[jss::error_code] = parsed.
error[jss::error_code];
514 err[jss::error_message] = parsed.
error[jss::error_message];
523 parsed.
object->setFieldVL(
527 stpTrans = std::make_shared<STTx>(std::move(parsed.
object.get()));
537 "Exception occurred constructing serialized transaction");
556 stpTrans->sign(pk, sk);
574 tpTrans = std::make_shared<Transaction>(stpTrans, reason, app);
575 if (tpTrans->getStatus() !=
NEW)
578 rpcINTERNAL,
"Unable to construct transaction: " + reason);
590 tpTrans->getSTransaction()->add(s);
595 auto sttxNew = std::make_shared<STTx const>(sit);
599 sttxNew->getTransactionID(),
611 std::make_shared<Transaction>(sttxNew, reason, app);
615 if (!tpTransNew->getSTransaction()->isEquivalent(
616 *tpTrans->getSTransaction()))
620 tpTrans = std::move(tpTransNew);
636 ret.
second = std::move(tpTrans);
647 jvResult[jss::tx_blob] =
648 strHex(tpTrans->getSTransaction()->getSerializer().peekData());
657 jvResult[jss::engine_result] = sToken;
658 jvResult[jss::engine_result_code] = tpTrans->getResult();
659 jvResult[jss::engine_result_message] = sHuman;
665 rpcINTERNAL,
"Exception occurred during JSON handling.");
693 if (request.
isMember(jss::fee_mult_max))
695 if (request[jss::fee_mult_max].isInt())
697 mult = request[jss::fee_mult_max].
asInt();
702 jss::fee_mult_max,
"a positive integer"));
709 jss::fee_mult_max,
"a positive integer"));
712 if (request.
isMember(jss::fee_div_max))
714 if (request[jss::fee_div_max].isInt())
716 div = request[jss::fee_div_max].
asInt();
721 jss::fee_div_max,
"a positive integer"));
728 jss::fee_div_max,
"a positive integer"));
741 auto const baseFee = ledger->fees().base;
749 auto const limit = [&]() {
752 mulDiv(feeDefault, ledger->fees().base, ledger->fees().units);
754 Throw<std::overflow_error>(
"mulDiv");
755 auto const result =
mulDiv(drops.second, mult, div);
757 Throw<std::overflow_error>(
"mulDiv");
758 return result.second;
764 ss <<
"Fee of " << fee <<
" exceeds the requested tx limit of "
784 using namespace detail;
787 auto j = app.
journal(
"RPCHandler");
788 JLOG(j.debug()) <<
"transactionSign: " << jvRequest;
791 SigningForParams signForParams;
793 jvRequest, role, signForParams, validatedLedgerAge, app, ledger);
795 if (!preprocResult.second)
796 return preprocResult.first;
818 using namespace detail;
821 auto j = app.
journal(
"RPCHandler");
822 JLOG(j.debug()) <<
"transactionSubmit: " << jvRequest;
825 SigningForParams signForParams;
827 jvRequest, role, signForParams, validatedLedgerAge, app, ledger);
829 if (!preprocResult.second)
830 return preprocResult.first;
848 rpcINTERNAL,
"Exception occurred during transaction submission.");
860 if (!jvRequest.
isMember(jss::tx_json))
863 Json::Value const& tx_json(jvRequest[jss::tx_json]);
871 if (!tx_json.
isMember(jss::Sequence))
880 "When multi-signing 'tx_json.SigningPubKey' must be empty.");
899 return (a[sfAccount] < b[sfAccount]);
907 return (a[sfAccount] == b[sfAccount]);
910 if (dupIter != signers.
end())
913 err <<
"Duplicate Signers:Signer:Account entries ("
923 [&signingForID](
STObject const& elem) {
924 return elem[sfAccount] == signingForID;
928 err <<
"A Signer may not be the transaction's Account ("
947 auto j = app.
journal(
"RPCHandler");
948 JLOG(j.debug()) <<
"transactionSignFor: " << jvRequest;
951 const char accountField[] =
"account";
953 if (!jvRequest.
isMember(accountField))
957 auto const signerAccountID =
958 parseBase58<AccountID>(jvRequest[accountField].asString());
959 if (!signerAccountID)
965 if (!jvRequest.
isMember(jss::tx_json))
982 using namespace detail;
992 SigningForParams signForParams(
993 *signerAccountID, multiSignPubKey, multiSignature);
996 jvRequest, role, signForParams, validatedLedgerAge, app, ledger);
998 if (!preprocResult.second)
999 return preprocResult.first;
1013 auto& sttx = preprocResult.second;
1025 auto& signers = sttx->peekFieldArray(
sfSigners);
1026 signers.emplace_back(std::move(signer));
1055 auto j = app.
journal(
"RPCHandler");
1056 JLOG(j.debug()) <<
"transactionSubmitMultiSigned: " << jvRequest;
1060 using namespace detail;
1078 return std::move(txJsonResult);
1087 <<
"transactionSubmitMultiSigned: Failed to find source account "
1088 <<
"in current ledger: " <<
toBase58(srcAddressID);
1107 jvRequest, tx_json, srcAddressID, role, app, ledger,
false);
1117 if (!parsedTx_json.
object)
1120 jvResult[
"error"] = parsedTx_json.
error[
"error"];
1121 jvResult[
"error_code"] = parsedTx_json.
error[
"error_code"];
1122 jvResult[
"error_message"] = parsedTx_json.
error[
"error_message"];
1128 std::make_shared<STTx>(std::move(parsedTx_json.
object.get()));
1139 "Exception while serializing transaction: " + reason);
1156 <<
" field. Field must be empty when multi-signing.";
1165 auto const fee = stpTrans->getFieldAmount(
sfFee);
1171 <<
" field. Fees must be specified in XRP.";
1178 <<
" field. Fees must be greater than zero.";
1184 if (!stpTrans->isFieldPresent(
sfSigners))
1189 auto& signers = stpTrans->peekFieldArray(
sfSigners);
1191 if (signers.empty())
1200 obj.isFieldPresent(sfAccount) &&
1201 obj.isFieldPresent(sfSigningPubKey) &&
1202 obj.isFieldPresent(sfTxnSignature) && obj.getCount() == 3);
1203 }) != signers.
end())
1206 "Signers array may only contain Signer entries.");
1230 rpcINTERNAL,
"Exception occurred during transaction submission.");
AccountID const *const multiSigningAcctID_
virtual bool checkSigs() const =0
const SF_Account sfRegularKey(access, STI_ACCOUNT, 8, "RegularKey")
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.
std::string missing_field_message(std::string const &name)
Calculates payment paths.
const SField sfSigners(access, STI_ARRAY, 3, "Signers", SField::sMD_Default, SField::notSigning)
An immutable linear range of bytes.
PublicKey *const multiSignPublicKey_
const SF_Blob sfSigningPubKey(access, STI_VL, 3, "SigningPubKey")
const SF_U32 sfSequence(access, STI_UINT32, 4, "Sequence")
const std::string fieldName
const std::shared_ptr< STTx > second
const SF_Account sfAccount(access, STI_ACCOUNT, 1, "Account")
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
static Json::Value checkPayment(Json::Value const ¶ms, Json::Value &tx_json, AccountID const &srcAddressID, Role const role, Application &app, std::shared_ptr< ReadView const > const &ledger, bool doPath)
XRPAmount scaleFeeLoad(FeeUnit64 fee, LoadFeeTrack const &feeTrack, Fees const &fees, bool bUnlimited)
Json::Value checkFee(Json::Value &request, Role const role, bool doAutoFill, Config const &config, LoadFeeTrack const &feeTrack, TxQ const &txQ, std::shared_ptr< OpenView const > const &ledger)
Fill in the fee on behalf of the client.
Slice slice() const noexcept
bool findPaths(int searchLevel)
Like std::vector<char> but better.
Holds the serialized result of parsing an input JSON object.
bool isLegalNet(STAmount const &value)
const_iterator end() const
void setFieldVL(SField const &field, Blob const &)
const SField sfSigner(access, STI_OBJECT, 16, "Signer")
void setIssuer(AccountID const &uIssuer)
Json::StaticString const & getJsonName() const
virtual OpenLedger & openLedger()=0
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)
STPathSet getBestPaths(int maxPaths, STPath &fullLiquidityPath, STPathSet const &extraPaths, AccountID const &srcIssuer)
AccountID const & getSigner()
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig, bool mustBeFullyCanonical)
Verify a signature on a message.
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.
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.
void computePathRanks(int maxPaths)
Compute the rankings of the paths.
static constexpr FeeUnit32 TRANSACTION_FEE_BASE
static const account_t account
virtual Config & config()=0
static Json::Value sortAndValidateSigners(STArray &signers, AccountID const &signingForID)
AccountID calcAccountID(PublicKey const &pk)
Manages the current fee schedule.
const std::uint32_t tfFullyCanonicalSig
const SF_Blob sfTxnSignature(access, STI_VL, 4, "TxnSignature", SField::sMD_Default, SField::notSigning)
Slice slice() const noexcept
std::map< TxSeq, AccountTxDetails const > getAccountTxs(AccountID const &account, ReadView const &view) const
Returns information about the transactions currently in the queue for the account.
bool isMember(const char *key) const
Return true if the object has a member named key.
boost::optional< STObject > object
The STObject if the parse was successful.
Json::Value rpcError(int iError, Json::Value jvResult)
const SF_Amount sfFee(access, STI_AMOUNT, 8, "Fee")
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
static transactionPreProcessResult transactionPreProcessImpl(Json::Value ¶ms, Role role, SigningForParams &signingArgs, std::chrono::seconds validatedLedgerAge, Application &app, std::shared_ptr< OpenView const > const &ledger)
transactionPreProcessResult(Json::Value &&json)
std::string invalid_field_message(std::string const &name)
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)
Issue const & issue() const
std::pair< PublicKey, SecretKey > keypairForSignature(Json::Value const ¶ms, Json::Value &error)
std::pair< bool, XRPAmount > toDrops(FeeLevel< T > const &level, XRPAmount const &baseFee)
bool isLoadedCluster() const
Json::Value getJson(JsonOptions) const override
bool isSingleSigning() const
T adjacent_find(T... args)
bool isMultiSigning() const
Rules controlling protocol behavior.
static Json::Value checkMultiSignFields(Json::Value const &jvRequest)
transactionPreProcessResult(transactionPreProcessResult &&rhs)
SigningForParams(AccountID const &multiSigningAcctID, PublicKey &multiSignPublicKey, Buffer &multiSignature)
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 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)
const_iterator begin() const
static constexpr int defaultAutoFillFeeMultiplier
Json::Value invalid_field_error(std::string const &name)
virtual HashRouter & getHashRouter()=0
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.