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 ripple {
12
15{
17 context.params.isMember("fail_hard") &&
18 context.params["fail_hard"].asBool());
19}
20
21// {
22// tx_blob: <string> XOR tx_json: <object>,
23// secret: <secret>
24// }
27{
29
30 if (!context.params.isMember(jss::tx_blob))
31 {
32 auto const failType = getFailHard(context);
33
34 if (context.role != Role::ADMIN && !context.app.config().canSign())
35 return RPC::make_error(
36 rpcNOT_SUPPORTED, "Signing is not supported by this server.");
37
38 auto ret = RPC::transactionSubmit(
39 context.params,
40 context.apiVersion,
41 failType,
42 context.role,
44 context.app,
46
47 ret[jss::deprecated] =
48 "Signing support in the 'submit' command has been "
49 "deprecated and will be removed in a future version "
50 "of the server. Please migrate to a standalone "
51 "signing tool.";
52
53 return ret;
54 }
55
56 Json::Value jvResult;
57
58 auto ret = strUnHex(context.params[jss::tx_blob].asString());
59
60 if (!ret || !ret->size())
62
63 SerialIter sitTrans(makeSlice(*ret));
64
66
67 try
68 {
69 stTx = std::make_shared<STTx const>(std::ref(sitTrans));
70 }
71 catch (std::exception& e)
72 {
73 jvResult[jss::error] = "invalidTransaction";
74 jvResult[jss::error_exception] = e.what();
75
76 return jvResult;
77 }
78
79 {
80 if (!context.app.checkSigs())
82 context.app.getHashRouter(),
83 stTx->getTransactionID(),
85 auto [validity, reason] = checkValidity(
86 context.app.getHashRouter(),
87 *stTx,
88 context.ledgerMaster.getCurrentLedger()->rules(),
89 context.app.config());
90 if (validity != Validity::Valid)
91 {
92 jvResult[jss::error] = "invalidTransaction";
93 jvResult[jss::error_exception] = "fails local checks: " + reason;
94
95 return jvResult;
96 }
97 }
98
99 std::string reason;
100 auto transaction = std::make_shared<Transaction>(stTx, reason, context.app);
101 if (transaction->getStatus() != NEW)
102 {
103 jvResult[jss::error] = "invalidTransaction";
104 jvResult[jss::error_exception] = "fails local checks: " + reason;
105
106 return jvResult;
107 }
108
109 try
110 {
111 auto const failType = getFailHard(context);
112
114 transaction, isUnlimited(context.role), true, failType);
115 }
116 catch (std::exception& e)
117 {
118 jvResult[jss::error] = "internalSubmit";
119 jvResult[jss::error_exception] = e.what();
120
121 return jvResult;
122 }
123
124 try
125 {
126 jvResult[jss::tx_json] = transaction->getJson(JsonOptions::none);
127 jvResult[jss::tx_blob] =
128 strHex(transaction->getSTransaction()->getSerializer().peekData());
129
130 if (temUNCERTAIN != transaction->getResult())
131 {
132 std::string sToken;
133 std::string sHuman;
134
135 transResultInfo(transaction->getResult(), sToken, sHuman);
136
137 jvResult[jss::engine_result] = sToken;
138 jvResult[jss::engine_result_code] = transaction->getResult();
139 jvResult[jss::engine_result_message] = sHuman;
140
141 auto const submitResult = transaction->getSubmitResult();
142
143 jvResult[jss::accepted] = submitResult.any();
144 jvResult[jss::applied] = submitResult.applied;
145 jvResult[jss::broadcast] = submitResult.broadcast;
146 jvResult[jss::queued] = submitResult.queued;
147 jvResult[jss::kept] = submitResult.kept;
148
149 if (auto currentLedgerState = transaction->getCurrentLedgerState())
150 {
151 jvResult[jss::account_sequence_next] =
152 safe_cast<Json::Value::UInt>(
153 currentLedgerState->accountSeqNext);
154 jvResult[jss::account_sequence_available] =
155 safe_cast<Json::Value::UInt>(
156 currentLedgerState->accountSeqAvail);
157 jvResult[jss::open_ledger_cost] =
158 to_string(currentLedgerState->minFeeRequired);
159 jvResult[jss::validated_ledger_index] =
160 safe_cast<Json::Value::UInt>(
161 currentLedgerState->validatedLedger);
162 }
163 }
164
165 return jvResult;
166 }
167 catch (std::exception& e)
168 {
169 jvResult[jss::error] = "internalJson";
170 jvResult[jss::error_exception] = e.what();
171
172 return jvResult;
173 }
174}
175
176} // namespace ripple
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 Config & config()=0
virtual bool checkSigs() const =0
virtual HashRouter & getHashRouter()=0
bool canSign() const
Definition Config.h:329
std::shared_ptr< ReadView const > getCurrentLedger()
std::chrono::seconds getValidatedLedgerAge()
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 make_error(error_code_i code)
Returns a new json object that reflects the error code.
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)
Charge const feeMediumBurdenRPC
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
@ rpcNOT_SUPPORTED
Definition ErrorCodes.h:113
@ rpcINVALID_PARAMS
Definition ErrorCodes.h:65
static NetworkOPs::FailHard getFailHard(RPC::JsonContext const &context)
Definition Submit.cpp:14
Json::Value rpcError(int iError)
Definition RPCErr.cpp:12
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
Definition Role.cpp:106
Json::Value doSubmit(RPC::JsonContext &)
Definition Submit.cpp:26
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:11
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:225
void forceValidity(HashRouter &router, uint256 const &txid, Validity validity)
Sets the validity of a given transaction in the cache.
Definition apply.cpp:99
@ 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:611
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:25
bool transResultInfo(TER code, std::string &token, std::string &text)
Definition TER.cpp:230
@ temUNCERTAIN
Definition TER.h:104
T ref(T... args)
unsigned int apiVersion
Definition Context.h:30
Resource::Charge & loadType
Definition Context.h:23
Application & app
Definition Context.h:22
LedgerMaster & ledgerMaster
Definition Context.h:25
NetworkOPs & netOps
Definition Context.h:24
T what(T... args)