rippled
Loading...
Searching...
No Matches
STTakesAsset.cpp
1#include <xrpl/protocol/STTakesAsset.h>
2// Do not remove. Force STTakesAsset.h first
3#include <xrpl/protocol/STLedgerEntry.h>
4
5namespace xrpl {
6
7void
8associateAsset(SLE& sle, Asset const& asset)
9{
10 // Iterating by offset is the only way to get non-const references
11 for (int i = 0; i < sle.getCount(); ++i)
12 {
13 STBase& entry = sle.getIndex(i);
14 SField const& field = entry.getFName();
15 if (field.shouldMeta(SField::sMD_NeedsAsset))
16 {
17 auto const type = entry.getSType();
18 // If the field is not set or present, skip it.
19 if (type == STI_NOTPRESENT)
20 continue;
21
22 // If the type doesn't downcast, then the flag shouldn't be on the
23 // SField
24 auto& ta = entry.downcast<STTakesAsset>();
25 auto const style = sle.getStyle(ta.getFName());
26 XRPL_ASSERT_PARTS(style != soeINVALID, "xrpl::associateAsset", "valid template element style");
27
28 XRPL_ASSERT_PARTS(style != soeDEFAULT || !ta.isDefault(), "xrpl::associateAsset", "non-default value");
29 ta.associateAsset(asset);
30
31 // associateAsset in derived classes may change the underlying
32 // value, but it won't know anything about how the value relates to
33 // the SLE. If the template element is soeDEFAULT, and the value
34 // changed to the default value, remove the field.
35 if (style == soeDEFAULT && ta.isDefault())
36 sle.makeFieldAbsent(field);
37 }
38 }
39}
40
41} // namespace xrpl
Identifies fields.
Definition SField.h:127
@ sMD_NeedsAsset
Definition SField.h:139
A type which can be exported to a well known binary format.
Definition STBase.h:116
virtual bool isDefault() const
Definition STBase.cpp:109
SOEStyle getStyle(SField const &field) const
Definition STObject.cpp:558
int getCount() const
Definition STObject.h:983
STBase & getIndex(int offset)
Definition STObject.h:995
void makeFieldAbsent(SField const &field)
Definition STObject.cpp:525
Intermediate class for any STBase-derived class to store an Asset.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
@ soeINVALID
Definition SOTemplate.h:15
@ soeDEFAULT
Definition SOTemplate.h:18
void associateAsset(STLedgerEntry &sle, Asset const &asset)
Associate an Asset with all sMD_NeedsAsset fields in a ledger entry.