xrpld
Loading...
Searching...
No Matches
STTx.h
1#pragma once
2
3#include <xrpl/basics/Blob.h>
4#include <xrpl/basics/CountedObject.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/json/json_value.h>
7#include <xrpl/protocol/AccountID.h>
8#include <xrpl/protocol/PublicKey.h>
9#include <xrpl/protocol/Rules.h>
10#include <xrpl/protocol/SField.h>
11#include <xrpl/protocol/STBase.h>
12#include <xrpl/protocol/STObject.h>
13#include <xrpl/protocol/SecretKey.h>
14#include <xrpl/protocol/SeqProxy.h>
15#include <xrpl/protocol/Serializer.h>
16#include <xrpl/protocol/TxFormats.h>
17
18#include <boost/container/flat_set.hpp>
19
20#include <cstddef>
21#include <cstdint>
22#include <expected>
23#include <functional>
24#include <memory>
25#include <optional>
26#include <string>
27#include <vector>
28
29namespace xrpl {
30
31enum class TxnSql : char {
32 New = 'N',
33 Conflict = 'C',
34 Held = 'H',
35 Validated = 'V',
36 Included = 'I',
37 Unknown = 'U'
38};
39
40class STTx final : public STObject, public CountedObject<STTx>
41{
44
45public:
46 static constexpr std::size_t kMinMultiSigners = 1;
47 static constexpr std::size_t kMaxMultiSigners = 32;
48
49 STTx() = delete;
50 STTx(STTx const& other) = default;
51 STTx&
52 operator=(STTx const& other) = delete;
53
54 explicit STTx(SerialIter& sit);
55 explicit STTx(SerialIter&& sit);
56 explicit STTx(STObject&& object);
57
65 STTx(TxType type, std::function<void(STObject&)> assembler);
66
67 // STObject functions.
68 [[nodiscard]] SerializedTypeID
69 getSType() const override;
70
71 [[nodiscard]] std::string
72 getFullText() const override;
73
74 // Outer transaction functions / signature functions.
75 static Blob
76 getSignature(STObject const& sigObject);
77
78 [[nodiscard]] Blob
80 {
81 return getSignature(*this);
82 }
83
84 [[nodiscard]] uint256
85 getSigningHash() const;
86
87 [[nodiscard]] TxType
88 getTxnType() const;
89
90 [[nodiscard]] Blob
91 getSigningPubKey() const;
92
93 [[nodiscard]] SeqProxy
94 getSeqProxy() const;
95
96 [[nodiscard]] boost::container::flat_set<AccountID>
98
99 [[nodiscard]] uint256
100 getTransactionID() const;
101
102 [[nodiscard]] json::Value
103 getJson(JsonOptions options) const override;
104
105 [[nodiscard]] json::Value
106 getJson(JsonOptions options, bool binary) const;
107
108 void
109 sign(
110 PublicKey const& publicKey,
111 SecretKey const& secretKey,
113
119 [[nodiscard]] std::expected<void, std::string>
120 checkSign(Rules const& rules) const;
121
122 [[nodiscard]] std::expected<void, std::string>
123 checkBatchSign(Rules const& rules) const;
124
125 // SQL Functions with metadata.
126 static std::string const&
128
129 [[nodiscard]] std::string
130 getMetaSQL(std::uint32_t inLedger, std::string const& escapedMetaData) const;
131
132 [[nodiscard]] std::string
134 Serializer rawTxn,
135 std::uint32_t inLedger,
136 TxnSql status,
137 std::string const& escapedMetaData) const;
138
142 [[nodiscard]] std::vector<uint256>
144
149 [[nodiscard]] std::vector<std::shared_ptr<STTx const>> const&
150 getBatchTransactions() const;
151
156 [[nodiscard]] AccountID
157 getInitiator() const;
158
159 [[nodiscard]] AccountID
160 getFeePayerID() const;
161
162private:
170 [[nodiscard]] std::expected<void, std::string>
171 checkSign(Rules const& rules, STObject const& sigObject) const;
172
173 [[nodiscard]] std::expected<void, std::string>
174 checkSingleSign(STObject const& sigObject) const;
175
176 [[nodiscard]] std::expected<void, std::string>
177 checkMultiSign(Rules const& rules, STObject const& sigObject) const;
178
179 [[nodiscard]] std::expected<void, std::string>
180 checkBatchSingleSign(STObject const& batchSigner, std::vector<uint256> const& txIds) const;
181
182 [[nodiscard]] std::expected<void, std::string>
184 STObject const& batchSigner,
185 Rules const& rules,
186 std::vector<uint256> const& txIds) const;
187
188 void
190
191 STBase*
192 copy(std::size_t n, void* buf) const override;
193 STBase*
194 move(std::size_t n, void* buf) override;
195
196 friend class detail::STVar;
198};
199
200bool
202
212sterilize(STTx const& stx);
213
217bool
218isPseudoTx(STObject const& tx);
219
220inline STTx::STTx(SerialIter&& sit) // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved)
221 : STTx(sit)
222{
223}
224
225inline TxType
227{
228 return txType_;
229}
230
231inline Blob
233{
234 return getFieldVL(sfSigningPubKey);
235}
236
237inline uint256
239{
240 return tid_;
241}
242
243} // namespace xrpl
Represents a JSON value.
Definition json_value.h:117
A public key.
Definition PublicKey.h:53
Blob getFieldVL(SField const &field) const
Definition STObject.cpp:649
STObject(STObject const &)=default
std::string getFullText() const override
Definition STTx.cpp:136
STBase * move(std::size_t n, void *buf) override
Definition STTx.cpp:123
Blob getSignature() const
Definition STTx.h:79
std::string getMetaSQL(std::uint32_t inLedger, std::string const &escapedMetaData) const
Definition STTx.cpp:387
uint256 tid_
Definition STTx.h:42
std::optional< std::vector< std::shared_ptr< STTx const > > > batchTxns_
Definition STTx.h:197
STTx & operator=(STTx const &other)=delete
std::expected< void, std::string > checkBatchSign(Rules const &rules) const
Definition STTx.cpp:287
static std::string const & getMetaSQLInsertReplaceHeader()
Definition STTx.cpp:375
STTx(STTx const &other)=default
std::vector< uint256 > getBatchTransactionIDs() const
The IDs of the inner transactions of a Batch.
Definition STTx.cpp:634
std::expected< void, std::string > checkBatchMultiSign(STObject const &batchSigner, Rules const &rules, std::vector< uint256 > const &txIds) const
Definition STTx.cpp:544
static constexpr std::size_t kMinMultiSigners
Definition STTx.h:46
SeqProxy getSeqProxy() const
Definition STTx.cpp:199
std::expected< void, std::string > checkSign(Rules const &rules) const
Check the signature.
Definition STTx.cpp:257
std::expected< void, std::string > checkBatchSingleSign(STObject const &batchSigner, std::vector< uint256 > const &txIds) const
Definition STTx.cpp:457
STBase * copy(std::size_t n, void *buf) const override
Definition STTx.cpp:117
STTx()=delete
static constexpr std::size_t kMaxMultiSigners
Definition STTx.h:47
std::expected< void, std::string > checkSingleSign(STObject const &sigObject) const
Definition STTx.cpp:450
std::expected< void, std::string > checkMultiSign(Rules const &rules, STObject const &sigObject) const
Definition STTx.cpp:569
void buildBatchTxns()
Definition STTx.cpp:594
TxType getTxnType() const
Definition STTx.h:226
AccountID getFeePayerID() const
Definition STTx.cpp:670
Blob getSigningPubKey() const
Definition STTx.h:232
uint256 getSigningHash() const
Definition STTx.cpp:180
TxType txType_
Definition STTx.h:43
json::Value getJson(JsonOptions options) const override
Definition STTx.cpp:338
AccountID getInitiator() const
The account responsible for the authorization: the delegate when sfDelegate is present,...
Definition STTx.cpp:656
uint256 getTransactionID() const
Definition STTx.h:238
SerializedTypeID getSType() const override
Definition STTx.cpp:130
boost::container::flat_set< AccountID > getMentionedAccounts() const
Definition STTx.cpp:147
void sign(PublicKey const &publicKey, SecretKey const &secretKey, std::optional< std::reference_wrapper< SField const > > signatureTarget={})
Definition STTx.cpp:216
std::vector< std::shared_ptr< STTx const > > const & getBatchTransactions() const
The inner transactions of a Batch, built and validated at construction.
Definition STTx.cpp:645
A secret key.
Definition SecretKey.h:24
A type that represents either a sequence value or a ticket value.
Definition SeqProxy.h:37
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:45
@ Validated
The most recently validated ledger.
TxnSql
Definition STTx.h:31
@ Included
Definition STTx.h:36
@ Conflict
Definition STTx.h:33
bool passesLocalChecks(STTx const &tx, std::string &)
Definition STTx.cpp:847
SerializedTypeID
Definition SField.h:94
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
std::vector< unsigned char > Blob
Storage for linear binary data.
Definition Blob.h:11
std::shared_ptr< STTx const > sterilize(STTx const &stx)
Sterilize a transaction.
Definition STTx.cpp:877
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition STTx.cpp:886
BaseUInt< 256 > uint256
Definition base_uint.h:580
Note, should be treated as flags that can be | and &.
Definition STBase.h:22