Skip to content

Commit

Permalink
Merge pull request #2934 from Taraxa-project/remove_string_using
Browse files Browse the repository at this point in the history
chore: remove std::string using
  • Loading branch information
MatusKysel authored Jan 21, 2025
2 parents 6178b30 + 2fd1791 commit ce50f68
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 41 deletions.
4 changes: 2 additions & 2 deletions libraries/cli/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ bool Config::nodeConfigured() { return node_configured_; }

FullNodeConfig Config::getNodeConfiguration() { return node_config_; }

std::string Config::dirNameFromFile(const string& file) {
std::string Config::dirNameFromFile(const std::string& file) {
size_t pos = file.find_last_of("\\/");
return (string::npos == pos) ? "" : file.substr(0, pos);
return (std::string::npos == pos) ? "" : file.substr(0, pos);
}

} // namespace taraxa::cli
2 changes: 1 addition & 1 deletion libraries/config/src/genesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void dec_json(Json::Value const& json, GenesisConfig& obj) {
}

GenesisConfig::GenesisConfig() {
dag_genesis_block = DagBlock(string(R"({
dag_genesis_block = DagBlock(std::string(R"({
"level": 0,
"tips": [],
"trxs": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class StateAPI {
TransactionsExecutionResult result_buf_execution_result_;
dev::RLPStream rlp_enc_rewards_distribution_;
RewardsDistributionResult result_buf_rewards_distribution_;
string db_path_;
std::string db_path_;

public:
StateAPI(std::function<h256(EthBlockNumber)> get_blk_hash, const Config& state_config, const Opts& opts,
Expand Down
12 changes: 6 additions & 6 deletions libraries/core_libs/consensus/src/final_chain/state_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void from_rlp(taraxa_evm_Bytes b, Result& result) {
util::rlp(dev::RLP(map_bytes(b), 0), result);
}

void to_str(taraxa_evm_Bytes b, string& result) { result = {reinterpret_cast<char*>(b.Data), b.Len}; }
void to_str(taraxa_evm_Bytes b, std::string& result) { result = {reinterpret_cast<char*>(b.Data), b.Len}; }

void to_bytes(taraxa_evm_Bytes b, bytes& result) { result.assign(b.Data, b.Data + b.Len); }

Expand All @@ -48,20 +48,20 @@ class ErrorHandler {
this,
[](auto self, auto err_bytes) {
auto& raise = decltype(this)(self)->raise_;
static string const delim = ": ";
static std::string const delim = ": ";
static auto const delim_len = delim.size();
std::string_view err_str((char*)err_bytes.Data, err_bytes.Len);
auto delim_pos = err_str.find(delim);
string type(err_str.substr(0, delim_pos));
string msg(err_str.substr(delim_pos + delim_len));
std::string type(err_str.substr(0, delim_pos));
std::string msg(err_str.substr(delim_pos + delim_len));

if (type == "github.com/Taraxa-project/taraxa-evm/taraxa/state/state_db/ErrFutureBlock") {
raise = [err = ErrFutureBlock(std::move(type), msg)] { BOOST_THROW_EXCEPTION(err); };
return;
}

string traceback;
taraxa_evm_traceback(decoder_cb_c<string, to_str>(traceback));
std::string traceback;
taraxa_evm_traceback(decoder_cb_c<std::string, to_str>(traceback));
msg += "\nGo stack trace:\n" + traceback;
raise = [err = TaraxaEVMError(std::move(type), msg)] { BOOST_THROW_EXCEPTION(err); };
},
Expand Down
2 changes: 1 addition & 1 deletion libraries/core_libs/network/include/network/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Network {
// END METHODS USED IN TESTS ONLY

private:
static std::pair<bool, bi::tcp::endpoint> resolveHost(string const &addr, uint16_t port);
static std::pair<bool, bi::tcp::endpoint> resolveHost(std::string const &addr, uint16_t port);

/**
* @brief Register period events, e.g. sending status packet, transaction packet etc...
Expand Down
7 changes: 0 additions & 7 deletions libraries/core_libs/network/include/network/ws_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@

#include <jsonrpccpp/server/abstractserverconnector.h>

#include <algorithm>
#include <atomic>
#include <boost/asio/strand.hpp>
#include <boost/beast/core.hpp>
#include <boost/beast/websocket.hpp>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <memory>
#include <queue>
#include <string>
#include <thread>
#include <vector>

#include "common/thread_pool.hpp"
#include "config/config.hpp"
#include "dag/dag_block.hpp"
#include "final_chain/data.hpp"
#include "pbft/pbft_chain.hpp"
Expand All @@ -26,7 +20,6 @@
namespace taraxa::net {

namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>

Expand Down
4 changes: 2 additions & 2 deletions libraries/core_libs/network/rpc/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class Debug : public DebugFace {
state_api::EVMTransaction to_eth_trx(std::shared_ptr<Transaction> t) const;
state_api::EVMTransaction to_eth_trx(const Json::Value& json, EthBlockNumber blk_num);
std::vector<state_api::EVMTransaction> to_eth_trxs(const std::vector<std::shared_ptr<Transaction>>& trxs);
EthBlockNumber parse_blk_num(const string& blk_num_str);
EthBlockNumber parse_blk_num(const std::string& blk_num_str);
state_api::Tracing parse_tracking_parms(const Json::Value& json) const;
Address to_address(const string& s) const;
Address to_address(const std::string& s) const;
std::tuple<std::vector<state_api::EVMTransaction>, state_api::EVMTransaction, uint64_t> get_transaction_with_state(
const std::string& transaction_hash);

Expand Down
2 changes: 1 addition & 1 deletion libraries/core_libs/network/src/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Network::Network(const FullNodeConfig &config, const h256 &genesis_hash, std::fi
taraxa_net_conf.chain_id = config.genesis.chain_id;
taraxa_net_conf.expected_parallelism = tp_.capacity();

string net_version = "TaraxaNode"; // TODO maybe give a proper name?
const std::string net_version = "TaraxaNode"; // TODO maybe give a proper name?

// Create taraxa capabilities
dev::p2p::Host::CapabilitiesFactory constructCapabilities = [&](std::weak_ptr<dev::p2p::Host> host) {
Expand Down
2 changes: 1 addition & 1 deletion libraries/core_libs/network/src/ws_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void WsSession::run() {

// Set a decorator to change the Server of the handshake
ws_.set_option(websocket::stream_base::decorator([](websocket::response_type &res) {
res.set(http::field::server, std::string(BOOST_BEAST_VERSION_STRING) + " websocket-server-async");
res.set(beast::http::field::server, std::string(BOOST_BEAST_VERSION_STRING) + " websocket-server-async");
}));

// Accept the websocket handshake
Expand Down
14 changes: 7 additions & 7 deletions libraries/core_libs/storage/include/storage/storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ using OnEntry = std::function<void(Slice const&, Slice const&)>;
class DbStorage : public std::enable_shared_from_this<DbStorage> {
public:
class Column {
string const name_;
std::string const name_;

public:
size_t const ordinal_;
const rocksdb::Comparator* comparator_;

Column(string name, size_t ordinal, const rocksdb::Comparator* comparator)
Column(std::string name, size_t ordinal, const rocksdb::Comparator* comparator)
: name_(std::move(name)), ordinal_(ordinal), comparator_(comparator) {}

Column(string name, size_t ordinal) : name_(std::move(name)), ordinal_(ordinal), comparator_(nullptr) {}
Column(std::string name, size_t ordinal) : name_(std::move(name)), ordinal_(ordinal), comparator_(nullptr) {}

auto const& name() const { return ordinal_ ? name_ : rocksdb::kDefaultColumnFamilyName; }
};
Expand Down Expand Up @@ -311,8 +311,8 @@ class DbStorage : public std::enable_shared_from_this<DbStorage> {
std::vector<std::shared_ptr<PbftBlock>> getProposedPbftBlocks();

// pbft_blocks (head)
string getPbftHead(blk_hash_t const& hash);
void savePbftHead(blk_hash_t const& hash, string const& pbft_chain_head_str);
std::string getPbftHead(blk_hash_t const& hash);
void savePbftHead(blk_hash_t const& hash, std::string const& pbft_chain_head_str);
void addPbftHeadToBatch(taraxa::blk_hash_t const& head_hash, std::string const& head_str, Batch& write_batch);

// status
Expand Down Expand Up @@ -365,7 +365,7 @@ class DbStorage : public std::enable_shared_from_this<DbStorage> {

void compactColumn(Column const& column) { db_->CompactRange({}, handle(column), nullptr, nullptr); }

inline static bytes asBytes(string const& b) {
inline static bytes asBytes(std::string const& b) {
return bytes((byte const*)b.data(), (byte const*)(b.data() + b.size()));
}

Expand All @@ -391,7 +391,7 @@ class DbStorage : public std::enable_shared_from_this<DbStorage> {
return make_slice(&n, sizeof(N));
}

inline static Slice toSlice(string const& str) { return make_slice(str.data(), str.size()); }
inline static Slice toSlice(std::string const& str) { return make_slice(str.data(), str.size()); }

inline static auto const& toSlice(Slice const& s) { return s; }

Expand Down
8 changes: 5 additions & 3 deletions libraries/core_libs/storage/src/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ std::unique_ptr<rocksdb::Iterator> DbStorage::getColumnIterator(rocksdb::ColumnF

void DbStorage::checkStatus(rocksdb::Status const& status) {
if (status.ok()) return;
throw DbException(string("Db error. Status code: ") + std::to_string(status.code()) +
throw DbException(std::string("Db error. Status code: ") + std::to_string(status.code()) +
" SubCode: " + std::to_string(status.subcode()) + " Message:" + status.ToString());
}

Expand Down Expand Up @@ -1124,9 +1124,11 @@ bool DbStorage::pbftBlockInDb(blk_hash_t const& hash) {
return exist(toSlice(hash.asBytes()), Columns::pbft_block_period);
}

string DbStorage::getPbftHead(blk_hash_t const& hash) { return lookup(toSlice(hash.asBytes()), Columns::pbft_head); }
std::string DbStorage::getPbftHead(blk_hash_t const& hash) {
return lookup(toSlice(hash.asBytes()), Columns::pbft_head);
}

void DbStorage::savePbftHead(blk_hash_t const& hash, string const& pbft_chain_head_str) {
void DbStorage::savePbftHead(blk_hash_t const& hash, std::string const& pbft_chain_head_str) {
insert(Columns::pbft_head, toSlice(hash.asBytes()), pbft_chain_head_str);
}

Expand Down
3 changes: 1 addition & 2 deletions libraries/types/dag_block/include/dag/dag_block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace taraxa {

using std::string;
using VdfSortition = vdf_sortition::VdfSortition;

/**
Expand Down Expand Up @@ -49,7 +48,7 @@ class DagBlock {
DagBlock(blk_hash_t const &pivot, level_t level, vec_blk_t tips, vec_trx_t trxs, uint64_t est, VdfSortition vdf,
secret_t const &sk);
explicit DagBlock(Json::Value const &doc);
explicit DagBlock(string const &json);
explicit DagBlock(std::string const &json);
explicit DagBlock(dev::RLP const &_rlp);
explicit DagBlock(dev::RLP const &_rlp, vec_trx_t &&trxs);
explicit DagBlock(dev::bytes const &_rlp) : DagBlock(dev::RLP(_rlp)) {}
Expand Down
2 changes: 1 addition & 1 deletion libraries/types/dag_block/src/dag_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ DagBlock::DagBlock(blk_hash_t const &pivot, level_t level, vec_blk_t tips, vec_t
sig_ = dev::sign(sk, sha3(false));
}

DagBlock::DagBlock(string const &json)
DagBlock::DagBlock(std::string const &json)
: DagBlock([&] {
Json::Value doc;
std::stringstream(json) >> doc;
Expand Down
4 changes: 2 additions & 2 deletions tests/crypto_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,14 @@ TEST_F(CryptoTest, keypair_signature_verify_hash_test) {
EXPECT_EQ(key_pair.pub().size, 64);
EXPECT_EQ(key_pair.secret().size, 32);

string message = "0123456789abcdef";
std::string message = "0123456789abcdef";
dev::Signature signature = dev::sign(key_pair.secret(), dev::sha3(message));
EXPECT_EQ(signature.size, 65);

bool verify = dev::verify(key_pair.pub(), signature, dev::sha3(message));
EXPECT_EQ(verify, true);

string credential = dev::sha3(signature).hex();
std::string credential = dev::sha3(signature).hex();
EXPECT_EQ(credential.length(), 64);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_util/include/test_util/samples.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace taraxa::core_tests::samples {

static string const greeter_contract_code =
static std::string const greeter_contract_code =
// pragma solidity ^0.6.8;
// contract Greeter {
// string public greeting;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_util/include/test_util/test_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const auto kContractAddress = addr_t("0x00000000000000000000000000000000000000FE

inline auto addr(const Secret& secret = Secret::random()) { return KeyPair(secret).address(); }

inline auto addr(const string& secret_str) { return addr(Secret(secret_str)); }
inline auto addr(const std::string& secret_str) { return addr(Secret(secret_str)); }

struct wait_opts {
nanoseconds timeout;
Expand Down
4 changes: 2 additions & 2 deletions tests/transaction_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ TEST_F(TransactionTest, sig) {
"4fb635e7237e0e8d3ea33bbea19c36ca0229e80d57ba91a0f347686"
"30fd21ad86e4c403b307de9ac4550d0ccc81c90fe3")),
Transaction::InvalidFormat);
std::vector<std::pair<uint64_t, string>> valid_cases{
std::vector<std::pair<uint64_t, std::string>> valid_cases{
{0, "0xf647d1d47ce927ce2fb9f57e4e2a3c32b037c5e544b44611077f5cc6980b0bc2"},
{1, "0x49c1cb845df5d3ed238ca37ad25ca96f417e4f22d7911224cf3c2a725985e7ff"},
{uint64_t(1) << uint(32), "0xc1651c53d21ad6ddaac0af7ad93947074ef9f3b03479a36b29fa577b9faba8a9"},
Expand Down Expand Up @@ -637,7 +637,7 @@ TEST_F(TransactionTest, typed_deserialization) {
} catch (const std::exception& e) {
const std::string exception_str = e.what();
EXPECT_TRUE(exception_str.find("Can't parse transaction from RLP. Use legacy transactions because typed "
"transactions aren't supported yet.") != string::npos);
"transactions aren't supported yet.") != std::string::npos);
return;
}
// shouldn't reach this code
Expand Down

0 comments on commit ce50f68

Please sign in to comment.