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/MPTokenIssuanceID.h>
8#include <xrpld/rpc/detail/TransactionSign.h>
10#include <xrpl/basics/Log.h>
11#include <xrpl/basics/Number.h>
12#include <xrpl/basics/Slice.h>
13#include <xrpl/basics/StringUtilities.h>
14#include <xrpl/basics/strHex.h>
15#include <xrpl/core/NetworkIDService.h>
16#include <xrpl/core/ServiceRegistry.h>
17#include <xrpl/json/json_value.h>
18#include <xrpl/ledger/ApplyView.h>
19#include <xrpl/ledger/OpenView.h>
20#include <xrpl/protocol/AccountID.h>
21#include <xrpl/protocol/ErrorCodes.h>
22#include <xrpl/protocol/Indexes.h>
23#include <xrpl/protocol/NFTSyntheticSerializer.h>
24#include <xrpl/protocol/RPCErr.h>
25#include <xrpl/protocol/SField.h>
26#include <xrpl/protocol/STParsedJSON.h>
27#include <xrpl/protocol/Serializer.h>
28#include <xrpl/protocol/TER.h>
29#include <xrpl/protocol/TxFormats.h>
30#include <xrpl/protocol/jss.h>
31#include <xrpl/resource/Fees.h>
45static std::expected<std::uint32_t, json::Value>
49 bool const hasTicketSeq = txJson.
isMember(sfTicketSequence.jsonName);
50 auto const& accountStr = txJson[jss::Account];
51 if (!accountStr.isString())
59 if (!srcAddressID.has_value())
66 if (!hasTicketSeq && !sle)
69 <<
"Failed to find source account "
70 <<
"in current ledger: " <<
toBase58(*srcAddressID);
81 if (!sigObject.
isMember(jss::SigningPubKey))
84 sigObject[jss::SigningPubKey] =
"";
87 if (sigObject.
isMember(jss::Signers))
89 if (!sigObject[jss::Signers].isArray())
92 for (
unsigned index = 0; index < sigObject[jss::Signers].
size(); index++)
94 auto& signer = sigObject[jss::Signers][index];
95 if (!signer.isObject() || !signer.isMember(jss::Signer) ||
96 !signer[jss::Signer].isObject())
99 if (!signer[jss::Signer].isMember(jss::SigningPubKey))
102 signer[jss::Signer][jss::SigningPubKey] =
"";
105 if (!signer[jss::Signer].isMember(jss::TxnSignature))
108 signer[jss::Signer][jss::TxnSignature] =
"";
110 else if (signer[jss::Signer][jss::TxnSignature] !=
"")
118 if (!sigObject.
isMember(jss::TxnSignature))
121 sigObject[jss::TxnSignature] =
"";
123 else if (sigObject[jss::TxnSignature] !=
"")
146 if (feeOrError.isMember(jss::error))
148 txJson[jss::Fee] = feeOrError;
154 if (!txJson.
isMember(jss::Sequence))
159 txJson[sfSequence.jsonName] = *seq;
162 if (!txJson.
isMember(jss::NetworkID))
165 if (networkId > 1024)
166 txJson[jss::NetworkID] =
to_string(networkId);
184 auto const txBlob = params[jss::tx_blob];
185 if (!txBlob.isString())
190 auto unHexed =
strUnHex(txBlob.asString());
191 if (!unHexed || unHexed->empty())
204 else if (params.
isMember(jss::tx_json))
206 txJson = params[jss::tx_json];
218 if (!txJson.
isMember(jss::TransactionType))
238 context.
app, view, transaction->getSTransaction(),
TapDryRun, context.
j);
240 jvResult[jss::applied] = result.applied;
241 jvResult[jss::ledger_index] = view.
seq();
243 bool const isBinaryOutput = context.
params.
get(jss::binary,
false).
asBool();
251 jvResult[jss::engine_result] = token;
252 jvResult[jss::engine_result_code] = result.ter;
253 jvResult[jss::engine_result_message] = message;
259 jvResult[jss::engine_result] =
"unknown";
260 jvResult[jss::engine_result_code] = result.ter;
261 jvResult[jss::engine_result_message] =
"unknown";
265 if (token ==
"tesSUCCESS")
267 jvResult[jss::engine_result_message] =
"The simulated transaction would have been applied.";
274 auto const metaBlob = result.metadata->getAsObject().getSerializer().getData();
281 jvResult[jss::meta], view, transaction->getSTransaction(), *result.metadata);
283 jvResult, transaction->getSTransaction(), *result.metadata);
285 jvResult[jss::meta], transaction->getSTransaction(), *result.metadata);
291 auto const txBlob = transaction->getSTransaction()->getSerializer().getData();
319 for (
auto const field : {jss::secret, jss::seed, jss::seed_hex, jss::passphrase})
337 if (!parsed.
object.has_value())
348 jvResult[jss::error] =
"invalidTransaction";
349 jvResult[jss::error_exception] = e.
what();
353 if (stTx->getTxnType() == ttBATCH)
369 jvResult[jss::error] =
"internalSimulate";
370 jvResult[jss::error_exception] = e.
what();
Value get(UInt index, Value const &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(char const *key) const
Return true if the object has a member named key.
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.
std::shared_ptr< STLedgerEntry const > const_pointer
json::Value getJson(JsonOptions=JsonOptions::Values::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
SeqProxy nextQueuableSeq(SLE::const_ref 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.
@ Object
object value (collection of name/value pairs).
void insertMPTokenIssuanceID(json::Value &response, std::shared_ptr< STTx const > const &transaction, TxMeta const &transactionMeta)
json::Value objectFieldError(std::string const &name)
std::string invalidFieldMessage(std::string const &name)
json::Value makeError(ErrorCodeI code)
Returns a new json object that reflects the error code.
void insertNFTSyntheticInJson(json::Value &, std::shared_ptr< STTx const > const &, TxMeta const &)
Adds common synthetic fields to transaction-related JSON responses.
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 invalidFieldError(std::string const &name)
json::Value makeParamError(std::string const &message)
Returns a new json object that indicates invalid parameters.
json::Value missingFieldError(std::string const &name)
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.
Charge const kFeeMediumBurdenRpc
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
std::string strHex(FwdIt begin, FwdIt end)
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
bool transResultInfo(TER code, std::string &token, std::string &text)
static std::expected< std::uint32_t, json::Value > getAutofillSequence(json::Value const &txJson, RPC::JsonContext &context)
static json::Value getTxJsonFromParams(json::Value const ¶ms)
std::string to_string(BaseUInt< Bits, Tag > const &a)
json::Value rpcError(ErrorCodeI iError)
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
static std::optional< json::Value > autofillSignature(json::Value &sigObject)
json::Value doSimulate(RPC::JsonContext &)
static std::optional< json::Value > autofillTx(json::Value &txJson, RPC::JsonContext &context)
static json::Value simulateTxn(RPC::JsonContext &context, std::shared_ptr< Transaction > transaction)
std::enable_if_t< std::is_same_v< T, char >||std::is_same_v< T, unsigned char >, Slice > makeSlice(std::array< T, N > const &a)
Resource::Charge & loadType