xrpld
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 }
99
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
301
308 {
309 object_[sfDestination] = value;
310 return *this;
311 }
312
320 {
321 object_[sfAmount] = value;
322 return *this;
323 }
324
332 {
333 object_[sfSendMax] = value;
334 return *this;
335 }
336
342 setPaths(STPathSet const& value)
343 {
344 object_.setFieldPathSet(sfPaths, value);
345 return *this;
346 }
347
354 {
355 object_[sfInvoiceID] = value;
356 return *this;
357 }
358
365 {
366 object_[sfDestinationTag] = value;
367 return *this;
368 }
369
377 {
378 object_[sfDeliverMin] = value;
379 return *this;
380 }
381
388 {
389 object_[sfCredentialIDs] = value;
390 return *this;
391 }
392
399 {
400 object_[sfDomainID] = value;
401 return *this;
402 }
403
410 Payment
411 build(PublicKey const& publicKey, SecretKey const& secretKey)
412 {
413 sign(publicKey, secretKey);
414 return Payment{std::make_shared<STTx>(std::move(object_))};
415 }
416};
417
418} // namespace xrpl::transactions
A public key.
Definition PublicKey.h:53
A secret key.
Definition SecretKey.h:24
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).
std::shared_ptr< STTx const > tx_
The underlying transaction object being wrapped.
TransactionBase(std::shared_ptr< STTx const > tx)
Construct a transaction wrapper from an existing STTx object.
PaymentBuilder & sign(PublicKey const &publicKey, SecretKey const &secretKey)
T make_shared(T... args)
STL namespace.
std::conditional_t< std::is_reference_v< ValueType >, std::optional< std::reference_wrapper< std::remove_reference_t< ValueType > > >, std::optional< ValueType > > Optional
Definition Utils.h:9
TxType
Transaction type identifiers.
Definition TxFormats.h:45