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