Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qtils error #1865

Closed
wants to merge 2 commits into from
Closed
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 CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

cmake_minimum_required(VERSION 3.12)

cmake_policy(SET CMP0144 NEW)

find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
Expand Down
4 changes: 2 additions & 2 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ hunter_config(

hunter_config(
libp2p
VERSION 0.1.17
VERSION 0.1.17-qtils
KEEP_PACKAGE_SOURCES
)

Expand All @@ -66,7 +66,7 @@ hunter_config(

hunter_config(
scale
VERSION 1.1.0
VERSION 1.1.0-qtils
KEEP_PACKAGE_SOURCES
)

Expand Down
4 changes: 2 additions & 2 deletions cmake/Hunter/hunter-gate-url.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
HunterGate(
URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.23.257-qdrvm11.tar.gz
SHA1 b2a69ae501bdc99006fb86e55930640004468556
URL https://github.com/qdrvm/hunter/archive/refs/heads/turuslan/qtils.zip
SHA1 dd50fb297ba2d57bee6cb047beb81d433550da52
LOCAL
)
3 changes: 3 additions & 0 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ endif()
hunter_add_package(Boost COMPONENTS random filesystem program_options date_time)
find_package(Boost CONFIG REQUIRED random filesystem program_options date_time)

hunter_add_package(qtils)
find_package(qtils CONFIG REQUIRED)

# https://docs.hunter.sh/en/latest/packages/pkg/xxhash.html
hunter_add_package(xxhash)
find_package(xxhash CONFIG REQUIRED)
Expand Down
18 changes: 5 additions & 13 deletions core/api/jrpc/decode_args.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#pragma once

#include <jsonrpc-lean/request.h>
#include <qtils/unhex.hpp>

#include "primitives/mmr.hpp"

Expand All @@ -25,7 +26,7 @@ namespace kagome::api::details {
if (r) {
return std::move(r.value());
}
throw jsonrpc::InvalidParametersFault{r.error().message()};
throw jsonrpc::InvalidParametersFault{fmt::to_string(r.error())};
}

static auto &mapAt(const jsonrpc::Value &j, const std::string &k) {
Expand Down Expand Up @@ -99,21 +100,12 @@ namespace kagome::api::details {

template <size_t N>
static void loadValue(common::Blob<N> &out, const jsonrpc::Value &j) {
auto &s = j.AsString();
if (s.starts_with("0x")) {
out = unwrap(out.fromHexWithPrefix(s));
} else {
out = unwrap(out.fromHex(s));
}
out = unwrap(
qtils::unhex<common::Blob<N>>(j.AsString(), qtils::Unhex0x::Yes));
}

static void loadValue(common::Buffer &out, const jsonrpc::Value &j) {
auto &s = j.AsString();
if (s.starts_with("0x")) {
out = unwrap(common::unhexWith0x(s));
} else {
out = unwrap(common::unhex(s));
}
out = unwrap(qtils::unhex(j.AsString(), qtils::Unhex0x::Yes));
}

static void loadValue(primitives::MmrLeavesProof &out,
Expand Down
4 changes: 2 additions & 2 deletions core/api/jrpc/jrpc_method.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ namespace kagome::api {

// Init request
if (auto &&init_result = request.init(params); not init_result) {
throw jsonrpc::Fault(init_result.error().message());
throw jsonrpc::Fault(fmt::to_string(init_result.error()));
}

// Execute request
auto &&result = request.execute();

// Handle of failure
if (not result) {
throw jsonrpc::Fault(result.error().message());
throw jsonrpc::Fault(fmt::to_string(result.error()));
}

if constexpr (std::is_same_v<decltype(result.value()), void>) {
Expand Down
2 changes: 1 addition & 1 deletion core/api/jrpc/jrpc_server_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace kagome::api {
formatted_response->GetSize()));

} catch (const Fault &ex) {
cb(outcome::failure(Error::JSON_FORMAT_FAILED));
cb(Q_ERROR(Error::JSON_FORMAT_FAILED));
}

metric_rpc_requests_count_->inc();
Expand Down
1 change: 1 addition & 0 deletions core/api/jrpc/jrpc_server_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#pragma once

#include <jsonrpc-lean/server.h>
#include <qtils/enum_error_code.hpp>

#include "api/jrpc/jrpc_server.hpp"
#include "metrics/metrics.hpp"
Expand Down
6 changes: 3 additions & 3 deletions core/api/jrpc/value_converter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ namespace kagome::api {

template <size_t N>
inline jsonrpc::Value makeValue(const common::Blob<N> &val) {
return common::hex_lower_0x(val.data(), val.size());
return common::hex_lower_0x(val);
}

inline jsonrpc::Value makeValue(const common::Buffer &val) {
return common::hex_lower_0x(val.asVector().data(), val.asVector().size());
return common::hex_lower_0x(val);
}

inline jsonrpc::Value makeValue(common::BufferView val) {
return common::hex_lower_0x(val.data(), val.size());
return common::hex_lower_0x(val);
}

inline jsonrpc::Value makeValue(const primitives::DigestItem &val) {
Expand Down
8 changes: 4 additions & 4 deletions core/api/service/author/impl/author_api_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace kagome::api {
}
types.pop_back();
SL_INFO(logger_, "Unsupported key type, only [{}] are accepted", types);
return outcome::failure(crypto::CryptoStoreError::UNSUPPORTED_KEY_TYPE);
return Q_ERROR(crypto::CryptoStoreError::UNSUPPORTED_KEY_TYPE);
};
if (crypto::KeyTypes::BABE == key_type_id
or crypto::KeyTypes::AUTHORITY_DISCOVERY == key_type_id) {
Expand All @@ -83,7 +83,7 @@ namespace kagome::api {
OUTCOME_TRY(keypair,
store_->generateSr25519Keypair(key_type_id, seed_typed));
if (public_key_typed != keypair.public_key) {
return outcome::failure(crypto::CryptoStoreError::WRONG_PUBLIC_KEY);
return Q_ERROR(crypto::CryptoStoreError::WRONG_PUBLIC_KEY);
}
}
if (crypto::KeyTypes::GRANDPA == key_type_id) {
Expand All @@ -94,7 +94,7 @@ namespace kagome::api {
store_->generateEd25519Keypair(crypto::KeyTypes::GRANDPA,
seed_typed));
if (public_key_typed != keypair.public_key) {
return outcome::failure(crypto::CryptoStoreError::WRONG_PUBLIC_KEY);
return Q_ERROR(crypto::CryptoStoreError::WRONG_PUBLIC_KEY);
}
}
auto res = key_store_->saveKeyPair(key_type_id, public_key, seed);
Expand Down Expand Up @@ -162,7 +162,7 @@ namespace kagome::api {
AuthorApiImpl::removeExtrinsic(
const std::vector<primitives::ExtrinsicKey> &keys) {
BOOST_ASSERT_MSG(false, "not implemented"); // NOLINT
return outcome::failure(std::errc::not_supported);
return Q_ERROR(std::errc::not_supported);
}

outcome::result<AuthorApi::SubscriptionId>
Expand Down
4 changes: 2 additions & 2 deletions core/api/service/chain/impl/chain_api_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace kagome::api {
if (block) {
return block.value();
}
return Error::BLOCK_NOT_FOUND;
return Q_ERROR(Error::BLOCK_NOT_FOUND);
}

outcome::result<primitives::BlockData> ChainApiImpl::getBlock() {
Expand All @@ -96,7 +96,7 @@ namespace kagome::api {
if (block) {
return block.value();
}
return Error::BLOCK_NOT_FOUND;
return Q_ERROR(Error::BLOCK_NOT_FOUND);
}

outcome::result<primitives::BlockHash> ChainApiImpl::getFinalizedHead()
Expand Down
2 changes: 1 addition & 1 deletion core/api/service/internal/impl/internal_api_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace kagome::api {
OUTCOME_TRY(level, log::str2lvl(level_str));

if (not log::setLevelOfGroup(group, level)) {
return log::Error::WRONG_GROUP;
return Q_ERROR(log::Error::WRONG_GROUP);
}

return outcome::success();
Expand Down
2 changes: 1 addition & 1 deletion core/api/service/jrpc_fn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace kagome::api {
}
return {};
}
throw jsonrpc::Fault(result.error().message());
throw jsonrpc::Fault(fmt::to_string(result.error()));
} else {
call();
return {};
Expand Down
6 changes: 3 additions & 3 deletions core/api/service/state/impl/state_api_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,17 @@ namespace kagome::api {
auto to =
opt_to.has_value() ? opt_to.value() : block_tree_->bestBlock().hash;
if (keys.size() > static_cast<ssize_t>(kMaxKeySetSize)) {
return Error::MAX_KEY_SET_SIZE_EXCEEDED;
return Q_ERROR(Error::MAX_KEY_SET_SIZE_EXCEEDED);
}

if (from != to) {
OUTCOME_TRY(from_number, header_repo_->getNumberByHash(from));
OUTCOME_TRY(to_number, header_repo_->getNumberByHash(to));
if (to_number < from_number) {
return Error::END_BLOCK_LOWER_THAN_BEGIN_BLOCK;
return Q_ERROR(Error::END_BLOCK_LOWER_THAN_BEGIN_BLOCK);
}
if (to_number - from_number > kMaxBlockRange) {
return Error::MAX_BLOCK_RANGE_EXCEEDED;
return Q_ERROR(Error::MAX_BLOCK_RANGE_EXCEEDED);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/api/transport/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#pragma once

#include "outcome/outcome.hpp"
#include <qtils/enum_error_code.hpp>

namespace kagome::api {
enum class ApiTransportError {
Expand Down
3 changes: 2 additions & 1 deletion core/api/transport/impl/ws/ws_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

#include <boost/asio/dispatch.hpp>
#include <boost/config.hpp>
#include <libp2p/outcome/outcome.hpp>

#include "log/formatters/boost_ec.hpp"

namespace boost::beast {
template <class NextLayer, class DynamicBuffer>
Expand Down
8 changes: 4 additions & 4 deletions core/application/impl/app_configuration_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,11 @@ namespace kagome::application {
"Address cannot be used to bind to ({}). Only IPv4 and IPv6 "
"interfaces are supported",
multiaddress.getStringAddress());
return NOT_SUPPORTED;
return Q_ERROR(NOT_SUPPORTED);
}
auto port = multiaddress.getFirstValueForProtocol(proto::TCP);
if (not port) {
return NOT_SUPPORTED;
return Q_ERROR(NOT_SUPPORTED);
}
uint16_t port_number = 0;
try {
Expand All @@ -598,7 +598,7 @@ namespace kagome::application {
wide_port,
max_port,
multiaddress.getStringAddress());
return BAD_ADDRESS;
return Q_ERROR(BAD_ADDRESS);
}
port_number = static_cast<uint16_t>(wide_port);
} catch (...) {
Expand All @@ -607,7 +607,7 @@ namespace kagome::application {
"Passed value {} is not a valid port number within address {}",
port.value(),
multiaddress.getStringAddress());
return BAD_ADDRESS;
return Q_ERROR(BAD_ADDRESS);
}
return getEndpointFrom(host.value(), port_number);
}
Expand Down
12 changes: 6 additions & 6 deletions core/application/impl/chain_spec_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace kagome::application {
} catch (pt::json_parser_error &e) {
log_->error(
"Parser error: {}, line {}: {}", e.filename(), e.line(), e.message());
return Error::PARSER_ERROR;
return Q_ERROR(Error::PARSER_ERROR);
}

OUTCOME_TRY(loadFields(tree));
Expand Down Expand Up @@ -195,7 +195,7 @@ namespace kagome::application {
block_id_str.data() + block_id_str.size(),
block_num);
if (res.ec != std::errc()) {
return Error::PARSER_ERROR;
return Q_ERROR(Error::PARSER_ERROR);
}
block_id = block_num;
}
Expand All @@ -205,7 +205,7 @@ namespace kagome::application {
outcome::result<common::Buffer> ChainSpecImpl::fetchCodeSubstituteByBlockInfo(
const primitives::BlockInfo &block_info) const {
if (!known_code_substitutes_->contains(block_info)) {
return Error::MISSING_ENTRY;
return Q_ERROR(Error::MISSING_ENTRY);
}

pt::ptree tree;
Expand All @@ -214,7 +214,7 @@ namespace kagome::application {
} catch (pt::json_parser_error &e) {
log_->error(
"Parser error: {}, line {}: {}", e.filename(), e.line(), e.message());
return Error::PARSER_ERROR;
return Q_ERROR(Error::PARSER_ERROR);
}

auto code_substitutes_opt = tree.get_child_optional("codeSubstitutes");
Expand All @@ -234,7 +234,7 @@ namespace kagome::application {
}
}
}
return Error::MISSING_ENTRY;
return Q_ERROR(Error::MISSING_ENTRY);
}

outcome::result<void> ChainSpecImpl::loadGenesis(
Expand Down Expand Up @@ -293,7 +293,7 @@ namespace kagome::application {
OUTCOME_TRY(libp2p::peer::PeerId::fromBase58(peer_id_base58.value()));
boot_nodes_.emplace_back(std::move(multiaddr));
} else {
return Error::MISSING_PEER_ID;
return Q_ERROR(Error::MISSING_PEER_ID);
}
} else {
log_->warn("Unsupported multiaddress '{}'. Ignoring that boot node",
Expand Down
2 changes: 1 addition & 1 deletion core/application/impl/chain_spec_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace kagome::application {
if (not opt_entry) {
log_->error("Required '{}' entry not found in the chain spec",
entry_name);
return Error::MISSING_ENTRY;
return Q_ERROR(Error::MISSING_ENTRY);
}
return opt_entry.value();
}
Expand Down
12 changes: 5 additions & 7 deletions core/application/impl/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

#include "application/impl/util.hpp"

#define UNWRAP_ERROR_CODE(ec) \
{ \
if (ec) { \
return outcome::failure(ec); \
} \
#define UNWRAP_ERROR_CODE(ec) \
if (ec) { \
return Q_ERROR(ec); \
}

OUTCOME_CPP_DEFINE_CATEGORY(kagome::application::util, Error, e) {
Expand All @@ -34,12 +32,12 @@ namespace kagome::application::util {
if (not fs::exists(path, ec)) {
UNWRAP_ERROR_CODE(ec)
if (not fs::create_directory(path, ec)) {
return Error::FAILED_TO_CREATE_DIR;
return Q_ERROR(Error::FAILED_TO_CREATE_DIR);
}
UNWRAP_ERROR_CODE(ec)
} else {
if (not fs::is_directory(path, ec)) {
return Error::NOT_A_DIR;
return Q_ERROR(Error::NOT_A_DIR);
}
UNWRAP_ERROR_CODE(ec)
}
Expand Down
2 changes: 2 additions & 0 deletions core/application/impl/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#pragma once

#include <qtils/enum_error_code.hpp>

#include "filesystem/common.hpp"
#include "outcome/outcome.hpp"

Expand Down
Loading
Loading