rippled
Loading...
Searching...
No Matches
Submit.cpp
1#include <xrpld/app/ledger/LedgerMaster.h>
2#include <xrpld/app/misc/Transaction.h>
3#include <xrpld/app/tx/apply.h>
4#include <xrpld/rpc/Context.h>
5#include <xrpld/rpc/detail/TransactionSign.h>
6
7#include <xrpl/protocol/ErrorCodes.h>
8#include <xrpl/protocol/RPCErr.h>
9#include <xrpl/resource/Fees.h>
10
11namespace xrpl {
12
15{
16 return NetworkOPs::doFailHard(context.params.isMember("fail_hard") && context.params["fail_hard"].asBool());
17}
18
19// {
20// tx_blob: <string> XOR tx_json: <object>,
21// secret: <secret>
22// }
25{
27
28 if (!context.params.isMember(jss::tx_blob))
29 {
30 auto const failType = getFailHard(context);
31
32 if (context.role != Role::ADMIN && !context.app.config().canSign())
33 return RPC::make_error(rpcNOT_SUPPORTED, "Signing is not supported by this server.");
34
35 auto ret = RPC::transactionSubmit(
36 context.params,
37 context.apiVersion,
38 failType,
39 context.role,
41 context.app,
43
44 ret[jss::deprecated] =
45 "Signing support in the 'submit' command has been "
46 "deprecated and will be removed in a future version "
47 "of the server. Please migrate to a standalone "
48 "signing tool.";
49
50 return ret;
51 }
52
53 Json::Value jvResult;
54
55 auto ret = strUnHex(context.params[jss::tx_blob].asString());
56
57 if (!ret || !ret->size())
59
60 SerialIter sitTrans(makeSlice(*ret));
61
63
64 try
65 {
66 stTx = std::make_shared<STTx const>(std::ref(sitTrans));
67 }
68 catch (std::exception& e)
69 {
70 jvResult[jss::error] = "invalidTransaction";
71 jvResult[jss::error_exception] = e.what();
72
73 return jvResult;
74 }
75
76 {
77 if (!context.app.checkSigs())
78 forceValidity(context.app.getHashRouter(), stTx->getTransactionID(), Validity::SigGoodOnly);
79 auto [validity, reason] = checkValidity(
80 context.app.getHashRouter(), *stTx, context.ledgerMaster.getCurrentLedger()->rules(), context.app.config());
81 if (validity != Validity::Valid)
82 {
83 jvResult[jss::error] = "invalidTransaction";
84 jvResult[jss::error_exception] = "fails local checks: " + reason;
85
86 return jvResult;
87 }
88 }
89
90 std::string reason;
91 auto transaction = std::make_shared<Transaction>(stTx, reason, context.app);
92 if (transaction->getStatus() != NEW)
93 {
94 jvResult[jss::error] = "invalidTransaction";
95 jvResult[jss::error_exception] = "fails local checks: " + reason;
96
97 return jvResult;
98 }
99
100 try
101 {
102 auto const failType = getFailHard(context);
103
104 context.netOps.processTransaction(transaction, isUnlimited(context.role), true, failType);
105 }
106 catch (std::exception& e)
107 {
108 jvResult[jss::error] = "internalSubmit";
109 jvResult[jss::error_exception] = e.what();
110
111 return jvResult;
112 }
113
114 try
115 {
116 jvResult[jss::tx_json] = transaction->getJson(JsonOptions::none);
117 jvResult[jss::tx_blob] = strHex(transaction->getSTransaction()->getSerializer().peekData());
118
119 if (temUNCERTAIN != transaction->getResult())
120 {
121 std::string sToken;
122 std::string sHuman;
123
124 transResultInfo(transaction->getResult(), sToken, sHuman);
125
126 jvResult[jss::engine_result] = sToken;
127 jvResult[jss::engine_result_code] = transaction->getResult();
128 jvResult[jss::engine_result_message] = sHuman;
129
130 auto const submitResult = transaction->getSubmitResult();
131
132 jvResult[jss::accepted] = submitResult.any();
133 jvResult[jss::applied] = submitResult.applied;
134 jvResult[jss::broadcast] = submitResult.broadcast;
135 jvResult[jss::queued] = submitResult.queued;
136 jvResult[jss::kept] = submitResult.kept;
137
138 if (auto currentLedgerState = transaction->getCurrentLedgerState())
139 {
140 jvResult[jss::account_sequence_next] = safe_cast<Json::Value::UInt>(currentLedgerState->accountSeqNext);
141 jvResult[jss::account_sequence_available] =
142 safe_cast<Json::Value::UInt>(currentLedgerState->accountSeqAvail);
143 jvResult[jss::open_ledger_cost] = to_string(currentLedgerState->minFeeRequired);
144 jvResult[jss::validated_ledger_index] =
145 safe_cast<Json::Value::UInt>(currentLedgerState->validatedLedger);
146 }
147 }
148
149 return jvResult;
150 }
151 catch (std::exception& e)
152 {
153 jvResult[jss::error] = "internalJson";
154 jvResult[jss::error_exception] = e.what();
155
156 return jvResult;
157 }
158}
159
160} // namespace xrpl
Represents a JSON value.
Definition json_value.h:131
std::string asString() const
Returns the unquoted string value.
bool asBool() const
bool isMember(char const *key) const
Return true if the object has a member named key.
virtual HashRouter & getHashRouter()=0
virtual Config & config()=0
virtual bool checkSigs() const =0
bool canSign() const
Definition Config.h:324
std::chrono::seconds getValidatedLedgerAge()
std::shared_ptr< ReadView const > getCurrentLedger()
static FailHard doFailHard(bool noMeansDont)
Definition NetworkOPs.h:76
virtual void processTransaction(std::shared_ptr< Transaction > &transaction, bool bUnlimited, bool bLocal, FailHard failType)=0
Process transactions as they arrive from the network or which are submitted by clients.
T is_same_v
Json::Value transactionSubmit(Json::Value jvRequest, unsigned apiVersion, NetworkOPs::FailHard failType, Role role, std::chrono::seconds validatedLedgerAge, Application &app, ProcessTransactionFn const &processTransaction)
Returns a Json::objectValue.
ProcessTransactionFn getProcessTxnFn(NetworkOPs &netOPs)
Json::Value make_error(error_code_i code)
Returns a new json object that reflects the error code.
Charge const feeMediumBurdenRPC
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
@ Valid
Signature and local checks are good / passed.
@ SigGoodOnly
Signature is good, but local checks fail.
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:598
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:11
bool transResultInfo(TER code, std::string &token, std::string &text)
Definition TER.cpp:228
static NetworkOPs::FailHard getFailHard(RPC::JsonContext const &context)
Definition Submit.cpp:14
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
Json::Value rpcError(error_code_i iError)
Definition RPCErr.cpp:12
std::pair< Validity, std::string > checkValidity(HashRouter &router, STTx const &tx, Rules const &rules, Config const &config)
Checks transaction signature and local checks.
Definition apply.cpp:21
@ temUNCERTAIN
Definition TER.h:104
Json::Value doSubmit(RPC::JsonContext &)
Definition Submit.cpp:24
void forceValidity(HashRouter &router, uint256 const &txid, Validity validity)
Sets the validity of a given transaction in the cache.
Definition apply.cpp:89
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)
Definition Slice.h:214
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
Definition Role.cpp:96
@ rpcNOT_SUPPORTED
Definition ErrorCodes.h:113
@ rpcINVALID_PARAMS
Definition ErrorCodes.h:65
T ref(T... args)
Application & app
Definition Context.h:22
Resource::Charge & loadType
Definition Context.h:23
unsigned int apiVersion
Definition Context.h:30
LedgerMaster & ledgerMaster
Definition Context.h:25
NetworkOPs & netOps
Definition Context.h:24
Json::Value params
Definition Context.h:44
T what(T... args)