remove tor.cpp and copy escrow.cpp to src/core

pull/201/head
larteyoh 9 months ago
parent 337ed34813
commit 6b2a82bd32

@ -414,7 +414,6 @@ set(neroshop_database_src
set(neroshop_network_src
${NEROSHOP_CORE_SRC_DIR}/network/i2p.cpp
${NEROSHOP_CORE_SRC_DIR}/network/tor.cpp
)
set(neroshop_price_src
@ -458,6 +457,7 @@ set(neroshop_tools_src
set(neroshop_core_src
${NEROSHOP_CORE_SRC_DIR}/cart.cpp
${NEROSHOP_CORE_SRC_DIR}/escrow.cpp
${NEROSHOP_CORE_SRC_DIR}/listing.cpp
${NEROSHOP_CORE_SRC_DIR}/order.cpp
${NEROSHOP_CORE_SRC_DIR}/product.cpp

@ -85,7 +85,9 @@ https://user-images.githubusercontent.com/58671384/219222567-f170f728-be31-43d5-
## Building neroshop
### Dependencies
:heavy_check_mark: = Currently in use; :o: = Optional; :x: = Not currently in use or deprecated; :grey_question: = Not yet in use, but up for consideration; :white_square_button: = Exclusive to CLI; :package: = Bundled
:heavy_check_mark: = Currently in use; :o: = Optional; :x: = Marked for deprecation or removed; :grey_question: = Not in use, but may be considered
:white_square_button: = Exclusive to CLI; :package: = Bundled
| Library | Minimum Ver. | Purpose | Status |
|--------------------------------------------------------------------|--------------------|------------------------------------------------------------------------|----------------------------------------------------|

@ -48,27 +48,5 @@ enum class PriceSource {
Kraken,
};
// username and password verification
enum class PasswordResult {
Password_Ok = 0,
Password_NoUpperCaseLetter,
Password_NoLowerCaseLetter,
Password_NoDigit,
Password_NoSpecialCharacter,
Password_LengthTooShort, // or WrongLength
};
enum class UsernameResult {
Username_Ok = 0,
Username_LengthTooShort, // MinimumLengthReached
Username_LengthTooLong, // MaximumLengthReached
Username_NoSpacesAllowed,
Username_NoSymbolsAllowedWithExceptions,
Username_MustBeginWithLetter,
Username_MustEndWithAlphaNumericCharacter,
Username_TakenOrUnavailable,
Username_ReservedForInternalUse,
};
} // namespace neroshop
#endif

@ -0,0 +1,77 @@
#include "escrow.hpp"
void neroshop::Escrow::test_multisig_participants(const std::vector<neroshop::Wallet *>& participants, int M, int N, bool test_tx) {
std::cout << "test_multisig_participants(" + std::to_string(M) + ", " + std::to_string(N) + ")\n";
assert((N == participants.size()) && std::string("Number of participants must be equal to N (" + std::to_string(N) + ")").c_str());
}
void neroshop::Escrow::test_create_multisig_wallet(int M, int N) {
std::cout << "Creating " + std::to_string(M) + "/" + std::to_string(N) + " multisig wallet\n";
// create participating wallets
std::vector<neroshop::Wallet *> wallets = {};
for(int i = 0; i < N; i++) {
neroshop::Wallet *wallet = new neroshop::Wallet();
wallet->create_random("", "", std::string("multisig_wallet_" + std::to_string(i)));
wallets.push_back(wallet);
}
// prepare and collect multisig hex from each participant
std::vector<std::string> prepared_multisig_hexes = {};
for(auto wallet : wallets) {
prepared_multisig_hexes.push_back(wallet->get_monero_wallet()->prepare_multisig());
}
// make each wallet multisig and collect results
std::vector<std::string> made_multisig_hexes = {};
for(int i = 0; i < wallets.size(); i++) {
// collect prepared multisig hexes from wallet's peers
std::vector<std::string> peer_multisig_hexes = {};
for(int j = 0; j < wallets.size(); j++)
if(j != i) peer_multisig_hexes.push_back(prepared_multisig_hexes[j]);
// make wallet multisig and collect result hex
std::string multisig_hex = wallets[i]->get_monero_wallet()->make_multisig(peer_multisig_hexes, M, ""/*password*/);
made_multisig_hexes.push_back(multisig_hex);
}
// exchange multisig keys N - M + 1 times - error is found here!
std::vector<std::string> multisig_hexes = made_multisig_hexes;
for (int i = 0; i < N - M + 1; i++) {
// exchange multisig keys among participants and collect results for next round if applicable
std::vector<std::string> result_multisig_hexes = {};
for(auto wallet : wallets) {
// import the multisig hex of other participants and collect results
monero_multisig_init_result result = wallet->get_monero_wallet()->exchange_multisig_keys(multisig_hexes, ""/*password*/);
result_multisig_hexes.push_back(result.m_multisig_hex.get());
}
// use resulting multisig hex for next round of exchange if applicable
multisig_hexes = result_multisig_hexes;
}
// wallets are now multisig
for(auto wallet : wallets) {
std::string primary_address = wallet->get_monero_wallet()->get_address(0, 0);
if(!monero_utils::is_valid_address(primary_address, wallet->get_network_type())) {
throw std::runtime_error("wallet address is not valid!");
}
std::cout << "multisig address: " << primary_address << std::endl;
monero_multisig_info info = wallet->get_monero_wallet()->get_multisig_info();
assert(info.m_is_multisig == true);
assert(info.m_is_ready == true);
assert(M == static_cast<int>(info.m_threshold));
assert(N == static_cast<int>(info.m_num_participants));
wallet->get_monero_wallet()->close(true);
}
}
/*int main() {
//neroshop::Escrow::test_create_multisig_wallet(2, 3); // can be disputed if both buyer and seller do not come to an agreement (for a fee of 0.5% of order total)
neroshop::Escrow::test_create_multisig_wallet(2, 2); // funds are gone forever if both buyer and seller do not come to an agreement
return 0;
}*/

@ -0,0 +1,33 @@
#pragma once
#ifndef ESCROW_HPP_NEROSHOP
#define ESCROW_HPP_NEROSHOP
#include <iostream>
// uncomment to disable assert()
// #define NDEBUG
#include <cassert>
#include "wallet.hpp"
namespace neroshop {
struct Escrow {
static void test_multisig_participants(const std::vector<neroshop::Wallet *>& participants, int M, int N, bool test_tx);
static void test_create_multisig_wallet(int M, int N);
// Multi-sig functions to use:
//std::string monero::monero_wallet_full::export_multisig_hex ( )
//monero_multisig_init_result monero::monero_wallet_full::exchange_multisig_keys ( const std::vector< std::string > & mutisig_hexes,const std::string & password )
//std::vector< std::string > monero::monero_wallet_full::submit_multisig_tx_hex ( const std::string & signed_multisig_tx_hex )
//monero_multisig_info monero::monero_wallet_full::get_multisig_info ( ) const
//int monero::monero_wallet_full::import_multisig_hex ( const std::vector< std::string > & multisig_hexes )
//bool monero::monero_wallet_full::is_multisig_import_needed ( ) const
//std::string monero::monero_wallet_full::make_multisig ( const std::vector< std::string > & multisig_hexes,int threshold,const std::string & password )
//std::string monero::monero_wallet_full::prepare_multisig ( )
//monero_multisig_sign_result monero::monero_wallet_full::sign_multisig_tx_hex ( const std::string & multisig_tx_hex )
//monero_tx_set monero::monero_wallet_full::describe_tx_set ( const monero_tx_set & tx_set )
};
}
#endif

@ -1,3 +0,0 @@
#include "tor.hpp"

@ -1,3 +0,0 @@
#pragma once

@ -229,14 +229,14 @@ void neroshop::Node::join() {
}
// Then add nodes to the routing table
for (auto node : nodes) {
for (auto& node : nodes) {
// Ping the received nodes first
std::string node_ip = (node->get_ip_address() == this->public_ip_address) ? "127.0.0.1" : node->get_ip_address();
if(!ping(node_ip, node->get_port())) {
continue; // Skip the node and continue with the next iteration
}
// Process the response and update the routing table if necessary
routing_table->add_node(std::unique_ptr<neroshop::Node>(node));
routing_table->add_node(std::move(node));
}
}
@ -386,11 +386,11 @@ void neroshop::Node::add_provider(const std::string& data_hash, const Peer& peer
}
// If the data_hash is already in the map, add the peer to the vector of peers
it->second.push_back(peer);
std::cout << "Provider (\033[36m" << peer.address + ":" + std::to_string(peer.port) << "\033[0m) for hash (" << data_hash << ") has been added" << std::endl;
//std::cout << "Provider (\033[36m" << peer.address + ":" + std::to_string(peer.port) << "\033[0m) for hash (" << data_hash << ") has been added" << std::endl;
} else {
// If the data_hash is not in the map, create a new vector of peers and add the peer
providers.emplace(data_hash, std::vector<Peer>{peer});
std::cout << "Provider (\033[36m" << peer.address + ":" + std::to_string(peer.port) << "\033[0m) for hash (" << data_hash << ") has been added (0)" << std::endl;
//std::cout << "Provider (\033[36m" << peer.address + ":" + std::to_string(peer.port) << "\033[0m) for hash (" << data_hash << ") has been added (0)" << std::endl;
}
}
@ -621,7 +621,7 @@ bool neroshop::Node::send_ping(const std::string& address, int port) {
return true;
}
std::vector<neroshop::Node*> neroshop::Node::send_find_node(const std::string& target_id, const std::string& address, uint16_t port) {
std::vector<std::unique_ptr<neroshop::Node>> neroshop::Node::send_find_node(const std::string& target_id, const std::string& address, uint16_t port) {
std::string transaction_id = msgpack::generate_transaction_id();
nlohmann::json query_object;
@ -645,15 +645,15 @@ std::vector<neroshop::Node*> neroshop::Node::send_find_node(const std::string& t
}
std::cout << "\033[32m" << nodes_message.dump() << "\033[0m\n";
// Create node vector and store nodes from the message inside the vector
std::vector<Node*> nodes;
std::vector<std::unique_ptr<Node>> nodes;
if (nodes_message.contains("response") && nodes_message["response"].contains("nodes")) {
for (auto& node_json : nodes_message["response"]["nodes"]) {
if (node_json.contains("ip_address") && node_json.contains("port")) {
std::string ip_address = node_json["ip_address"];
uint16_t port = node_json["port"];
Node* node = new Node(ip_address, port, false);
auto node = std::make_unique<Node>(ip_address, port, false);
if (node->id != this->id && !routing_table->has_node(node->id)) { // add node to vector only if it's not the current node
nodes.push_back(node);
nodes.push_back(std::move(node));
}
}
}
@ -793,6 +793,8 @@ std::string neroshop::Node::send_get(const std::string& key) {
//-----------------------------------------------
// Send get message to the closest nodes
for(auto const& node : closest_nodes) {
if (node->get_status() != NodeStatus::Active) { continue; } // ignore inactive nodes
std::string transaction_id = msgpack::generate_transaction_id();
query_object["tid"] = transaction_id; // tid should be unique for each get message
std::vector<uint8_t> get_message = nlohmann::json::to_msgpack(query_object);

@ -68,7 +68,7 @@ public:
std::vector<uint8_t> send_query(const std::string& address, uint16_t port, const std::vector<uint8_t>& message, int recv_timeout = 5);
//---------------------------------------------------
bool send_ping(const std::string& address, int port);
std::vector<Node*> send_find_node(const std::string& target_id, const std::string& address, uint16_t port);
std::vector<std::unique_ptr<Node>> send_find_node(const std::string& target_id, const std::string& address, uint16_t port);
int send_put(const std::string& key, const std::string& value);
int send_store(const std::string& key, const std::string& value);
std::string send_get(const std::string& key);

@ -50,6 +50,26 @@ public:
UserIsNullPointer,
};
Q_ENUM(LoginError)
enum class RegistrationError {
Ok = 0,
Password_NoUpperCaseLetter,
Password_NoLowerCaseLetter,
Password_NoDigit,
Password_NoSpecialCharacter,
Password_LengthTooShort, // or WrongLength
Username_LengthTooShort, // MinimumLengthReached
Username_LengthTooLong, // MaximumLengthReached
Username_NoSpacesAllowed,
Username_NoSymbolsAllowedWithExceptions,
Username_MustBeginWithLetter,
Username_MustEndWithAlphaNumericCharacter,
Username_TakenOrUnavailable,
Username_ReservedForInternalUse,
};
Q_ENUM(RegistrationError)
enum class Sorting {
// Listing sorting
@ -82,5 +102,6 @@ public:
Q_DECLARE_METATYPE(neroshop::EnumWrapper::WalletError)
Q_DECLARE_METATYPE(neroshop::EnumWrapper::CartError)
Q_DECLARE_METATYPE(neroshop::EnumWrapper::LoginError)
Q_DECLARE_METATYPE(neroshop::EnumWrapper::RegistrationError)
Q_DECLARE_METATYPE(neroshop::EnumWrapper::Sorting)
#endif

@ -537,6 +537,26 @@ QVariantList neroshop::UserController::getMessages() const {
}
}
std::sort(messages_array.begin(), messages_array.end(), [](const QVariant& a, const QVariant& b) {
QVariantMap mapA = a.toMap();
QVariantMap mapB = b.toMap();
QString timestampA = mapA.value("timestamp").toString();
QString timestampB = mapB.value("timestamp").toString();
// Convert 'Z' to UTC+0 offset
if (timestampA.endsWith("Z")) {
timestampA.replace(timestampA.length() - 1, 1, "+00:00");
}
if (timestampB.endsWith("Z")) {
timestampB.replace(timestampB.length() - 1, 1, "+00:00");
}
QDateTime dateTimeA = QDateTime::fromString(timestampA, Qt::ISODateWithMs);
QDateTime dateTimeB = QDateTime::fromString(timestampB, Qt::ISODateWithMs);
return dateTimeA > dateTimeB;
});
sqlite3_finalize(stmt);
return messages_array;

@ -1,7 +1,5 @@
#include "wallet_controller.hpp"
#include "../core/enums.hpp"
neroshop::WalletController::WalletController(QObject *parent) : QObject(parent)
{
_wallet = std::make_unique<neroshop::Wallet>();

@ -10,6 +10,7 @@
#include "core/cart.hpp"
#include "core/category.hpp"
#include "core/enums.hpp"
#include "core/escrow.hpp"
#include "core/listing.hpp"
#include "core/order.hpp"
#include "core/product.hpp"
@ -28,7 +29,6 @@
#include "core/database/sqlite.hpp"
// network
#include "core/network/i2p.hpp"
#include "core/network/tor.hpp"
// price
#include "core/price/currency_converter.hpp"
// protocol

Loading…
Cancel
Save