rippled
Loading...
Searching...
No Matches
STObjectValidation.h
1#pragma once
2
3#include <xrpl/protocol/SOTemplate.h>
4#include <xrpl/protocol/STObject.h>
5
7
8[[nodiscard]]
9inline bool
10validateSTObject(STObject const& obj, SOTemplate const& format)
11{
12 for (auto const& field : format)
13 {
14 if (!obj.isFieldPresent(field.sField()) && field.style() == soeREQUIRED)
15 {
16 return false; // LCOV_EXCL_LINE
17 }
18
19 if (field.supportMPT() == soeMPTNotSupported && obj.isFieldPresent(field.sField()))
20 {
21 if (field.sField().fieldType == STI_AMOUNT)
22 {
23 auto const& amount = obj.getFieldAmount(field.sField());
24
25 if (amount.asset().holds<MPTIssue>())
26 return false; // LCOV_EXCL_LINE
27 }
28 else if (field.sField().fieldType == STI_ISSUE)
29 {
30 auto issue = dynamic_cast<STIssue const*>(obj.peekAtPField(field.sField()));
31 if (!issue)
32 return false; // LCOV_EXCL_LINE
33
34 if (issue->holds<MPTIssue>())
35 return false; // LCOV_EXCL_LINE
36 }
37 }
38 }
39
40 return true;
41}
42
43} // namespace xrpl::protocol_autogen
Defines the fields and their attributes within a STObject.
Definition SOTemplate.h:92
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:456
STBase const * peekAtPField(SField const &field) const
Definition STObject.cpp:429
STAmount const & getFieldAmount(SField const &field) const
Definition STObject.cpp:649
bool validateSTObject(STObject const &obj, SOTemplate const &format)
@ soeREQUIRED
Definition SOTemplate.h:16
@ soeMPTNotSupported
Definition SOTemplate.h:24