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>(ledger),
245 auto j = app.
journal(
"RPCHandler");
246 JLOG(j.debug()) <<
"transactionSign: build_path: "
284 if (!tx_json.
isMember(jss::TransactionType))
290 if (!tx_json.
isMember(jss::Account))
297 auto const srcAddressID =
298 parseBase58<AccountID>(tx_json[jss::Account].asString());
327 ret.
second = *srcAddressID;
360 static transactionPreProcessResult
368 auto j = app.
journal(
"RPCHandler");
376 !(params.
isMember(jss::offline) && params[jss::offline].
asBool());
394 return std::move(txJsonResult);
409 JLOG(j.debug()) <<
"transactionSign: Failed to find source account "
410 <<
"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);
496 if (parsed.
object == boost::none)
499 err[jss::error] = parsed.
error[jss::error];
500 err[jss::error_code] = parsed.
error[jss::error_code];
501 err[jss::error_message] = parsed.
error[jss::error_message];
510 parsed.
object->setFieldVL(
514 stpTrans = std::make_shared<STTx>(std::move(parsed.
object.get()));
524 "Exception occurred constructing serialized transaction");
543 stpTrans->sign(pk, sk);
561 tpTrans = std::make_shared<Transaction>(stpTrans, reason, app);
562 if (tpTrans->getStatus() !=
NEW)
565 rpcINTERNAL,
"Unable to construct transaction: " + reason);
577 tpTrans->getSTransaction()->add(s);
582 auto sttxNew = std::make_shared<STTx const>(sit);
586 sttxNew->getTransactionID(),
598 std::make_shared<Transaction>(sttxNew, reason, app);
602 if (!tpTransNew->getSTransaction()->isEquivalent(
603 *tpTrans->getSTransaction()))
607 tpTrans = std::move(tpTransNew);
623 ret.
second = std::move(tpTrans);
634 jvResult[jss::tx_blob] =
635 strHex(tpTrans->getSTransaction()->getSerializer().peekData());
644 jvResult[jss::engine_result] = sToken;
645 jvResult[jss::engine_result_code] = tpTrans->getResult();
646 jvResult[jss::engine_result_message] = sHuman;
652 rpcINTERNAL,
"Exception occurred during JSON handling.");
680 if (request.
isMember(jss::fee_mult_max))
682 if (request[jss::fee_mult_max].isInt())
684 mult = request[jss::fee_mult_max].
asInt();
689 jss::fee_mult_max,
"a positive integer"));
696 jss::fee_mult_max,
"a positive integer"));
699 if (request.
isMember(jss::fee_div_max))
701 if (request[jss::fee_div_max].isInt())
703 div = request[jss::fee_div_max].
asInt();
708 jss::fee_div_max,
"a positive integer"));
715 jss::fee_div_max,
"a positive integer"));
729 auto const baseFee = ledger->fees().base;
735 auto const limit = [&]() {
738 mulDiv(feeDefault, ledger->fees().base, ledger->fees().units);
740 Throw<std::overflow_error>(
"mulDiv");
741 auto const result =
mulDiv(drops.second, mult, div);
743 Throw<std::overflow_error>(
"mulDiv");
744 return result.second;
750 ss <<
"Fee of " << fee <<
" exceeds the requested tx limit of "
770 using namespace detail;
772 auto j = app.
journal(
"RPCHandler");
773 JLOG(j.debug()) <<
"transactionSign: " << jvRequest;
776 SigningForParams signForParams;
778 jvRequest, role, signForParams, validatedLedgerAge, app);
780 if (!preprocResult.second)
781 return preprocResult.first;
808 using namespace detail;
811 auto j = app.
journal(
"RPCHandler");
812 JLOG(j.debug()) <<
"transactionSubmit: " << jvRequest;
815 SigningForParams signForParams;
817 jvRequest, role, signForParams, validatedLedgerAge, app);
819 if (!preprocResult.second)
820 return preprocResult.first;
838 rpcINTERNAL,
"Exception occurred during transaction submission.");
850 if (!jvRequest.
isMember(jss::tx_json))
853 Json::Value const& tx_json(jvRequest[jss::tx_json]);
861 if (!tx_json.
isMember(jss::Sequence))
870 "When multi-signing 'tx_json.SigningPubKey' must be empty.");
889 return (a[sfAccount] < b[sfAccount]);
897 return (a[sfAccount] == b[sfAccount]);
900 if (dupIter != signers.end())
903 err <<
"Duplicate Signers:Signer:Account entries ("
913 [&signingForID](
STObject const& elem) {
914 return elem[sfAccount] == signingForID;
918 err <<
"A Signer may not be the transaction's Account ("
937 auto j = app.
journal(
"RPCHandler");
938 JLOG(j.debug()) <<
"transactionSignFor: " << jvRequest;
941 const char accountField[] =
"account";
943 if (!jvRequest.
isMember(accountField))
947 auto const signerAccountID =
948 parseBase58<AccountID>(jvRequest[accountField].asString());
949 if (!signerAccountID)
955 if (!jvRequest.
isMember(jss::tx_json))
972 using namespace detail;
982 SigningForParams signForParams(
983 *signerAccountID, multiSignPubKey, multiSignature);
986 jvRequest, role, signForParams, validatedLedgerAge, app);
988 if (!preprocResult.second)
989 return preprocResult.first;
1003 auto& sttx = preprocResult.second;
1015 auto& signers = sttx->peekFieldArray(
sfSigners);
1016 signers.emplace_back(std::move(signer));
1045 auto j = app.
journal(
"RPCHandler");
1046 JLOG(j.debug()) <<
"transactionSubmitMultiSigned: " << jvRequest;
1050 using namespace detail;
1069 return std::move(txJsonResult);
1078 <<
"transactionSubmitMultiSigned: Failed to find source account "
1079 <<
"in current ledger: " <<
toBase58(srcAddressID);
1097 err =
checkPayment(jvRequest, tx_json, srcAddressID, role, app,
false);
1107 if (!parsedTx_json.
object)
1110 jvResult[
"error"] = parsedTx_json.
error[
"error"];
1111 jvResult[
"error_code"] = parsedTx_json.
error[
"error_code"];
1112 jvResult[
"error_message"] = parsedTx_json.
error[
"error_message"];
1118 std::make_shared<STTx>(std::move(parsedTx_json.
object.get()));
1129 "Exception while serializing transaction: " + reason);
1146 <<
" field. Field must be empty when multi-signing.";
1155 auto const fee = stpTrans->getFieldAmount(
sfFee);
1161 <<
" field. Fees must be specified in XRP.";
1168 <<
" field. Fees must be greater than zero.";
1174 if (!stpTrans->isFieldPresent(
sfSigners))
1179 auto& signers = stpTrans->peekFieldArray(
sfSigners);
1181 if (signers.empty())
1186 signers.begin(), signers.end(), [](
STObject const& obj) {
1190 obj.isFieldPresent(sfAccount) &&
1191 obj.isFieldPresent(sfSigningPubKey) &&
1192 obj.isFieldPresent(sfTxnSignature) && obj.getCount() == 3);
1193 }) != signers.end())
1196 "Signers array may only contain Signer entries.");
1220 rpcINTERNAL,
"Exception occurred during transaction submission.");
AccountID const *const multiSigningAcctID_
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.
std::string missing_field_message(std::string const &name)
Calculates payment paths.
unsigned int getAPIVersionNumber(Json::Value const &jv)
Retrieve the api version number from the json value.
An immutable linear range of bytes.
const SF_ACCOUNT sfRegularKey
PublicKey *const multiSignPublicKey_
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.
XRPAmount scaleFeeLoad(FeeUnit64 fee, LoadFeeTrack const &feeTrack, Fees const &fees, bool bUnlimited)
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
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)
void setFieldVL(SField const &field, Blob const &)
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.
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)
XRPAmount toDrops(FeeLevel< T > const &level, XRPAmount const &baseFee)
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.
void computePathRanks(int maxPaths)
Compute the rankings of the paths.
static constexpr FeeUnit32 TRANSACTION_FEE_BASE
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
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.
boost::optional< STObject > object
The STObject if the parse was successful.
Json::Value rpcError(int iError, Json::Value jvResult)
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
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)
Issue const & issue() const
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)
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
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.