From 014e85409afc8acfcfa655d8a1de9346c05b7882 Mon Sep 17 00:00:00 2001 From: novacypher Date: Fri, 31 Oct 2025 01:38:29 +0000 Subject: [PATCH 1/4] update dependencies --- CommonJS.h | 13 +++++++++++++ HexUtils.cpp | 34 ++++++++++++++++++++++++++++++++++ HexUtils.h | 14 ++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 HexUtils.cpp create mode 100644 HexUtils.h diff --git a/CommonJS.h b/CommonJS.h index f8a2837..29ed345 100644 --- a/CommonJS.h +++ b/CommonJS.h @@ -11,6 +11,16 @@ namespace dev { +std::string toHexBytes(dev::bytes const& data) +{ + return data.empty() ? std::string("0x") : toHexPrefixed(data); +} + +std::string toHexQuantity(uint64_t value) +{ + return toJS(value); +} + inline std::string toJS(byte _b) { return "0x" + std::to_string(_b); @@ -53,6 +63,9 @@ template std::string toJS(T const& _i) return stream.str(); } +std::string toHexBytes(dev::bytes const& data); +std::string toHexQuantity(uint64_t value); + enum class OnFailed { InterpretRaw, Empty, Throw }; /// Convert string to byte array. Input parameter is hex, optionally prefixed by "0x". diff --git a/HexUtils.cpp b/HexUtils.cpp new file mode 100644 index 0000000..f68c324 --- /dev/null +++ b/HexUtils.cpp @@ -0,0 +1,34 @@ +// Olympus: mcp C++ client, tools and libraries. +// Licensed under the GNU General Public License, Version 3. + +#include "HexUtils.h" + +std::string dev::toCompactHexFromIntx(intx::uint256 value) +{ + std::ostringstream out; + out << "0x"; + + if (value == 0) + { + out << '0'; + return out.str(); + } + + std::string hex; + hex.reserve(64); + + while (value != 0) + { + auto nibble = static_cast(value & intx::uint256{0xF}); + hex.push_back(nibble < 10 ? static_cast('0' + nibble) + : static_cast('a' + (nibble - 10))); + value >>= 4; + } + + if (hex.size() % 2 != 0) + hex.push_back('0'); + + std::reverse(hex.begin(), hex.end()); + out << hex; + return out.str(); +} \ No newline at end of file diff --git a/HexUtils.h b/HexUtils.h new file mode 100644 index 0000000..277c79a --- /dev/null +++ b/HexUtils.h @@ -0,0 +1,14 @@ +// Olympus: mcp C++ client, tools and libraries. +// Licensed under the GNU General Public License, Version 3. + +#pragma once + +#include +#include +#include +#include + +namespace dev +{ + std::string toCompactHexFromIntx(intx::uint256 value); +} \ No newline at end of file From f87080b47a806daa87751ef92328fa8877d19654 Mon Sep 17 00:00:00 2001 From: novacypher Date: Fri, 31 Oct 2025 01:42:52 +0000 Subject: [PATCH 2/4] chore: updates --- CommonJS.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CommonJS.cpp b/CommonJS.cpp index a1c7b93..45ad442 100644 --- a/CommonJS.cpp +++ b/CommonJS.cpp @@ -10,6 +10,16 @@ namespace dev { +std::string toHexBytes(dev::bytes const& data) +{ + return data.empty() ? std::string("0x") : toHexPrefixed(data); +} + +std::string toHexQuantity(uint64_t value) +{ + return toJS(value); +} + bytes jsToBytes(std::string const& _s, OnFailed _f) { try From 85bc1585af7ca52a690f4fef9668af685cd1095c Mon Sep 17 00:00:00 2001 From: novacypher Date: Fri, 31 Oct 2025 01:44:50 +0000 Subject: [PATCH 3/4] chore: updates --- CommonJS.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/CommonJS.h b/CommonJS.h index 29ed345..b5aaeb2 100644 --- a/CommonJS.h +++ b/CommonJS.h @@ -11,15 +11,6 @@ namespace dev { -std::string toHexBytes(dev::bytes const& data) -{ - return data.empty() ? std::string("0x") : toHexPrefixed(data); -} - -std::string toHexQuantity(uint64_t value) -{ - return toJS(value); -} inline std::string toJS(byte _b) { From b2c7ecf120c197d42700c0133a154fd5bcc90288 Mon Sep 17 00:00:00 2001 From: novacypher Date: Fri, 31 Oct 2025 01:45:21 +0000 Subject: [PATCH 4/4] chore: updates --- CommonJS.h | 1 - 1 file changed, 1 deletion(-) diff --git a/CommonJS.h b/CommonJS.h index b5aaeb2..003ff58 100644 --- a/CommonJS.h +++ b/CommonJS.h @@ -11,7 +11,6 @@ namespace dev { - inline std::string toJS(byte _b) { return "0x" + std::to_string(_b);