rippled
Loading...
Searching...
No Matches
LedgerEntryBuilderBase.h
1#pragma once
2
3#include <xrpl/protocol/LedgerFormats.h>
4#include <xrpl/protocol/SField.h>
5#include <xrpl/protocol/STAccount.h>
6#include <xrpl/protocol/STAmount.h>
7#include <xrpl/protocol/STBlob.h>
8#include <xrpl/protocol/STInteger.h>
9#include <xrpl/protocol/STLedgerEntry.h>
10#include <xrpl/protocol/STObject.h>
11#include <xrpl/protocol_autogen/STObjectValidation.h>
12
13namespace xrpl::ledger_entries {
14
19template <typename Derived>
21{
22public:
24
26 SF_UINT16::type::value_type ledgerEntryType,
27 SF_UINT32::type::value_type flags = 0)
28 {
29 // Don't call object_.set(soTemplate) - keep object_ as a free object.
30 // This avoids creating STBase placeholders for soeDEFAULT fields,
31 // which would cause applyTemplate() to throw "may not be explicitly
32 // set to default" when building the SLE.
33 // The SLE constructor will call applyTemplate() which properly
34 // handles missing fields.
35 object_[sfLedgerEntryType] = ledgerEntryType;
36 object_[sfFlags] = flags;
37 }
38
43 [[nodiscard]]
44 bool
45 validate() const
46 {
47 if (!object_.isFieldPresent(sfLedgerEntryType))
48 {
49 return false; // LCOV_EXCL_LINE
50 }
51 auto ledgerEntryType = static_cast<LedgerEntryType>(object_.getFieldU16(sfLedgerEntryType));
53 object_, LedgerFormats::getInstance().findByType(ledgerEntryType)->getSOTemplate());
54 }
55
61 Derived&
62 setLedgerIndex(uint256 const& value)
63 {
64 object_[sfLedgerIndex] = value;
65 return static_cast<Derived&>(*this);
66 }
67
73 Derived&
74 setFlags(uint32_t value)
75 {
76 object_.setFieldU32(sfFlags, value);
77 return static_cast<Derived&>(*this);
78 }
79
80protected:
81 STObject object_{sfLedgerEntry};
82};
83
84} // namespace xrpl::ledger_entries
static LedgerFormats const & getInstance()
void setFieldU32(SField const &field, std::uint32_t)
Definition STObject.cpp:735
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:456
std::uint16_t getFieldU16(SField const &field) const
Definition STObject.cpp:587
Base class for all ledger entry builders.
Derived & setLedgerIndex(uint256 const &value)
Set the ledger index.
LedgerEntryBuilderBase(SF_UINT16::type::value_type ledgerEntryType, SF_UINT32::type::value_type flags=0)
Derived & setFlags(uint32_t value)
Set the flags.
bool validate() const
Validate the ledger entry.
bool validateSTObject(STObject const &obj, SOTemplate const &format)
LedgerEntryType
Identifiers for on-ledger objects.