Skip to content

Commit

Permalink
Fix clang-tidy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Jan 18, 2025
1 parent d86928a commit c708de9
Show file tree
Hide file tree
Showing 44 changed files with 184 additions and 146 deletions.
1 change: 1 addition & 0 deletions src/api-objects/src/apikeysprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "apikey.hpp"
#include "cct_const.hpp"
#include "cct_exception.hpp"
#include "cct_json.hpp"
#include "cct_log.hpp"
#include "cct_string.hpp"
#include "exchangename.hpp"
Expand Down
1 change: 0 additions & 1 deletion src/api-objects/src/closed-order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "order.hpp"
#include "orderid.hpp"
#include "timedef.hpp"
#include "timestring.hpp"
#include "tradeside.hpp"

namespace cct {
Expand Down
5 changes: 3 additions & 2 deletions src/api/common/src/commonapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "read-json.hpp"
#include "timedef.hpp"
#include "withdrawalfees-crawler.hpp"
#include "write-json.hpp"

namespace cct::api {
namespace {
Expand Down Expand Up @@ -152,10 +153,10 @@ CurrencyCodeVector CommonAPI::FiatsFunc::retrieveFiatsSource1() {
// data is UTF-8 encoded - but the relevant data that we will parse is ASCII normally

CurrencyCSV currencies;
auto ec = json::read<json::opts{.format = glz::CSV, .layout = glz::colwise}>(currencies, data);
auto ec = json::read<json::opts{.format = json::CSV, .layout = json::colwise}>(currencies, data);

if (ec || currencies.AlphabeticCode.size() != currencies.WithdrawalDate.size()) {
log::warn("Error parsing json data of currency codes from source 1: {}", glz::format_error(ec, data));
log::warn("Error parsing json data of currency codes from source 1: {}", json::format_error(ec, data));
return fiatsVec;
}

Expand Down
3 changes: 1 addition & 2 deletions src/api/common/src/withdrawalfees-crawler.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#include "withdrawalfees-crawler.hpp"

#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <string_view>
#include <utility>

Expand All @@ -12,6 +10,7 @@
#include "cct_cctype.hpp"
#include "cct_const.hpp"
#include "cct_exception.hpp"
#include "cct_json.hpp"
#include "cct_log.hpp"
#include "cct_string.hpp"
#include "coincenterinfo.hpp"
Expand Down
17 changes: 10 additions & 7 deletions src/api/common/test/exchangeprivateapi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@

namespace cct {

static inline BalancePortfolio operator+(const BalancePortfolio &balancePortfolio, const TradedAmounts &tradedAmounts) {
namespace {
BalancePortfolio addTradedAmounts(const BalancePortfolio &balancePortfolio, const TradedAmounts &tradedAmounts) {
BalancePortfolio ret = balancePortfolio;
ret += tradedAmounts.to;
ret += -tradedAmounts.from;
return ret;
}

} // namespace

static inline bool operator==(const TradedAmountsVectorWithFinalAmount &lhs,
const TradedAmountsVectorWithFinalAmount &rhs) {
return lhs.finalAmount == rhs.finalAmount && lhs.tradedAmountsVector == rhs.tradedAmountsVector;
Expand Down Expand Up @@ -444,11 +447,11 @@ TEST_F(ExchangePrivateTest, MakerTradeQuoteToBaseTimeout) {
EXPECT_EQ(exchangePrivate.trade(from, market.base(), tradeOptions), partialMatchedTradedAmounts);
}

static inline bool operator==(const InitiatedWithdrawInfo &lhs, const InitiatedWithdrawInfo &rhs) {
inline bool operator==(const InitiatedWithdrawInfo &lhs, const InitiatedWithdrawInfo &rhs) {
return lhs.withdrawId() == rhs.withdrawId();
}

static inline bool operator==(const SentWithdrawInfo &lhs, const SentWithdrawInfo &rhs) {
inline bool operator==(const SentWithdrawInfo &lhs, const SentWithdrawInfo &rhs) {
return lhs.withdrawStatus() == rhs.withdrawStatus() && lhs.netEmittedAmount() == rhs.netEmittedAmount();
}

Expand Down Expand Up @@ -788,15 +791,15 @@ TEST_F(ExchangePrivateDustSweeperTest, DustSweeper5Steps) {
TradedAmounts tradedAmounts1 = expectTakerBuy(xrpDustThreshold, xrpbtcAskPri, xrpbtcBidPri, xrpbtcMarket);
from += tradedAmounts1.to;

BalancePortfolio balance2 = balance1 + tradedAmounts1;
BalancePortfolio balance2 = addTradedAmounts(balance1, tradedAmounts1);

EXPECT_CALL(exchangePrivate, queryAccountBalance(balanceOptions)).WillOnce(testing::Return(balance2));

int percentXRPSoldSecondStep = 80;
TradedAmounts tradedAmounts2 = expectTakerSell(from, priBtc, percentXRPSoldSecondStep);
from -= tradedAmounts2.from;

BalancePortfolio balance3 = balance2 + tradedAmounts2;
BalancePortfolio balance3 = addTradedAmounts(balance2, tradedAmounts2);

EXPECT_CALL(exchangePrivate, queryAccountBalance(balanceOptions)).WillOnce(testing::Return(balance3));

Expand All @@ -810,13 +813,13 @@ TEST_F(ExchangePrivateDustSweeperTest, DustSweeper5Steps) {
TradedAmounts tradedAmounts3 = expectTakerBuy((3 * xrpDustThreshold) / 2, xrpeurAskPri, xrpeurBidPri, xrpeurMarket);
from += tradedAmounts3.to;

BalancePortfolio balance4 = balance3 + tradedAmounts3;
BalancePortfolio balance4 = addTradedAmounts(balance3, tradedAmounts3);
EXPECT_CALL(exchangePrivate, queryAccountBalance(balanceOptions)).WillOnce(testing::Return(balance4));

// Final sell that works
TradedAmounts tradedAmounts4 = expectTakerSell(from, priEur);

BalancePortfolio balance5 = balance4 + tradedAmounts4;
BalancePortfolio balance5 = addTradedAmounts(balance4, tradedAmounts4);

EXPECT_CALL(exchangePrivate, queryAccountBalance(balanceOptions)).WillOnce(testing::Return(balance5));

Expand Down
2 changes: 2 additions & 0 deletions src/api/common/test/fiatconverter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

#include "../src/fiats-converter-responses-schema.hpp"
#include "besturlpicker.hpp"
#include "cct_string.hpp"
#include "coincenterinfo.hpp"
#include "curlhandle.hpp"
#include "curloptions.hpp"
#include "permanentcurloptions.hpp"
#include "reader.hpp"
#include "runmodes.hpp"
#include "timedef.hpp"
#include "write-json.hpp"
Expand Down
1 change: 0 additions & 1 deletion src/api/exchanges/src/binancepublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "cachedresult.hpp"
#include "cct_const.hpp"
#include "cct_exception.hpp"
#include "cct_json.hpp"
#include "cct_log.hpp"
#include "cct_string.hpp"
#include "coincenterinfo.hpp"
Expand Down
1 change: 0 additions & 1 deletion src/api/exchanges/src/bithumbprivateapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "cachedresult.hpp"
#include "cct_exception.hpp"
#include "cct_fixedcapacityvector.hpp"
#include "cct_json.hpp"
#include "cct_log.hpp"
#include "cct_smallvector.hpp"
#include "cct_string.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/api/exchanges/src/bithumbpublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <string_view>
#include <type_traits>
#include <utility>
#include <variant>

#include "apiquerytypeenum.hpp"
#include "bithumb-schema.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/api/exchanges/src/huobiprivateapi.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "huobiprivateapi.hpp"

#include <algorithm>
#include <amc/isdetected.hpp>
#include <chrono>
#include <cstdint>
#include <cstring>
Expand Down
11 changes: 7 additions & 4 deletions src/api/exchanges/src/huobipublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "apiquerytypeenum.hpp"
#include "cachedresult.hpp"
#include "cct_const.hpp"
#include "cct_json.hpp"
#include "cct_log.hpp"
#include "cct_string.hpp"
#include "coincenterinfo.hpp"
Expand All @@ -26,6 +27,7 @@
#include "currencycodeset.hpp"
#include "currencyexchange.hpp"
#include "currencyexchangeflatset.hpp"
#include "exchange-asset-config.hpp"
#include "exchangepublicapi.hpp"
#include "exchangepublicapitypes.hpp"
#include "fiatconverter.hpp"
Expand Down Expand Up @@ -130,13 +132,14 @@ schema::huobi::V2ReferenceCurrency HuobiPublic::TradableCurrenciesFunc::operator
return PublicQuery<schema::huobi::V2ReferenceCurrency>(_curlHandle, "/v2/reference/currencies");
}

namespace {
CurrencyChainPicker<schema::huobi::V2ReferenceCurrencyDetails::Chain> CreateCurrencyChainPicker(
const schema::ExchangeAssetConfig& assetConfig) {
return CurrencyChainPicker<schema::huobi::V2ReferenceCurrencyDetails::Chain>(
assetConfig, [](const schema::huobi::V2ReferenceCurrencyDetails::Chain& chain) -> std::string_view {
return chain.displayName;
});
return {assetConfig, [](const schema::huobi::V2ReferenceCurrencyDetails::Chain& chain) -> std::string_view {
return chain.displayName;
}};
}
} // namespace

HuobiPublic::WithdrawParams HuobiPublic::getWithdrawParams(CurrencyCode cur) {
WithdrawParams withdrawParams;
Expand Down
6 changes: 4 additions & 2 deletions src/api/exchanges/src/krakenprivateapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include <optional>
#include <string_view>
#include <tuple>
#include <type_traits>
#include <utility>
#include <variant>

#include "apikey.hpp"
#include "apiquerytypeenum.hpp"
Expand Down Expand Up @@ -228,7 +230,7 @@ Wallet KrakenPrivate::DepositWalletFunc::operator()(CurrencyCode currencyCode) {
[&tag](auto&& field) {
using T = std::decay_t<decltype(field)>;
if constexpr (std::is_same_v<T, string>) {
tag = std::move(field);
tag = std::forward<decltype(field)>(field);
} else if constexpr (std::is_same_v<T, int64_t>) {
tag = IntegralToString(field);
} else {
Expand All @@ -242,7 +244,7 @@ Wallet KrakenPrivate::DepositWalletFunc::operator()(CurrencyCode currencyCode) {
[&tag](auto&& field) {
using T = std::decay_t<decltype(field)>;
if constexpr (std::is_same_v<T, string>) {
tag = std::move(field);
tag = std::forward<decltype(field)>(field);
} else if constexpr (std::is_same_v<T, int64_t>) {
tag = IntegralToString(field);
} else {
Expand Down
1 change: 1 addition & 0 deletions src/api/exchanges/src/krakenpublicapi.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "krakenpublicapi.hpp"

#include <algorithm>
#include <amc/isdetected.hpp>
#include <cstdint>
#include <optional>
#include <string_view>
Expand Down
2 changes: 2 additions & 0 deletions src/api/exchanges/src/kucoinprivateapi.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "kucoinprivateapi.hpp"

#include <algorithm>
#include <amc/isdetected.hpp>
#include <chrono>
#include <cstdint>
#include <string_view>
Expand Down Expand Up @@ -39,6 +40,7 @@
#include "orderid.hpp"
#include "ordersconstraints.hpp"
#include "permanentcurloptions.hpp"
#include "query-retry-policy.hpp"
#include "request-retry.hpp"
#include "ssl_sha.hpp"
#include "stringconv.hpp"
Expand Down
7 changes: 5 additions & 2 deletions src/api/exchanges/src/kucoinpublicapi.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "kucoinpublicapi.hpp"

#include <algorithm>
#include <amc/isdetected.hpp>
#include <array>
#include <cstdint>
#include <iterator>
Expand Down Expand Up @@ -116,9 +117,11 @@ KucoinPublic::TradableCurrenciesFunc::CurrencyInfoSet KucoinPublic::TradableCurr
continue;
}

const auto& chains = *curDetail.chains;

bool foundChain = false;
for (const auto& curChain : *curDetail.chains) {
if (curDetail.chains->size() > 1U && curChain.chainName != curStr &&
for (const auto& curChain : chains) {
if (chains.size() > 1U && curChain.chainName != curStr &&
(curChain.chainId.size() > CurrencyCode::kMaxLen || CurrencyCode(curChain.chainId) != cur)) {
log::debug("Discard {} as chain name is different from currency code", curStr);
continue;
Expand Down
14 changes: 14 additions & 0 deletions src/api/exchanges/src/upbit-schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ struct V1Deposit {

enum class State : int8_t { PROCESSING, REFUNDING, ACCEPTED, CANCELLED, REJECTED, TRAVEL_RULE_SUSPECTED, REFUNDED };

std::string_view timeStr() const {
if (done_at) {
return *done_at;
}
return created_at;
}

string currency;
string txid;
string created_at;
Expand All @@ -252,6 +259,13 @@ struct V1Withdraw {
// Let's support both spellings to avoid issues.
enum class State : int8_t { WAITING, PROCESSING, DONE, FAILED, CANCELLED, CANCELED, REJECTED };

std::string_view timeStr() const {
if (done_at) {
return *done_at;
}
return created_at;
}

string currency;
string txid;
string created_at;
Expand Down
15 changes: 10 additions & 5 deletions src/api/exchanges/src/upbitprivateapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <optional>
#include <string>
#include <string_view>
#include <thread>
#include <type_traits>
#include <utility>
#include <variant>

#include "apikey.hpp"
#include "apiquerytypeenum.hpp"
Expand All @@ -31,7 +31,6 @@
#include "currencyexchangeflatset.hpp"
#include "deposit.hpp"
#include "depositsconstraints.hpp"
#include "durationstring.hpp"
#include "exchange-tradefees-config.hpp"
#include "exchangename.hpp"
#include "exchangeprivateapi.hpp"
Expand All @@ -45,6 +44,7 @@
#include "orderid.hpp"
#include "ordersconstraints.hpp"
#include "permanentcurloptions.hpp"
#include "query-retry-policy.hpp"
#include "request-retry.hpp"
#include "ssl_sha.hpp"
#include "timedef.hpp"
Expand Down Expand Up @@ -235,7 +235,11 @@ Wallet UpbitPrivate::DepositWalletFunc::operator()(CurrencyCode currencyCode) {
"/v1/deposits/coin_address", postData, 10)
.first;
}
std::string_view tag = result.secondary_address.value_or("");

std::string_view tag;
if (result.secondary_address) {
tag = *result.secondary_address;
}

const CoincenterInfo& coincenterInfo = _exchangePublic.coincenterInfo();
bool doCheckWallet =
Expand Down Expand Up @@ -453,7 +457,7 @@ DepositsSet UpbitPrivate::queryRecentDeposits(const DepositsConstraints& deposit

// 'done_at' string is in this format: "2019-01-04T13:48:09+09:00"
// It can be empty for deposits that failed - take the start time instead of the end time in this case
std::string_view timeStr = trx.done_at.value_or(trx.created_at);
std::string_view timeStr = trx.timeStr();

TimePoint timestamp = StringToTime(timeStr, kTimeYearToSecondTSeparatedFormat);
if (!depositsConstraints.validateTime(timestamp)) {
Expand Down Expand Up @@ -529,7 +533,8 @@ WithdrawsSet UpbitPrivate::queryRecentWithdraws(const WithdrawsConstraints& with
MonetaryAmount withdrawFee(trx.fee, currencyCode);
// 'done_at' string is in this format: "2019-01-04T13:48:09+09:00"
// It can be empty for withdraws that failed - take the start time instead of the end time in this case
std::string_view timeStr = trx.done_at.value_or(trx.created_at);
std::string_view timeStr = trx.timeStr();

TimePoint timestamp = StringToTime(timeStr, kTimeYearToSecondTSeparatedFormat);
if (!withdrawsConstraints.validateTime(timestamp)) {
continue;
Expand Down
1 change: 0 additions & 1 deletion src/api/exchanges/src/upbitpublicapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <ranges>
#include <string_view>
#include <utility>
#include <variant>

#include "apiquerytypeenum.hpp"
#include "cachedresult.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/api/interface/include/exchange.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace cct {

class Exchange : public CacheFileUpdatorInterface {
class Exchange final : public CacheFileUpdatorInterface {
public:
using ExchangePublic = api::ExchangePublic;
using ExchangePrivate = api::ExchangePrivate;
Expand Down
1 change: 0 additions & 1 deletion src/api/interface/src/exchange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "cct_log.hpp"
#include "currencycode.hpp"
#include "currencyexchangeflatset.hpp"
#include "exchangename.hpp"
#include "exchangeprivateapi.hpp"
#include "exchangepublicapi.hpp"
#include "marketorderbook.hpp"
Expand Down
3 changes: 0 additions & 3 deletions src/basic-objects/src/coincentercommandtype.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#include "coincentercommandtype.hpp"

#include <string_view>
#include <type_traits>

namespace cct {

bool IsAnyTrade(CoincenterCommandType coincenterCommandType) {
Expand Down
Loading

0 comments on commit c708de9

Please sign in to comment.