Switch version strings to string_view's

This commit is contained in:
Jason Rhinelander 2020-11-27 21:31:44 -04:00
parent 3eeb295f16
commit a56284e311
7 changed files with 16 additions and 13 deletions

View file

@ -559,7 +559,7 @@ namespace tx {
tsx_data.set_num_inputs(static_cast<google::protobuf::uint32>(input_size));
tsx_data.set_mixin(static_cast<google::protobuf::uint32>(tx.sources[0].outputs.size() - 1));
tsx_data.set_account(tx.subaddr_account);
tsx_data.set_monero_version(std::string(LOKI_VERSION_STR) + "|" + LOKI_VERSION_TAG);
tsx_data.set_monero_version(std::string{LOKI_VERSION_STR} + "|" + std::string{LOKI_VERSION_TAG});
tsx_data.set_hard_fork(m_aux_data->hard_fork ? *m_aux_data->hard_fork : 0);
if (client_version() <= 1){

View file

@ -73,7 +73,7 @@ public:
{
if (!base_url_.empty())
set_base_url(std::move(base_url_));
session.SetUserAgent("loki rpc client v"s + LOKI_VERSION_STR);
session.SetUserAgent("loki rpc client v" + std::string{LOKI_VERSION_STR});
}
/// Sets the base_url to the given one. Will have / appended if it doesn't already end in /. The

View file

@ -581,7 +581,7 @@ namespace cryptonote::rpc {
throw std::logic_error{"Cannot call http_server::start() more than once"};
auto net = m_server.nettype();
m_server_header = "lokid/"s + (m_restricted ? std::to_string(LOKI_VERSION[0]) : LOKI_VERSION_FULL)
m_server_header = "lokid/"s + (m_restricted ? std::to_string(LOKI_VERSION[0]) : std::string{LOKI_VERSION_FULL})
+ (net == MAINNET ? " mainnet" : net == TESTNET ? " testnet" : net == DEVNET ? " devnet" : net == FAKECHAIN ? " fakenet" : " unknown net");
m_startup_promise.set_value(true);

View file

@ -78,7 +78,7 @@ namespace cryptonote::rpc {
// An optional required login for this HTTP RPC interface
std::optional<tools::login> m_login;
// Cached string we send for the Server header
std::string m_server_header = "Loki RPC HTTP/"s + LOKI_VERSION_STR;
std::string m_server_header = "Loki RPC HTTP/" + std::string{LOKI_VERSION_STR};
// Access-Control-Allow-Origin header values; if one of these match the incoming Origin header
// we return it in the ACAO header; otherwise (or if this is empty) we omit the header entirely.
std::unordered_set<std::string> m_cors;

View file

@ -1,8 +1,10 @@
#include "version.h"
using namespace std::literals;
const std::array<uint16_t, 3> LOKI_VERSION = {@PROJECT_VERSION_MAJOR@, @PROJECT_VERSION_MINOR@, @PROJECT_VERSION_PATCH@};
const char* const LOKI_VERSION_TAG = "@VERSIONTAG@";
const char* const LOKI_VERSION_STR = "@PROJECT_VERSION@";
const char* const LOKI_RELEASE_NAME = "@LOKI_RELEASE_CODENAME@";
const char* const LOKI_VERSION_FULL = "@PROJECT_VERSION@-@VERSIONTAG@@LOKI_RELEASE_SUFFIX@";
const std::string_view LOKI_VERSION_TAG = "@VERSIONTAG@"sv;
const std::string_view LOKI_VERSION_STR = "@PROJECT_VERSION@"sv;
const std::string_view LOKI_RELEASE_NAME = "@LOKI_RELEASE_CODENAME@"sv;
const std::string_view LOKI_VERSION_FULL = "@PROJECT_VERSION@-@VERSIONTAG@@LOKI_RELEASE_SUFFIX@"sv;

View file

@ -1,10 +1,11 @@
#pragma once
#include <cstdint>
#include <array>
#include <string_view>
extern const std::array<uint16_t, 3> LOKI_VERSION;
extern const char* const LOKI_VERSION_TAG;
extern const char* const LOKI_VERSION_STR;
extern const char* const LOKI_RELEASE_NAME;
extern const char* const LOKI_VERSION_FULL;
extern const std::string_view LOKI_VERSION_TAG;
extern const std::string_view LOKI_VERSION_STR;
extern const std::string_view LOKI_RELEASE_NAME;
extern const std::string_view LOKI_VERSION_FULL;

View file

@ -497,7 +497,7 @@ namespace tools
m_restricted = command_line::get_arg(m_vm, arg_restricted);
m_server_header = "loki-wallet-rpc/"s + (m_restricted ? std::to_string(LOKI_VERSION[0]) : LOKI_VERSION_STR);
m_server_header = "loki-wallet-rpc/"s + (m_restricted ? std::to_string(LOKI_VERSION[0]) : std::string{LOKI_VERSION_STR});
m_cors = {rpc_config.access_control_origins.begin(), rpc_config.access_control_origins.end()};