feat: Hook up amendment_enabled host function

This commit is contained in:
TimothyBanks
2026-08-10 16:06:05 -04:00
parent 9a6efde771
commit accd0cac6c
11 changed files with 141 additions and 1 deletions

View File

@@ -107,6 +107,34 @@ HostContext::getBaseFee(rust::Slice<std::uint8_t> out) const noexcept
});
}
std::int32_t
HostContext::isAmendmentEnabled(rust::Slice<std::uint8_t const> amendment) const noexcept
{
return guarded(hostFunctions_.getJournal(), kHostInternal, [&] {
// A 32-byte input may be an amendment id; try that first and fall through to
// a name lookup if it is not an enabled amendment - the 32 bytes could spell
// a name instead.
if (amendment.size() == uint256::size())
{
auto const enabled =
hostFunctions_.isAmendmentEnabled(uint256::fromVoid(amendment.data()));
if (enabled && *enabled == 1)
return *enabled;
}
if (amendment.size() > 64)
return hfErrorToInt(HostFunctionError::DataFieldTooLarge);
auto const name =
std::string_view(reinterpret_cast<char const*>(amendment.data()), amendment.size());
auto const enabled = hostFunctions_.isAmendmentEnabled(name);
if (!enabled)
return hfErrorToInt(enabled.error());
return *enabled;
});
}
std::int32_t
HostContext::getCurrentLedgerObjField(std::int32_t field, rust::Slice<std::uint8_t> out)
const noexcept