xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
protocol
STTakesAsset.cpp
1
#include <xrpl/protocol/STTakesAsset.h>
2
3
#include <xrpl/beast/utility/instrumentation.h>
4
#include <xrpl/protocol/Asset.h>
5
#include <xrpl/protocol/SField.h>
6
#include <xrpl/protocol/SOTemplate.h>
7
#include <xrpl/protocol/STBase.h>
8
#include <xrpl/protocol/STLedgerEntry.h>
9
10
namespace
xrpl
{
11
12
void
13
associateAsset
(
SLE
& sle,
Asset
const
& asset)
14
{
15
// Iterating by offset is the only way to get non-const references
16
for
(
int
i = 0; i < sle.
getCount
(); ++i)
17
{
18
STBase
& entry = sle.
getIndex
(i);
19
SField
const
& field = entry.getFName();
20
if
(field.
shouldMeta
(
SField::kSmdNeedsAsset
))
21
{
22
auto
const
type = entry.getSType();
23
// If the field is not set or present, skip it.
24
if
(type == STI_NOTPRESENT)
25
continue
;
26
27
// If the type doesn't downcast, then the flag shouldn't be on the
28
// SField
29
auto
& ta = entry.downcast<
STTakesAsset
>();
30
auto
const
style = sle.
getStyle
(ta.getFName());
31
XRPL_ASSERT_PARTS(
32
style !=
SoeInvalid
,
"xrpl::associateAsset"
,
"valid template element style"
);
33
34
XRPL_ASSERT_PARTS(
35
style !=
SoeDefault
|| !ta.isDefault(),
36
"xrpl::associateAsset"
,
37
"non-default value"
);
38
ta.associateAsset(asset);
39
40
// associateAsset in derived classes may change the underlying
41
// value, but it won't know anything about how the value relates to
42
// the SLE. If the template element is soeDEFAULT, and the value
43
// changed to the default value, remove the field.
44
if
(style ==
SoeDefault
&& ta.isDefault())
45
sle.
makeFieldAbsent
(field);
46
}
47
}
48
}
49
50
}
// namespace xrpl
xrpl::Asset
Definition
Asset.h:52
xrpl::SField
Identifies fields.
Definition
SField.h:132
xrpl::SField::kSmdNeedsAsset
static constexpr auto kSmdNeedsAsset
Definition
SField.h:143
xrpl::SField::shouldMeta
bool shouldMeta(int c) const
Definition
SField.h:265
xrpl::STBase
A type which can be exported to a well known binary format.
Definition
STBase.h:129
xrpl::STObject::getStyle
SOEStyle getStyle(SField const &field) const
Definition
STObject.cpp:583
xrpl::STObject::getCount
int getCount() const
Definition
STObject.h:1019
xrpl::STObject::getIndex
STBase & getIndex(int offset)
Definition
STObject.h:1031
xrpl::STObject::makeFieldAbsent
void makeFieldAbsent(SField const &field)
Definition
STObject.cpp:550
xrpl::STTakesAsset
Intermediate class for any STBase-derived class to store an Asset.
Definition
STTakesAsset.h:25
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::SoeDefault
@ SoeDefault
Definition
SOTemplate.h:24
xrpl::SoeInvalid
@ SoeInvalid
Definition
SOTemplate.h:21
xrpl::SLE
STLedgerEntry SLE
Definition
ServiceRegistry.h:42
xrpl::associateAsset
void associateAsset(STLedgerEntry &sle, Asset const &asset)
Associate an Asset with all sMD_NeedsAsset fields in a ledger entry.
Generated by
1.17.0