26 using ::pineforge::detail::strategy_module_symbol;
27 const auto version = strategy_module_symbol(host,
"strategy_capabilities_api_version",
30 const auto read = strategy_module_symbol(host,
"strategy_capabilities_receipt",
32 std::size_t required = 0;
34 required < 2 || required > 1024 * 1024)
36 std::vector<char> receipt(required,
'\1');
37 std::size_t written = 0;
38 if (read(&host, receipt.data(), receipt.size(), &written,
nullptr, 0) !=
PF_SETTINGS_OK ||
39 written != required || receipt.back() !=
'\0')
42 constexpr auto invalid =
"invalid compiled strategy currency declaration";
45 document = live::parse_json(std::string_view(receipt.data(), written - 1));
46 if (document.at(
"version").integer<
unsigned>() != 1)
return false;
47 }
catch (
const std::runtime_error&) {
50 const auto* unresolved = document.find(
"unresolved");
51 if (!unresolved || unresolved->kind != live::Json::Kind::Array)
53 bool currency_unresolved =
false;
54 for (
const auto& field : unresolved->items) {
56 if (field.value ==
"currency") currency_unresolved =
true;
58 const auto* declarations = document.find(
"declarations");
59 if (!declarations || declarations->kind != live::Json::Kind::Object)
61 if (currency_unresolved)
return false;
62 const auto* currency = declarations->find(
"currency");
63 if (!currency || currency->kind != live::Json::Kind::String)
65 const std::string_view spelling = currency->value;
66 constexpr std::string_view prefix =
"currency.";
67 if (spelling.substr(0, prefix.size()) != prefix)
return false;
68 const auto code = spelling.substr(prefix.size());
69 return code ==
"NONE" || code == quote;