Skip to content
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
17 changes: 16 additions & 1 deletion src/impl/dgb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,23 @@
# slice under daemon/. Top-level add_subdirectory(src/impl/dgb) registration
# follows the OBJECT-lib convention PR; held ~2-3 heartbeats, not raced here.
if(COIN_DGB)
message(STATUS "c2pool: DGB Scrypt-only coin module enabled (skeleton)")
message(STATUS "c2pool: DGB Scrypt-only coin module enabled")
add_subdirectory(coin)
# add_subdirectory(daemon)
# add_subdirectory(test)

# dgb -- DGB Scrypt pool-layer OBJECT lib. Mirrors the ltc OBJECT lib
# (src/impl/ltc/CMakeLists.txt): compiles the real NodeImpl translation unit
# (node.cpp + protocol handlers) so share_tracker.hpp / share_check.hpp are
# pulled into a compiled TU. Links the shared core / pool / sharechain base
# plus dgb_coin (embedded P2P+mempool) and c2pool_storage (LevelDB sharechain).
add_library(dgb OBJECT
config_coin.hpp config_coin.cpp config_pool.hpp config_pool.cpp
node.hpp node.cpp
peer.hpp
protocol_actual.cpp protocol_legacy.cpp
messages.hpp
share_types.hpp share.hpp
)
target_link_libraries(dgb core pool sharechain dgb_coin btclibs c2pool_storage ${SECP256K1_LIBRARIES})
endif()
35 changes: 35 additions & 0 deletions src/impl/dgb/config_coin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "config_coin.hpp"

#include <btclibs/util/strencodings.h>

namespace dgb
{

std::ofstream& CoinConfig::get_default(std::ofstream& file)
{
YAML::Node out;

out["symbol"] = "defaultNet";
out["p2p"] = config::P2PData();
out["rpc"] = config::RPCData();
out["share_period"] = 0;
out["testnet"] = false;

file << out;
return file;
}

void CoinConfig::load()
{
YAML::Node node = YAML::LoadFile(m_filepath.string());

PARSE_CONFIG(node, symbol, std::string);

m_p2p = node["p2p"].as<config::P2PData>();
m_rpc = node["rpc"].as<config::RPCData>();

PARSE_CONFIG(node, share_period, int);
PARSE_CONFIG(node, testnet, bool);
}

} // namespace dgb
46 changes: 46 additions & 0 deletions src/impl/dgb/config_coin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <core/fileconfig.hpp>
#include <core/netaddress.hpp>

#include <yaml-cpp/yaml.h>
#include <btclibs/util/strencodings.h>

#include <cstdint>
#include <algorithm>

Expand All @@ -25,6 +28,49 @@ namespace config
};

} // config
} // namespace dgb

namespace YAML
{
template<> struct convert<dgb::config::P2PData>
{
static Node encode(const dgb::config::P2PData& rhs)
{
Node node;
node["prefix"] = HexStr(rhs.prefix);
node["address"] = rhs.address;
return node;
}

static bool decode(const Node& node, dgb::config::P2PData& rhs)
{
rhs.prefix = ParseHexBytes(node["prefix"].as<std::string>());
rhs.address = node["address"].as<NetService>();
return true;
}
};

template<> struct convert<dgb::config::RPCData>
{
static Node encode(const dgb::config::RPCData& rhs)
{
Node node;
node["address"] = rhs.address;
node["userpass"] = rhs.userpass;
return node;
}

static bool decode(const Node& node, dgb::config::RPCData& rhs)
{
rhs.address = node["address"].as<NetService>();
rhs.userpass = node["userpass"].as<std::string>();
return true;
}
};
}

namespace dgb
{

/// DigiByte Scrypt coin parameters.
/// Source of truth: p2pool-dgb-scrypt oracle bitcoin/networks/digibyte.py
Expand Down
48 changes: 48 additions & 0 deletions src/impl/dgb/config_pool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "config_pool.hpp"

#include <btclibs/util/strencodings.h>
#include <yaml-cpp/yaml.h>

namespace dgb
{

std::ofstream& PoolConfig::get_default(std::ofstream& file)
{
YAML::Node out;

// Use the canonical LTC p2pool mainnet prefix when no prefix is set yet
out["prefix"] = m_prefix.empty() ? DEFAULT_PREFIX_HEX : HexStr(m_prefix);
out["worker"] = m_worker;

YAML::Node addrs_node;
for (const auto& host : DEFAULT_BOOTSTRAP_HOSTS)
addrs_node.push_back(host + ":" + std::to_string(P2P_PORT));
out["bootstrap_addrs"] = addrs_node;

file << out;
return file;
}

void PoolConfig::load()
{
YAML::Node node = YAML::LoadFile(m_filepath.string());

// prefix
m_prefix = ParseHexBytes(node["prefix"].as<std::string>());

PARSE_CONFIG(node, worker, std::string);

// Bootstrap addresses: load from YAML if present, otherwise use hardcoded defaults
if (node["bootstrap_addrs"] && node["bootstrap_addrs"].IsSequence())
{
for (const auto& item : node["bootstrap_addrs"])
m_bootstrap_addrs.emplace_back(item.as<std::string>());
}
else
{
for (const auto& host : DEFAULT_BOOTSTRAP_HOSTS)
m_bootstrap_addrs.emplace_back(host + ":" + std::to_string(P2P_PORT));
}
}

} // namespace dgb
Loading