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(
27 style != soeINVALID, "xrpl::associateAsset", "valid template element style");
28
29 XRPL_ASSERT_PARTS(
30 style != soeDEFAULT || !ta.isDefault(),
31 "xrpl::associateAsset",
32 "non-default value");
33 ta.associateAsset(asset);
34
35 // associateAsset in derived classes may change the underlying
36 // value, but it won't know anything about how the value relates to
37 // the SLE. If the template element is soeDEFAULT, and the value
38 // changed to the default value, remove the field.
39 if (style == soeDEFAULT && ta.isDefault())
40 sle.makeFieldAbsent(field);
41 }
42 }
43}
44
45} // namespace xrpl
Identifies fields.
Definition SField.h:126
@ sMD_NeedsAsset
Definition SField.h:138
A type which can be exported to a well known binary format.
Definition STBase.h:115
virtual bool isDefault() const
Definition STBase.cpp:112
SOEStyle getStyle(SField const &field) const
Definition STObject.cpp:575
int getCount() const
Definition STObject.h:996
STBase & getIndex(int offset)
Definition STObject.h:1008
void makeFieldAbsent(SField const &field)
Definition STObject.cpp:542
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:5
@ 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.