rippled
Loading...
Searching...
No Matches
TransactionBase.h
1#pragma once
2
3#include <xrpl/protocol/SField.h>
4#include <xrpl/protocol/STAccount.h>
5#include <xrpl/protocol/STArray.h>
6#include <xrpl/protocol/STObject.h>
7#include <xrpl/protocol/STTx.h>
8#include <xrpl/protocol/TxFormats.h>
9#include <xrpl/protocol_autogen/STObjectValidation.h>
10#include <xrpl/protocol_autogen/Utils.h>
11
12#include <optional>
13#include <string>
14
16
25{
26public:
32 {
33 }
34
39 [[nodiscard]]
40 bool
41 validate(std::string& reason) const
42 {
44 *tx_, TxFormats::getInstance().findByType(tx_->getTxnType())->getSOTemplate()))
45 {
46 // LCOV_EXCL_START
47 reason = "Transaction failed schema validation";
48 return false;
49 // LCOV_EXCL_STOP
50 }
51
52 // Pseudo transactions are not submitted to the network
53 if (isPseudoTx(*tx_))
54 {
55 return true;
56 }
57 return passesLocalChecks(*tx_, reason);
58 }
59
64 [[nodiscard]]
67 {
68 return tx_->getTxnType();
69 }
70
77 [[nodiscard]]
79 getAccount() const
80 {
81 return tx_->at(sfAccount);
82 }
83
90 [[nodiscard]]
93 {
94 return tx_->at(sfSequence);
95 }
96
103 [[nodiscard]]
105 getFee() const
106 {
107 return tx_->at(sfFee);
108 }
109
116 [[nodiscard]]
117 Blob
119 {
120 return tx_->getFieldVL(sfSigningPubKey);
121 }
122
129 [[nodiscard]]
131 getFlags() const
132 {
133 if (tx_->isFieldPresent(sfFlags))
134 return tx_->at(sfFlags);
135 return std::nullopt;
136 }
137
142 [[nodiscard]]
143 bool
144 hasFlags() const
145 {
146 return tx_->isFieldPresent(sfFlags);
147 }
148
155 [[nodiscard]]
158 {
159 if (tx_->isFieldPresent(sfSourceTag))
160 return tx_->at(sfSourceTag);
161 return std::nullopt;
162 }
163
168 [[nodiscard]]
169 bool
171 {
172 return tx_->isFieldPresent(sfSourceTag);
173 }
174
181 [[nodiscard]]
184 {
185 if (tx_->isFieldPresent(sfPreviousTxnID))
186 return tx_->at(sfPreviousTxnID);
187 return std::nullopt;
188 }
189
194 [[nodiscard]]
195 bool
197 {
198 return tx_->isFieldPresent(sfPreviousTxnID);
199 }
200
208 [[nodiscard]]
211 {
212 if (tx_->isFieldPresent(sfLastLedgerSequence))
213 return tx_->at(sfLastLedgerSequence);
214 return std::nullopt;
215 }
216
221 [[nodiscard]]
222 bool
224 {
225 return tx_->isFieldPresent(sfLastLedgerSequence);
226 }
227
234 [[nodiscard]]
237 {
238 if (tx_->isFieldPresent(sfAccountTxnID))
239 return tx_->at(sfAccountTxnID);
240 return std::nullopt;
241 }
242
247 [[nodiscard]]
248 bool
250 {
251 return tx_->isFieldPresent(sfAccountTxnID);
252 }
253
260 [[nodiscard]]
263 {
264 if (tx_->isFieldPresent(sfOperationLimit))
265 return tx_->at(sfOperationLimit);
266 return std::nullopt;
267 }
268
273 [[nodiscard]]
274 bool
276 {
277 return tx_->isFieldPresent(sfOperationLimit);
278 }
279
287 [[nodiscard]]
289 getMemos() const
290 {
291 if (tx_->isFieldPresent(sfMemos))
292 return tx_->getFieldArray(sfMemos);
293 return std::nullopt;
294 }
295
300 [[nodiscard]]
301 bool
302 hasMemos() const
303 {
304 return tx_->isFieldPresent(sfMemos);
305 }
306
313 [[nodiscard]]
316 {
317 if (tx_->isFieldPresent(sfTicketSequence))
318 return tx_->at(sfTicketSequence);
319 return std::nullopt;
320 }
321
326 [[nodiscard]]
327 bool
329 {
330 return tx_->isFieldPresent(sfTicketSequence);
331 }
332
339 [[nodiscard]]
342 {
343 if (tx_->isFieldPresent(sfTxnSignature))
344 return tx_->getFieldVL(sfTxnSignature);
345 return std::nullopt;
346 }
347
352 [[nodiscard]]
353 bool
355 {
356 return tx_->isFieldPresent(sfTxnSignature);
357 }
358
366 [[nodiscard]]
369 {
370 if (tx_->isFieldPresent(sfSigners))
371 return tx_->getFieldArray(sfSigners);
372 return std::nullopt;
373 }
374
379 [[nodiscard]]
380 bool
382 {
383 return tx_->isFieldPresent(sfSigners);
384 }
385
392 [[nodiscard]]
395 {
396 if (tx_->isFieldPresent(sfNetworkID))
397 return tx_->at(sfNetworkID);
398 return std::nullopt;
399 }
400
405 [[nodiscard]]
406 bool
408 {
409 return tx_->isFieldPresent(sfNetworkID);
410 }
411
418 [[nodiscard]]
421 {
422 if (tx_->isFieldPresent(sfDelegate))
423 return tx_->at(sfDelegate);
424 return std::nullopt;
425 }
426
431 [[nodiscard]]
432 bool
434 {
435 return tx_->isFieldPresent(sfDelegate);
436 }
437
445 [[nodiscard]]
447 getSTTx() const
448 {
449 return tx_;
450 }
451
452protected:
455};
456
457} // namespace xrpl::transactions
static TxFormats const & getInstance()
Definition TxFormats.cpp:55
Base class for all transaction wrapper types.
std::optional< uint256 > getPreviousTxnID() const
Get the previous transaction ID (sfPreviousTxnID).
std::optional< std::reference_wrapper< STArray const > > getMemos() const
Get the memos array (sfMemos).
std::shared_ptr< STTx const > tx_
The underlying transaction object being wrapped.
bool hasMemos() const
Check if the transaction has memos.
bool hasNetworkID() const
Check if the transaction has a network ID.
bool hasPreviousTxnID() const
Check if the transaction has a previous transaction ID.
std::shared_ptr< STTx const > getSTTx() const
Get the underlying STTx object.
std::optional< uint256 > getAccountTxnID() const
Get the account transaction ID (sfAccountTxnID).
std::optional< AccountID > getDelegate() const
Get the delegate account (sfDelegate).
bool validate(std::string &reason) const
Validate the transaction.
xrpl::TxType getTransactionType() const
Get the transaction type.
bool hasTicketSequence() const
Check if the transaction has a ticket sequence.
std::optional< uint32_t > getLastLedgerSequence() const
Get the last ledger sequence (sfLastLedgerSequence).
TransactionBase(std::shared_ptr< STTx const > tx)
Construct a transaction wrapper from an existing STTx object.
std::uint32_t getSequence() const
Get the sequence number of the transaction (sfSequence).
bool hasSourceTag() const
Check if the transaction has a source tag.
bool hasAccountTxnID() const
Check if the transaction has an account transaction ID.
bool hasDelegate() const
Check if the transaction has a delegate account.
AccountID getAccount() const
Get the account initiating the transaction (sfAccount).
bool hasOperationLimit() const
Check if the transaction has an operation limit.
std::optional< uint32_t > getOperationLimit() const
Get the operation limit (sfOperationLimit).
bool hasFlags() const
Check if the transaction has flags set.
std::optional< uint32_t > getFlags() const
Get the transaction flags (sfFlags).
std::optional< std::reference_wrapper< STArray const > > getSigners() const
Get the signers array (sfSigners).
std::optional< uint32_t > getTicketSequence() const
Get the ticket sequence (sfTicketSequence).
bool hasSigners() const
Check if the transaction has signers.
bool hasTxnSignature() const
Check if the transaction has a transaction signature.
std::optional< uint32_t > getSourceTag() const
Get the source tag (sfSourceTag).
bool hasLastLedgerSequence() const
Check if the transaction has a last ledger sequence.
std::optional< Blob > getTxnSignature() const
Get the transaction signature (sfTxnSignature).
Blob getSigningPubKey() const
Get the signing public key (sfSigningPubKey).
STAmount getFee() const
Get the transaction fee (sfFee).
std::optional< uint32_t > getNetworkID() const
Get the network ID (sfNetworkID).
T is_same_v
STL namespace.
bool validateSTObject(STObject const &obj, SOTemplate const &format)
TxType
Transaction type identifiers.
Definition TxFormats.h:39
bool passesLocalChecks(STObject const &st, std::string &)
Definition STTx.cpp:770
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition STTx.cpp:809