Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/hyperliquid/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ namespace hyperliquid
// Default vault/subaccount address used when a per-call vaultAddress isn't given - see
// Signing::prepareBodyForType for which action types this fallback does and doesn't apply to.
std::optional<std::string> vaultAddress;
// Set false to skip WebsocketMessageParser's extra DOM validation pass (see crack()).
bool validateJson = true;
};
}
4 changes: 3 additions & 1 deletion include/hyperliquid/websocket/WebsocketMessageParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>
#include <string_view>
#include "WebsocketMessageHandler.h"
#include "../config/Config.h"

namespace hyperliquid
{
Expand All @@ -14,7 +15,8 @@ namespace hyperliquid
class WebsocketMessageParser
{
public:
WebsocketMessageParser();
// See ApiConfig::validateJson.
explicit WebsocketMessageParser(const ApiConfig& config = ApiConfig{});
~WebsocketMessageParser();

WebsocketMessageParser(WebsocketMessageParser&&) noexcept;
Expand Down
6 changes: 5 additions & 1 deletion src/websocket/WebsocketMessageParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ namespace hyperliquid
simdjson::ondemand::parser parser;
simdjson::padded_string padded;
simdjson::dom::parser domParser;
bool validateJson_;

explicit Impl(bool validateJson) : validateJson_(validateJson) {}

// simdjson's ondemand API can hit an internal assertion (abort) rather than a catchable
// simdjson_error when a value is looked up by name more than once on the same malformed
Expand All @@ -111,6 +114,7 @@ namespace hyperliquid
// a structurally invalid document.
void validateStructure(std::string_view message)
{
if (!validateJson_) return;
domParser.parse(message.data(), message.size()).value();
}

Expand Down Expand Up @@ -1493,7 +1497,7 @@ namespace hyperliquid
}
};

WebsocketMessageParser::WebsocketMessageParser() : impl_(std::make_unique<Impl>()) {}
WebsocketMessageParser::WebsocketMessageParser(const ApiConfig& config) : impl_(std::make_unique<Impl>(config.validateJson)) {}

WebsocketMessageParser::~WebsocketMessageParser() = default;
WebsocketMessageParser::WebsocketMessageParser(WebsocketMessageParser&&) noexcept = default;
Expand Down
Loading