1#include <xrpld/app/ledger/LedgerMaster.h>
2#include <xrpld/app/ledger/OpenLedger.h>
3#include <xrpld/app/misc/Transaction.h>
4#include <xrpld/app/misc/TxQ.h>
5#include <xrpld/rpc/Context.h>
6#include <xrpld/rpc/DeliveredAmount.h>
7#include <xrpld/rpc/GRPCHandlers.h>
8#include <xrpld/rpc/MPTokenIssuanceID.h>
9#include <xrpld/rpc/detail/TransactionSign.h>
11#include <xrpl/core/HashRouter.h>
12#include <xrpl/core/NetworkIDService.h>
13#include <xrpl/protocol/ErrorCodes.h>
14#include <xrpl/protocol/NFTSyntheticSerializer.h>
15#include <xrpl/protocol/RPCErr.h>
16#include <xrpl/protocol/STParsedJSON.h>
17#include <xrpl/resource/Fees.h>
18#include <xrpl/tx/apply.h>
22static Expected<std::uint32_t, Json::Value>
26 bool const hasTicketSeq = tx_json.
isMember(sfTicketSequence.jsonName);
27 auto const& accountStr = tx_json[jss::Account];
28 if (!accountStr.isString())
35 auto const srcAddressID = parseBase58<AccountID>(accountStr.asString());
36 if (!srcAddressID.has_value())
43 if (!hasTicketSeq && !sle)
46 <<
"Failed to find source account "
47 <<
"in current ledger: " <<
toBase58(*srcAddressID);
58 if (!sigObject.
isMember(jss::SigningPubKey))
61 sigObject[jss::SigningPubKey] =
"";
64 if (sigObject.
isMember(jss::Signers))
66 if (!sigObject[jss::Signers].isArray())
69 for (
unsigned index = 0; index < sigObject[jss::Signers].
size(); index++)
71 auto& signer = sigObject[jss::Signers][index];
72 if (!signer.isObject() || !signer.isMember(jss::Signer) ||
73 !signer[jss::Signer].isObject())
76 if (!signer[jss::Signer].isMember(jss::SigningPubKey))
79 signer[jss::Signer][jss::SigningPubKey] =
"";
82 if (!signer[jss::Signer].isMember(jss::TxnSignature))
85 signer[jss::Signer][jss::TxnSignature] =
"";
87 else if (signer[jss::Signer][jss::TxnSignature] !=
"")
95 if (!sigObject.
isMember(jss::TxnSignature))
98 sigObject[jss::TxnSignature] =
"";
100 else if (sigObject[jss::TxnSignature] !=
"")
123 if (feeOrError.isMember(jss::error))
125 tx_json[jss::Fee] = feeOrError;
131 if (!tx_json.
isMember(jss::Sequence))
136 tx_json[sfSequence.jsonName] = *seq;
139 if (!tx_json.
isMember(jss::NetworkID))
142 if (networkId > 1024)
143 tx_json[jss::NetworkID] =
to_string(networkId);
161 auto const tx_blob = params[jss::tx_blob];
162 if (!tx_blob.isString())
167 auto unHexed =
strUnHex(tx_blob.asString());
168 if (!unHexed || unHexed->empty())
181 else if (params.
isMember(jss::tx_json))
183 tx_json = params[jss::tx_json];
195 if (!tx_json.
isMember(jss::TransactionType))
200 if (!tx_json.
isMember(jss::Account))
215 context.
app, view, transaction->getSTransaction(),
tapDRY_RUN, context.
j);
217 jvResult[jss::applied] = result.applied;
218 jvResult[jss::ledger_index] = view.
seq();
220 bool const isBinaryOutput = context.
params.
get(jss::binary,
false).
asBool();
228 jvResult[jss::engine_result] = token;
229 jvResult[jss::engine_result_code] = result.ter;
230 jvResult[jss::engine_result_message] = message;
236 jvResult[jss::engine_result] =
"unknown";
237 jvResult[jss::engine_result_code] = result.ter;
238 jvResult[jss::engine_result_message] =
"unknown";
242 if (token ==
"tesSUCCESS")
244 jvResult[jss::engine_result_message] =
"The simulated transaction would have been applied.";
251 auto const metaBlob = result.metadata->getAsObject().getSerializer().getData();
258 jvResult[jss::meta], view, transaction->getSTransaction(), *result.metadata);
260 jvResult, transaction->getSTransaction(), *result.metadata);
262 jvResult[jss::meta], transaction->getSTransaction(), *result.metadata);
268 auto const txBlob = transaction->getSTransaction()->getSerializer().getData();
296 for (
auto const field : {jss::secret, jss::seed, jss::seed_hex, jss::passphrase})
310 if (
auto error =
autofillTx(tx_json, context))
314 if (!parsed.
object.has_value())
325 jvResult[jss::error] =
"invalidTransaction";
326 jvResult[jss::error_exception] = e.
what();
330 if (stTx->getTxnType() == ttBATCH)
346 jvResult[jss::error] =
"internalSimulate";
347 jvResult[jss::error_exception] = e.
what();
UInt size() const
Number of values in array or object.
bool isMember(char const *key) const
Return true if the object has a member named key.
Value get(UInt index, Value const &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
virtual Config & config()=0
virtual std::uint32_t getNetworkID() const noexcept=0
Get the configured network ID.
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=JsonOptions::none) 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
virtual beast::Journal getJournal(std::string const &name)=0
virtual OpenLedger & getOpenLedger()=0
virtual NetworkIDService & getNetworkIDService()=0
virtual LoadFeeTrack & getFeeTrack()=0
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.
SeqProxy nextQueuableSeq(std::shared_ptr< SLE const > const &sleAccount) const
Return the next sequence that would go in the TxQ for an account.
@ objectValue
object value (collection of name/value pairs).
Json::Value invalid_field_error(std::string const &name)
Json::Value missing_field_error(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)
void insertMPTokenIssuanceID(Json::Value &response, std::shared_ptr< STTx const > const &transaction, TxMeta const &transactionMeta)
void insertDeliveredAmount(Json::Value &meta, ReadView const &, std::shared_ptr< STTx const > const &serializedTx, TxMeta const &)
Add a delivered_amount field to the meta input/output parameter.
Json::Value make_param_error(std::string const &message)
Returns a new json object that indicates invalid parameters.
void insertNFTSyntheticInJson(Json::Value &, std::shared_ptr< STTx const > const &, TxMeta const &)
Adds common synthetic fields to transaction-related JSON responses.
std::string invalid_field_message(std::string const &name)
Json::Value make_error(error_code_i code)
Returns a new json object that reflects the error code.
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 to_string(base_uint< Bits, Tag > const &a)
std::string strHex(FwdIt begin, FwdIt end)
static std::optional< Json::Value > autofillTx(Json::Value &tx_json, RPC::JsonContext &context)
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
bool transResultInfo(TER code, std::string &token, std::string &text)
static Json::Value simulateTxn(RPC::JsonContext &context, std::shared_ptr< Transaction > transaction)
static Expected< std::uint32_t, Json::Value > getAutofillSequence(Json::Value const &tx_json, RPC::JsonContext &context)
static std::optional< Json::Value > autofillSignature(Json::Value &sigObject)
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
static Json::Value getTxJsonFromParams(Json::Value const ¶ms)
Json::Value rpcError(error_code_i iError)
Json::Value doSimulate(RPC::JsonContext &)
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)
Resource::Charge & loadType