xrpld
Loading...
Searching...
No Matches
STTx.h
1#pragma once
2
3#include <xrpl/protocol/Feature.h>
4#include <xrpl/protocol/PublicKey.h>
5#include <xrpl/protocol/Rules.h>
6#include <xrpl/protocol/STObject.h>
7#include <xrpl/protocol/SecretKey.h>
8#include <xrpl/protocol/SeqProxy.h>
9#include <xrpl/protocol/TxFormats.h>
10
11#include <boost/container/flat_set.hpp>
12
13#include <expected>
14#include <functional>
15
16namespace xrpl {
17
18enum class TxnSql : char {
19 New = 'N',
20 Conflict = 'C',
21 Held = 'H',
22 Validated = 'V',
23 Included = 'I',
24 Unknown = 'U'
25};
26
27class STTx final : public STObject, public CountedObject<STTx>
28{
31
32public:
33 static constexpr std::size_t kMinMultiSigners = 1;
34 static constexpr std::size_t kMaxMultiSigners = 32;
35
36 STTx() = delete;
37 STTx(STTx const& other) = default;
38 STTx&
39 operator=(STTx const& other) = delete;
40
41 explicit STTx(SerialIter& sit);
42 explicit STTx(SerialIter&& sit);
43 explicit STTx(STObject&& object);
44
51 STTx(TxType type, std::function<void(STObject&)> assembler);
52
53 // STObject functions.
55 getSType() const override;
56
58 getFullText() const override;
59
60 // Outer transaction functions / signature functions.
61 static Blob
62 getSignature(STObject const& sigObject);
63
64 Blob
66 {
67 return getSignature(*this);
68 }
69
71 getSigningHash() const;
72
73 TxType
74 getTxnType() const;
75
76 Blob
77 getSigningPubKey() const;
78
80 getSeqProxy() const;
81
84 getSeqValue() const;
85
87 getFeePayer() const;
88
89 boost::container::flat_set<AccountID>
91
93 getTransactionID() const;
94
96 getJson(JsonOptions options) const override;
97
99 getJson(JsonOptions options, bool binary) const;
100
101 void
102 sign(
103 PublicKey const& publicKey,
104 SecretKey const& secretKey,
106
111 std::expected<void, std::string>
112 checkSign(Rules const& rules) const;
113
114 std::expected<void, std::string>
115 checkBatchSign(Rules const& rules) const;
116
117 // SQL Functions with metadata.
118 static std::string const&
120
122 getMetaSQL(std::uint32_t inLedger, std::string const& escapedMetaData) const;
123
126 Serializer rawTxn,
127 std::uint32_t inLedger,
128 TxnSql status,
129 std::string const& escapedMetaData) const;
130
133
134private:
141 std::expected<void, std::string>
142 checkSign(Rules const& rules, STObject const& sigObject) const;
143
144 std::expected<void, std::string>
145 checkSingleSign(STObject const& sigObject) const;
146
147 std::expected<void, std::string>
148 checkMultiSign(Rules const& rules, STObject const& sigObject) const;
149
150 std::expected<void, std::string>
151 checkBatchSingleSign(STObject const& batchSigner) const;
152
153 std::expected<void, std::string>
154 checkBatchMultiSign(STObject const& batchSigner, Rules const& rules) const;
155
156 STBase*
157 copy(std::size_t n, void* buf) const override;
158 STBase*
159 move(std::size_t n, void* buf) override;
160
161 friend class detail::STVar;
163};
164
165bool
167
176sterilize(STTx const& stx);
177
179bool
180isPseudoTx(STObject const& tx);
181
182inline STTx::STTx(SerialIter&& sit) // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved)
183 : STTx(sit)
184{
185}
186
187inline TxType
189{
190 return txType_;
191}
192
193inline Blob
195{
196 return getFieldVL(sfSigningPubKey);
197}
198
199inline uint256
201{
202 return tid_;
203}
204
205} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
A public key.
Definition PublicKey.h:42
Blob getFieldVL(SField const &field) const
Definition STObject.cpp:639
STObject(STObject const &)=default
std::string getFullText() const override
Definition STTx.cpp:130
STBase * move(std::size_t n, void *buf) override
Definition STTx.cpp:117
Blob getSignature() const
Definition STTx.h:65
std::string getMetaSQL(std::uint32_t inLedger, std::string const &escapedMetaData) const
Definition STTx.cpp:365
uint256 tid_
Definition STTx.h:29
STTx & operator=(STTx const &other)=delete
std::expected< void, std::string > checkBatchSign(Rules const &rules) const
Definition STTx.cpp:286
static std::string const & getMetaSQLInsertReplaceHeader()
Definition STTx.cpp:353
std::expected< void, std::string > checkBatchSingleSign(STObject const &batchSigner) const
Definition STTx.cpp:430
STTx(STTx const &other)=default
std::vector< uint256 > const & getBatchTransactionIDs() const
Retrieves a batch of transaction IDs from the STTx.
Definition STTx.cpp:574
std::expected< void, std::string > checkBatchMultiSign(STObject const &batchSigner, Rules const &rules) const
Definition STTx.cpp:515
static constexpr std::size_t kMinMultiSigners
Definition STTx.h:33
SeqProxy getSeqProxy() const
Definition STTx.cpp:193
AccountID getFeePayer() const
Definition STTx.cpp:216
std::expected< void, std::string > checkSign(Rules const &rules) const
Check the signature.
Definition STTx.cpp:271
STBase * copy(std::size_t n, void *buf) const override
Definition STTx.cpp:111
STTx()=delete
static constexpr std::size_t kMaxMultiSigners
Definition STTx.h:34
std::expected< void, std::string > checkSingleSign(STObject const &sigObject) const
Definition STTx.cpp:423
std::expected< void, std::string > checkMultiSign(Rules const &rules, STObject const &sigObject) const
Definition STTx.cpp:534
std::uint32_t getSeqValue() const
Returns the first non-zero value of (Sequence, TicketSequence).
Definition STTx.cpp:210
TxType getTxnType() const
Definition STTx.h:188
std::vector< uint256 > batchTxnIds_
Definition STTx.h:162
Blob getSigningPubKey() const
Definition STTx.h:194
uint256 getSigningHash() const
Definition STTx.cpp:174
TxType txType_
Definition STTx.h:30
json::Value getJson(JsonOptions options) const override
Definition STTx.cpp:316
uint256 getTransactionID() const
Definition STTx.h:200
SerializedTypeID getSType() const override
Definition STTx.cpp:124
boost::container::flat_set< AccountID > getMentionedAccounts() const
Definition STTx.cpp:141
void sign(PublicKey const &publicKey, SecretKey const &secretKey, std::optional< std::reference_wrapper< SField const > > signatureTarget={})
Definition STTx.cpp:230
A secret key.
Definition SecretKey.h:18
A type that represents either a sequence value or a ticket value.
Definition SeqProxy.h:36
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
TxType
Transaction type identifiers.
Definition TxFormats.h:41
@ Validated
The most recently validated ledger.
TxnSql
Definition STTx.h:18
@ Included
Definition STTx.h:23
@ Conflict
Definition STTx.h:20
SerializedTypeID
Definition SField.h:93
bool passesLocalChecks(STObject const &st, std::string &)
Definition STTx.cpp:771
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
std::vector< unsigned char > Blob
Storage for linear binary data.
Definition Blob.h:10
std::shared_ptr< STTx const > sterilize(STTx const &stx)
Sterilize a transaction.
Definition STTx.cpp:801
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition STTx.cpp:810
BaseUInt< 256 > uint256
Definition base_uint.h:562
Note, should be treated as flags that can be | and &.
Definition STBase.h:17