20#include <xrpld/app/ledger/LedgerMaster.h>
21#include <xrpld/app/ledger/OpenLedger.h>
22#include <xrpld/app/misc/HashRouter.h>
23#include <xrpld/app/misc/Transaction.h>
24#include <xrpld/app/tx/apply.h>
25#include <xrpld/rpc/Context.h>
26#include <xrpld/rpc/GRPCHandlers.h>
27#include <xrpld/rpc/detail/RPCHelpers.h>
28#include <xrpld/rpc/detail/TransactionSign.h>
29#include <xrpl/protocol/ErrorCodes.h>
30#include <xrpl/protocol/RPCErr.h>
31#include <xrpl/protocol/STParsedJSON.h>
32#include <xrpl/resource/Fees.h>
36static Expected<std::uint32_t, Json::Value>
40 bool const hasTicketSeq = tx_json.
isMember(sfTicketSequence.jsonName);
41 auto const& accountStr = tx_json[jss::Account];
42 if (!accountStr.isString())
49 auto const srcAddressID = parseBase58<AccountID>(accountStr.asString());
50 if (!srcAddressID.has_value())
58 if (!hasTicketSeq && !sle)
61 <<
"Failed to find source account "
62 <<
"in current ledger: " <<
toBase58(*srcAddressID);
85 if (feeOrError.isMember(jss::error))
87 tx_json[jss::Fee] = feeOrError;
90 if (!tx_json.
isMember(jss::SigningPubKey))
93 tx_json[jss::SigningPubKey] =
"";
98 if (!tx_json[jss::Signers].isArray())
101 for (
unsigned index = 0; index < tx_json[jss::Signers].
size(); index++)
103 auto& signer = tx_json[jss::Signers][index];
104 if (!signer.isObject() || !signer.isMember(jss::Signer) ||
105 !signer[jss::Signer].isObject())
109 if (!signer[jss::Signer].isMember(jss::SigningPubKey))
112 signer[jss::Signer][jss::SigningPubKey] =
"";
115 if (!signer[jss::Signer].isMember(jss::TxnSignature))
118 signer[jss::Signer][jss::TxnSignature] =
"";
120 else if (signer[jss::Signer][jss::TxnSignature] !=
"")
128 if (!tx_json.
isMember(jss::TxnSignature))
131 tx_json[jss::TxnSignature] =
"";
133 else if (tx_json[jss::TxnSignature] !=
"")
139 if (!tx_json.
isMember(jss::Sequence))
144 tx_json[sfSequence.jsonName] = *seq;
147 if (!tx_json.
isMember(jss::NetworkID))
150 if (networkId > 1024)
151 tx_json[jss::NetworkID] =
to_string(networkId);
167 "Can only include one of `tx_blob` and `tx_json`.");
170 auto const tx_blob = params[jss::tx_blob];
171 if (!tx_blob.isString())
176 auto unHexed =
strUnHex(tx_blob.asString());
177 if (!unHexed || unHexed->empty())
191 else if (params.
isMember(jss::tx_json))
193 tx_json = params[jss::tx_json];
202 "Neither `tx_blob` nor `tx_json` included.");
206 if (!tx_json.
isMember(jss::TransactionType))
211 if (!tx_json.
isMember(jss::Account))
228 transaction->getSTransaction(),
232 jvResult[jss::applied] = result.applied;
233 jvResult[jss::ledger_index] = view.
seq();
235 const bool isBinaryOutput = context.
params.
get(jss::binary,
false).
asBool();
243 jvResult[jss::engine_result] = token;
244 jvResult[jss::engine_result_code] = result.ter;
245 jvResult[jss::engine_result_message] = message;
251 jvResult[jss::engine_result] =
"unknown";
252 jvResult[jss::engine_result_code] = result.ter;
253 jvResult[jss::engine_result_message] =
"unknown";
257 if (token ==
"tesSUCCESS")
259 jvResult[jss::engine_result_message] =
260 "The simulated transaction would have been applied.";
267 auto const metaBlob =
268 result.metadata->getAsObject().getSerializer().getData();
280 transaction->getSTransaction()->getSerializer().getData();
309 for (
auto const field :
310 {jss::secret, jss::seed, jss::seed_hex, jss::passphrase})
324 if (
auto error =
autofillTx(tx_json, context))
328 if (!parsed.
object.has_value())
334 stTx = std::make_shared<STTx>(std::move(parsed.
object.value()));
339 jvResult[jss::error] =
"invalidTransaction";
340 jvResult[jss::error_exception] = e.
what();
345 auto transaction = std::make_shared<Transaction>(stTx, reason, context.
app);
355 jvResult[jss::error] =
"internalSimulate";
356 jvResult[jss::error_exception] = e.
what();
Value get(UInt index, const Value &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
UInt size() const
Number of values in array or object.
bool isMember(const char *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
std::shared_ptr< OpenView const > current() const
Returns a view to the current open ledger.
Writable ledger view that accumulates state and tx changes.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
Json::Value getJson(JsonOptions options) const override
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.
constexpr std::uint32_t value() const
SeqProxy nextQueuableSeq(std::shared_ptr< SLE const > const &sleAccount) const
Return the next sequence that would go in the TxQ for an account.
ApplyResult apply(Application &app, OpenView &view, std::shared_ptr< STTx const > const &tx, ApplyFlags flags, beast::Journal j)
Add a new transaction to the open ledger, hold it in the queue, or reject it.
@ objectValue
object value (collection of name/value pairs).
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)
Json::Value make_param_error(std::string const &message)
Returns a new json object that indicates invalid parameters.
std::string invalid_field_message(std::string const &name)
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 object_field_error(std::string const &name)
Json::Value missing_field_error(std::string const &name)
Charge const feeMediumBurdenRPC
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.
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
static std::optional< Json::Value > autofillTx(Json::Value &tx_json, RPC::JsonContext &context)
static Expected< std::uint32_t, Json::Value > getAutofillSequence(Json::Value const &tx_json, RPC::JsonContext &context)
Json::Value doSimulate(RPC::JsonContext &)
static Json::Value getTxJsonFromParams(Json::Value const ¶ms)
Json::Value rpcError(int iError)
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)
static Json::Value simulateTxn(RPC::JsonContext &context, std::shared_ptr< Transaction > transaction)
std::string to_string(base_uint< Bits, Tag > const &a)
bool transResultInfo(TER code, std::string &token, std::string &text)
Resource::Charge & loadType