Skip to content

Commit

Permalink
Merge branch 'UCR-develop' of https://github.com/decenomy/DSW
Browse files Browse the repository at this point in the history
  • Loading branch information
zimbora committed May 3, 2024
2 parents 50574bd + dbdf36f commit dd8253e
Show file tree
Hide file tree
Showing 22 changed files with 1,648 additions and 108 deletions.
2 changes: 2 additions & 0 deletions contrib/pivx-qt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ HEADERS += src/activemasternode.h \
src/protocol.h \
src/pubkey.h \
src/random.h \
src/rewards.h \
src/rpcclient.h \
src/rpcprotocol.h \
src/rpcserver.h \
Expand Down Expand Up @@ -407,6 +408,7 @@ SOURCES += src/activemasternode.cpp \
src/pubkey.cpp \
src/random.cpp \
src/rest.cpp \
src/rewards.cpp \
src/rpcblockchain.cpp \
src/rpcclient.cpp \
src/rpcdump.cpp \
Expand Down
2 changes: 1 addition & 1 deletion docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Check if all required arguments are provided
if [ $# -ne 6 ]; then
echo "Usage: $0 <TICKER> <NAME> <BASE_NAME> <TARGET> <VERSION> <ARCHITECTURE>"
echo "Usage: $0 DSW __Decenomy__ __decenomy__ bootstrap 3.0.0.0 Linux"
echo "Usage: $0 DSW __Decenomy__ __decenomy__ develop 3.0.0.0 Linux"
exit 1
fi

Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ BITCOIN_CORE_H = \
random.h \
reverselock.h \
reverse_iterate.h \
rewards.h \
rpc/client.h \
rpc/protocol.h \
rpc/server.h \
Expand Down Expand Up @@ -241,6 +242,7 @@ libbitcoin_server_a_SOURCES = \
policy/policy.cpp \
pow.cpp \
rest.cpp \
rewards.cpp \
rpc/blockchain.cpp \
rpc/masternode.cpp \
rpc/mining.cpp \
Expand Down
51 changes: 25 additions & 26 deletions src/bootstrap/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ bool Bootstrap::rmDirectory(const std::string& directory_path) {
if (fs::exists(directory_path)) {
// Remove the directory and its contents
fs::remove_all(directory_path);
//std::cout << "Directory removed successfully." << std::endl;
//LogPrintf("-bootstrap: Directory removed successfully.");
} else {
//std::cerr << "Directory does not exist." << std::endl;
//LogPrintf("-bootstrap: Directory does not exist.");
}
} catch (const fs::filesystem_error& ex) {
//std::cerr << "Error removing directory: " << ex.what() << std::endl;
//LogPrintf("-bootstrap: Error removing directory: " << ex.what());
return false;
}

Expand Down Expand Up @@ -47,8 +47,7 @@ int Bootstrap::ProgressCallback(void *clientp, double dltotal, double dlnow, dou
auto duration = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch());
if(!log_flag && duration.count() % 2 == 0){
log_flag = true;
std::printf("-Bootstrap: Download: %d%%\n", (uint8_t)progress);
//LogPrintf("-Bootstrap: Download: %d%%\n", (uint8_t)progress);
LogPrintf("-bootstrap: Download: %d%%\n", (uint8_t)progress);
//uiInterface.ShowProgress(_("Download: "), (uint8_t)progress);
}else if(duration.count() % 2 != 0) log_flag = false;

Expand All @@ -60,24 +59,24 @@ bool Bootstrap::DownloadFile(const std::string& url, const std::string& outputFi

CURL* curl = curl_easy_init();
if (!curl) {
//std::cerr << "Error initializing libcurl." << std::endl;
//LogPrintf("-bootstrap: Error initializing libcurl.");
return false;
}

curl_version_info_data *info = curl_version_info(CURLVERSION_NOW);

if (info) {
// Print libcurl version information
printf("libcurl version: %s\n", info->version);
printf("libcurl SSL version: %s\n", info->ssl_version);
printf("libcurl zlib version: %s\n", info->libz_version);
LogPrintf("-bootstrap: libcurl version: %s \n", info->version);
LogPrintf("-bootstrap: libcurl SSL version: %s \n", info->ssl_version);
//LogPrintf("-bootstrap: libcurl zlib version: %s \n", info->libz_version);
} else {
printf("Failed to retrieve libcurl version information.\n");
LogPrintf("-bootstrap: Failed to retrieve libcurl version information.\n");
}

std::ofstream outputFile(outputFileName, std::ios::binary);
if (!outputFile.is_open()) {
//std::cerr << "Error opening output file." << std::endl;
LogPrintf("-bootstrap: Error opening output file.");
return false;
}

Expand All @@ -93,16 +92,16 @@ bool Bootstrap::DownloadFile(const std::string& url, const std::string& outputFi
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, func);

#if defined(__APPLE__)
std::cout << "apple ca path: " << (const char*)APPLE_CA_PATH << std::endl;
LogPrintf("-bootstrap: apple ca path: %s \n",(const char*)APPLE_CA_PATH);
curl_easy_setopt(curl, CURLOPT_CAINFO, (const char*)APPLE_CA_PATH);
#elif defined(__linux__)
//std::cout << "linux ca path: " << (const char*)LINUX_CA_PATH << std::endl;
//LogPrintf("-bootstrap: linux ca path: " << (const char*)LINUX_CA_PATH);
//curl_easy_setopt(curl, CURLOPT_CAINFO, (const char*)LINUX_CA_PATH);
#elif defined(_WIN32)
///std::cout << "windows ca path: " << (const char*)WIN_CA_PATH << std::endl;
///LogPrintf("-bootstrap: windows ca path: " << (const char*)WIN_CA_PATH);
//curl_easy_setopt(curl, CURLOPT_CAINFO, (const char*)WIN_CA_PATH);
#else
std::cerr << "OS not recognized, CA Path not defined" << std::endl;
LogPrintf("-bootstrap: OS not recognized, CA Path not defined");
#endif

CURLcode res = curl_easy_perform(curl);
Expand All @@ -111,7 +110,7 @@ bool Bootstrap::DownloadFile(const std::string& url, const std::string& outputFi
outputFile.close();

if (res != CURLE_OK) {
std::cerr << "Error downloading file: " << curl_easy_strerror(res) << std::endl;
LogPrintf("-bootstrap: Error downloading file: %s \n",curl_easy_strerror(res));
return false;
}

Expand All @@ -123,21 +122,21 @@ bool Bootstrap::extractZip(const std::string& zipFilePath, const std::string& ou
// Open the zip file
unzFile zipFile = unzOpen(zipFilePath.c_str());
if (!zipFile) {
std::cerr << "Error opening zip file: " << zipFilePath << std::endl;
LogPrintf("-bootstrap: Error opening zip file: %s \n",zipFilePath);
return false;
}

// Create the output folder if it doesn't exist
if (!ensureOutputFolder(outputFolderPath)) {
std::cerr << "Error creating output folder: " << outputFolderPath << std::endl;
LogPrintf("-bootstrap: Error creating output folder: %s \n",outputFolderPath);
unzClose(zipFile);
return false;
}

// Go through each file in the zip and extract it
unz_global_info globalInfo;
if (unzGetGlobalInfo(zipFile, &globalInfo) != UNZ_OK) {
std::cerr << "Error getting global info from zip file." << std::endl;
LogPrintf("-bootstrap: Error getting global info from zip file.");
unzClose(zipFile);
return false;
}
Expand All @@ -147,26 +146,26 @@ bool Bootstrap::extractZip(const std::string& zipFilePath, const std::string& ou
unz_file_info fileInfo;

if (unzGetCurrentFileInfo(zipFile, &fileInfo, fileName, sizeof(fileName), nullptr, 0, nullptr, 0) != UNZ_OK) {
std::cerr << "Error getting file info from zip file." << std::endl;
LogPrintf("-bootstrap: Error getting file info from zip file.");
unzClose(zipFile);
return false;
}

if (unzOpenCurrentFile(zipFile) != UNZ_OK) {
std::cerr << "Error opening current file in zip." << std::endl;
LogPrintf("-bootstrap: Error opening current file in zip.");
unzClose(zipFile);
return false;
}

std::string outputPath = std::string(outputFolderPath) + "/" + fileName;
std::cout << "extract file: " << fileName << std::endl;
LogPrintf("-bootstrap: extract file: %s \n",fileName);

if(endsWithSlash(outputPath))
ensureOutputFolder(outputPath);
else{
std::ofstream outFile(outputPath, std::ios::binary);
if (!outFile.is_open()) {
std::cerr << "Error creating output file: " << outputPath << std::endl;
LogPrintf("-bootstrap: Error creating output file: %s \n",outputPath);
unzCloseCurrentFile(zipFile);
unzClose(zipFile);
return false;
Expand All @@ -193,7 +192,7 @@ bool Bootstrap::extractZip(const std::string& zipFilePath, const std::string& ou
// Close the zip file
unzClose(zipFile);

std::cout << "Zip extraction successful." << std::endl;
LogPrintf("-bootstrap: Zip extraction successful.");

return true;

Expand All @@ -206,12 +205,12 @@ bool Bootstrap::ensureOutputFolder(const std::string& outputPath) {
fs::create_directories(outputPath);
} else if (!fs::is_directory(outputPath)) {
// If it exists but is not a directory, print an error
std::cerr << "Error: Output path '" << outputPath << "' is not a directory." << std::endl;
LogPrintf("-bootstrap: Error: Output path %s is not a directory.", outputPath);
return false;
}
} catch (const std::exception& e) {
// Handle any exceptions that may occur during filesystem operations
std::cerr << "Error creating output folder: " << e.what() << std::endl;
LogPrintf("-bootstrap: Error creating output folder: %s \n",e.what());
return false;
}

Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
#include <boost/filesystem/fstream.hpp>

#include "minizip/unzip.h"
#ifdef BOOTSTRAPTEST
#include "logging.h"
#else
#include "../logging.h"
#endif

#ifndef TICKER
#define TICKER "UCR"
Expand Down
34 changes: 34 additions & 0 deletions src/bootstrap/logging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef BITCOIN_LOGGING_H
#define BITCOIN_LOGGING_H

#include "tinyformat.h"
#include <cerrno> // For perror
#include <cstring> // For strerror
#include <iostream>
#include <string>

/** Get format string from VA_ARGS for error reporting */
template<typename... Args> std::string FormatStringFromLogArgs(const char *fmt, const Args&... args) { return fmt; }

#define LogPrintf(...) do { \
if(true) { \
std::string _log_msg_; /* Unlikely name to avoid shadowing variables */ \
try { \
_log_msg_ = tfm::format(__VA_ARGS__); \
} catch (tinyformat::format_error &e) { \
/* Original format string will have newline so don't add one here */ \
_log_msg_ = "Error \"" + std::string(e.what()) + \
"\" while formatting log message: " + \
FormatStringFromLogArgs(__VA_ARGS__); \
} \
std::cout << _log_msg_; \
} \
} while(0)

#define LogPrint(category, ...) do { \
if (LogAcceptCategory((category))) { \
LogPrintf(__VA_ARGS__); \
} \
} while(0)

#endif
14 changes: 7 additions & 7 deletions src/bootstrap/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,36 @@ curl_test:

#linux_x86=true make test
test:
$(CXX) \
$(CXX) -DBOOTSTRAPTEST \
-I$(work_dir)/../../depends/$(arch)/include \
-L$(work_dir)/../../depends/$(arch)/lib \
-L$(work_dir)/../../depends/$(arch)/lib64 \
-o test test.cpp bootstrap.h bootstrap.cpp minizip/unzip.h minizip/unzip.c minizip/ioapi.h minizip/ioapi.c \
-lcurl -pthread -lz -lssl -lcrypto -lboost_system-mt-x64 -lboost_filesystem-mt-x64

docker_macos_test:
/DSW/depends/x86_64-apple-darwin14/native/bin/clang++ \
/DSW/depends/x86_64-apple-darwin14/native/bin/clang++ -DBOOTSTRAPTEST \
-target x86_64-apple-darwin14 -mmacosx-version-min=10.10 --sysroot /DSW/depends/SDKs/MacOSX10.11.sdk -mlinker-version=253.9 -stdlib=libc++ \
-I/DSW/depends/x86_64-apple-darwin14/include \
-L/DSW/depends/x86_64-apple-darwin14/lib \
-L/DSW/depends/x86_64-apple-darwin14/lib64 \
test.cpp bootstrap.h bootstrap.cpp minizip/unzip.h minizip/unzip.c minizip/ioapi.h minizip/ioapi.c \
test.cpp logging.h tinyformat.h bootstrap.h bootstrap.cpp minizip/unzip.h minizip/unzip.c minizip/ioapi.h minizip/ioapi.c \
-lcurl -DCURL_STATICLIB `/DSW/depends/x86_64-apple-darwin14/bin/curl-config --cflags --static-libs` -pthread -lz -lssl -lcrypto -lboost_system-mt-x64 -lboost_filesystem-mt-x64

docker_linux_test:
$(CXX) \
$(CXX) -DBOOTSTRAPTEST \
-I/DSW/depends/x86_64-pc-linux-gnu/include \
-L/DSW/depends/x86_64-pc-linux-gnu/lib \
-L/DSW/depends/x86_64-pc-linux-gnu/lib64 \
-o test test.cpp bootstrap.h bootstrap.cpp minizip/unzip.h minizip/unzip.c minizip/ioapi.h minizip/ioapi.c \
-o test test.cpp logging.h tinyformat.h bootstrap.h bootstrap.cpp minizip/unzip.h minizip/unzip.c minizip/ioapi.h minizip/ioapi.c \
-lcurl -pthread -lz -lssl -lcrypto -ldl -lboost_system-mt-x64 -lboost_filesystem-mt-x64

docker_windows_test:
/usr/bin/x86_64-w64-mingw32-g++ -static \
/usr/bin/x86_64-w64-mingw32-g++ -DBOOTSTRAPTEST -static \
-I/DSW/depends/x86_64-w64-mingw32/include \
-L/DSW/depends/x86_64-w64-mingw32/lib \
-L/DSW/depends/x86_64-w64-mingw32/lib64 \
-o test.exe test.cpp bootstrap.h bootstrap.cpp minizip/unzip.h minizip/unzip.c minizip/ioapi.h minizip/ioapi.c \
-o test.exe test.cpp logging.h tinyformat.h bootstrap.h bootstrap.cpp minizip/unzip.h minizip/unzip.c minizip/ioapi.h minizip/ioapi.c \
-lcurl -DCURL_STATICLIB `/DSW/depends/x86_64-w64-mingw32/bin/curl-config --cflags --static-libs` -pthread -lz -lssl -lcrypto -lboost_system-mt-s-x64 -lboost_filesystem-mt-s-x64

clean:
Expand Down
9 changes: 8 additions & 1 deletion src/bootstrap/test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define COIN "777"

#include "bootstrap.h"
namespace fs = boost::filesystem;

// Define the progress callback function
static int downloadProgressCallback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) {
Expand All @@ -13,7 +14,7 @@ static int downloadProgressCallback(void *clientp, double dltotal, double dlnow,
static bool log_flag = false; // Declare log_flag as static
if (!log_flag && duration.count() % 2 == 0) {
log_flag = true;
std::printf("-Bootstrap: Download: %d%%\n", (uint8_t)progress);
std::printf("-bootstrap: Download: %d%%\n", (uint8_t)progress);
// LogPrintf("-Bootstrap: Download: %d%%\n", (uint8_t)progress);
// uiInterface.ShowProgress(_("Download: "), (uint8_t)progress);
} else if (duration.count() % 2 != 0) {
Expand Down Expand Up @@ -75,9 +76,15 @@ int main() {
} else {
std::cerr << "Error extracting zip file." << std::endl;
}

if(Bootstrap::isDirectory(extractPath))
Bootstrap::rmDirectory(extractPath);

} else {
std::cerr << "Error downloading file." << std::endl;
}

fs::remove(outputFileName);

return 0;
}
Loading

0 comments on commit dd8253e

Please sign in to comment.