rippled
Loading...
Searching...
No Matches
protocol_autogen/transactions/Payment.h
1// This file is auto-generated. Do not edit.
2#pragma once
3
4#include <xrpl/protocol/STTx.h>
5#include <xrpl/protocol/STParsedJSON.h>
6#include <xrpl/protocol/jss.h>
7#include <xrpl/protocol_autogen/TransactionBase.h>
8#include <xrpl/protocol_autogen/TransactionBuilderBase.h>
9#include <xrpl/json/json_value.h>
10
11#include <stdexcept>
12#include <optional>
13
14namespace xrpl::transactions {
15
16class PaymentBuilder;
17
30{
31public:
32 static constexpr xrpl::TxType txType = ttPAYMENT;
33
39 : TransactionBase(std::move(tx))
40 {
41 // Verify transaction type
42 if (tx_->getTxnType() != txType)
43 {
44 throw std::runtime_error("Invalid transaction type for Payment");
45 }
46 }
47
48 // Transaction-specific field getters
49
54 [[nodiscard]]
55 SF_ACCOUNT::type::value_type
57 {
58 return this->tx_->at(sfDestination);
59 }
60
66 [[nodiscard]]
67 SF_AMOUNT::type::value_type
68 getAmount() const
69 {
70 return this->tx_->at(sfAmount);
71 }
72
78 [[nodiscard]]
80 getSendMax() const
81 {
82 if (hasSendMax())
83 {
84 return this->tx_->at(sfSendMax);
85 }
86 return std::nullopt;
87 }
88
93 [[nodiscard]]
94 bool
95 hasSendMax() const
96 {
97 return this->tx_->isFieldPresent(sfSendMax);
98 }
104 [[nodiscard]]
106 getPaths() const
107 {
108 if (this->tx_->isFieldPresent(sfPaths))
109 return this->tx_->getFieldPathSet(sfPaths);
110 return std::nullopt;
111 }
112
117 [[nodiscard]]
118 bool
119 hasPaths() const
120 {
121 return this->tx_->isFieldPresent(sfPaths);
122 }
123
128 [[nodiscard]]
131 {
132 if (hasInvoiceID())
133 {
134 return this->tx_->at(sfInvoiceID);
135 }
136 return std::nullopt;
137 }
138
143 [[nodiscard]]
144 bool
146 {
147 return this->tx_->isFieldPresent(sfInvoiceID);
148 }
149
154 [[nodiscard]]
157 {
158 if (hasDestinationTag())
159 {
160 return this->tx_->at(sfDestinationTag);
161 }
162 return std::nullopt;
163 }
164
169 [[nodiscard]]
170 bool
172 {
173 return this->tx_->isFieldPresent(sfDestinationTag);
174 }
175
181 [[nodiscard]]
184 {
185 if (hasDeliverMin())
186 {
187 return this->tx_->at(sfDeliverMin);
188 }
189 return std::nullopt;
190 }
191
196 [[nodiscard]]
197 bool
199 {
200 return this->tx_->isFieldPresent(sfDeliverMin);
201 }
202
207 [[nodiscard]]
210 {
211 if (hasCredentialIDs())
212 {
213 return this->tx_->at(sfCredentialIDs);
214 }
215 return std::nullopt;
216 }
217
222 [[nodiscard]]
223 bool
225 {
226 return this->tx_->isFieldPresent(sfCredentialIDs);
227 }
228
233 [[nodiscard]]
236 {
237 if (hasDomainID())
238 {
239 return this->tx_->at(sfDomainID);
240 }
241 return std::nullopt;
242 }
243
248 [[nodiscard]]
249 bool
251 {
252 return this->tx_->isFieldPresent(sfDomainID);
253 }
254};
255
263class PaymentBuilder : public TransactionBuilderBase<PaymentBuilder>
264{
265public:
274 PaymentBuilder(SF_ACCOUNT::type::value_type account,
277)
278 : TransactionBuilderBase<PaymentBuilder>(ttPAYMENT, account, sequence, fee)
279 {
280 setDestination(destination);
281 setAmount(amount);
282 }
283
290 {
291 if (tx->getTxnType() != ttPAYMENT)
292 {
293 throw std::runtime_error("Invalid transaction type for PaymentBuilder");
294 }
295 object_ = *tx;
296 }
297
306 {
307 object_[sfDestination] = value;
308 return *this;
309 }
310
318 {
319 object_[sfAmount] = value;
320 return *this;
321 }
322
330 {
331 object_[sfSendMax] = value;
332 return *this;
333 }
334
340 setPaths(STPathSet const& value)
341 {
342 object_.setFieldPathSet(sfPaths, value);
343 return *this;
344 }
345
352 {
353 object_[sfInvoiceID] = value;
354 return *this;
355 }
356
363 {
364 object_[sfDestinationTag] = value;
365 return *this;
366 }
367
375 {
376 object_[sfDeliverMin] = value;
377 return *this;
378 }
379
386 {
387 object_[sfCredentialIDs] = value;
388 return *this;
389 }
390
397 {
398 object_[sfDomainID] = value;
399 return *this;
400 }
401
408 Payment
409 build(PublicKey const& publicKey, SecretKey const& secretKey)
410 {
411 sign(publicKey, secretKey);
412 return Payment{std::make_shared<STTx>(std::move(object_))};
413 }
414};
415
416} // namespace xrpl::transactions
A public key.
Definition PublicKey.h:42
void setFieldPathSet(SField const &field, STPathSet const &)
Definition STObject.cpp:813
A secret key.
Definition SecretKey.h:18
PaymentBuilder & setDeliverMin(std::decay_t< typename SF_AMOUNT::type::value_type > const &value)
Set sfDeliverMin (soeOPTIONAL)
PaymentBuilder & setCredentialIDs(std::decay_t< typename SF_VECTOR256::type::value_type > const &value)
Set sfCredentialIDs (soeOPTIONAL)
PaymentBuilder & setAmount(std::decay_t< typename SF_AMOUNT::type::value_type > const &value)
Set sfAmount (soeREQUIRED)
PaymentBuilder & setSendMax(std::decay_t< typename SF_AMOUNT::type::value_type > const &value)
Set sfSendMax (soeOPTIONAL)
PaymentBuilder(SF_ACCOUNT::type::value_type account, std::decay_t< typename SF_ACCOUNT::type::value_type > const &destination, std::decay_t< typename SF_AMOUNT::type::value_type > const &amount, std::optional< SF_UINT32::type::value_type > sequence=std::nullopt, std::optional< SF_AMOUNT::type::value_type > fee=std::nullopt)
Construct a new PaymentBuilder with required fields.
PaymentBuilder(std::shared_ptr< STTx const > tx)
Construct a PaymentBuilder from an existing STTx object.
PaymentBuilder & setDestination(std::decay_t< typename SF_ACCOUNT::type::value_type > const &value)
Transaction-specific field setters.
PaymentBuilder & setInvoiceID(std::decay_t< typename SF_UINT256::type::value_type > const &value)
Set sfInvoiceID (soeOPTIONAL)
PaymentBuilder & setDestinationTag(std::decay_t< typename SF_UINT32::type::value_type > const &value)
Set sfDestinationTag (soeOPTIONAL)
PaymentBuilder & setPaths(STPathSet const &value)
Set sfPaths (soeDEFAULT)
Payment build(PublicKey const &publicKey, SecretKey const &secretKey)
Build and return the Payment wrapper.
PaymentBuilder & setDomainID(std::decay_t< typename SF_UINT256::type::value_type > const &value)
Set sfDomainID (soeOPTIONAL)
bool hasPaths() const
Check if sfPaths is present.
std::optional< std::reference_wrapper< STPathSet const > > getPaths() const
Get sfPaths (soeDEFAULT)
protocol_autogen::Optional< SF_AMOUNT::type::value_type > getSendMax() const
Get sfSendMax (soeOPTIONAL)
bool hasDomainID() const
Check if sfDomainID is present.
protocol_autogen::Optional< SF_VECTOR256::type::value_type > getCredentialIDs() const
Get sfCredentialIDs (soeOPTIONAL)
bool hasDestinationTag() const
Check if sfDestinationTag is present.
protocol_autogen::Optional< SF_AMOUNT::type::value_type > getDeliverMin() const
Get sfDeliverMin (soeOPTIONAL)
protocol_autogen::Optional< SF_UINT256::type::value_type > getInvoiceID() const
Get sfInvoiceID (soeOPTIONAL)
Payment(std::shared_ptr< STTx const > tx)
Construct a Payment transaction wrapper from an existing STTx object.
bool hasInvoiceID() const
Check if sfInvoiceID is present.
bool hasSendMax() const
Check if sfSendMax is present.
bool hasCredentialIDs() const
Check if sfCredentialIDs is present.
protocol_autogen::Optional< SF_UINT32::type::value_type > getDestinationTag() const
Get sfDestinationTag (soeOPTIONAL)
bool hasDeliverMin() const
Check if sfDeliverMin is present.
protocol_autogen::Optional< SF_UINT256::type::value_type > getDomainID() const
Get sfDomainID (soeOPTIONAL)
SF_AMOUNT::type::value_type getAmount() const
Get sfAmount (soeREQUIRED)
SF_ACCOUNT::type::value_type getDestination() const
Get sfDestination (soeREQUIRED)
Base class for all transaction wrapper types.
std::shared_ptr< STTx const > tx_
The underlying transaction object being wrapped.
Base class for all transaction builders.
PaymentBuilder & sign(PublicKey const &publicKey, SecretKey const &secretKey)
Sign the transaction with the given keys.
T is_same_v
STL namespace.
TxType
Transaction type identifiers.
Definition TxFormats.h:39