Skip to content

Commit

Permalink
Merge pull request #35 from GeniusVentures/dev_crdt_blockchain
Browse files Browse the repository at this point in the history
CRDT into blockchain and transactions
  • Loading branch information
itsafuu authored Apr 17, 2024
2 parents 34d574a + 8095b9c commit bfefb7f
Show file tree
Hide file tree
Showing 50 changed files with 1,281 additions and 673 deletions.
2 changes: 1 addition & 1 deletion build/CommonBuildParameters.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ link_directories(
)

add_subdirectory(${PROJECT_ROOT}/src ${CMAKE_BINARY_DIR}/src)
add_subdirectory(${PROJECT_ROOT}/app ${CMAKE_BINARY_DIR}/app)
#add_subdirectory(${PROJECT_ROOT}/app ${CMAKE_BINARY_DIR}/app)


if (TESTING)
Expand Down
37 changes: 23 additions & 14 deletions example/account_handling/AccountHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
#include <boost/program_options.hpp>
#include <boost/format.hpp>
#include <boost/asio.hpp>
#include "TransactionManager.hpp"
#include "account/TransferTransaction.hpp"
#include "account/TransactionManager.hpp"
#include "blockchain/impl/common.hpp"
#include "blockchain/impl/key_value_block_header_repository.hpp"
#include "blockchain/impl/key_value_block_storage.hpp"
#include "crypto/hasher/hasher_impl.hpp"

#include <ipfs_lite/ipfs/graphsync/graphsync.hpp>
#include "account/AccountManager.hpp"
Expand Down Expand Up @@ -78,8 +81,7 @@ void CreateTransferTransaction( const std::vector<std::string> &args, sgns::Tran
}
else
{
auto transfer_transaction = std::make_shared<sgns::TransferTransaction>( uint256_t{ args[1] }, uint256_t{ args[2] } );
transaction_manager.EnqueueTransaction( transfer_transaction );
transaction_manager.TransferFunds(uint256_t{ args[1] }, uint256_t{ args[2] });
}
}
void CreateProcessingTransaction( const std::vector<std::string> &args, sgns::TransactionManager &transaction_manager )
Expand All @@ -91,8 +93,7 @@ void CreateProcessingTransaction( const std::vector<std::string> &args, sgns::Tr
}

//TODO - Create processing transaction
//auto transfer_transaction = std::make_shared<sgns::TransferTransaction>( uint256_t{ args[1] }, uint256_t{ args[2] } );
//transaction_manager.EnqueueTransaction( transfer_transaction );

}
void MintTokens( const std::vector<std::string> &args, sgns::TransactionManager &transaction_manager )
{
Expand All @@ -101,9 +102,7 @@ void MintTokens( const std::vector<std::string> &args, sgns::TransactionManager
std::cerr << "Invalid process command format.\n";
return;
}

auto mint_transaction = std::make_shared<sgns::MintTransaction>( std::stoull( args[1] ) );
transaction_manager.EnqueueTransaction( mint_transaction );
transaction_manager.MintFunds(std::stoull( args[1] ));
}
void PrintAccountInfo( const std::vector<std::string> &args, sgns::TransactionManager &transaction_manager )
{
Expand All @@ -115,8 +114,6 @@ void PrintAccountInfo( const std::vector<std::string> &args, sgns::TransactionMa
transaction_manager.PrintAccountInfo();

//TODO - Create processing transaction
//auto transfer_transaction = std::make_shared<sgns::TransferTransaction>( uint256_t{ args[1] }, uint256_t{ args[2] } );
//transaction_manager.EnqueueTransaction( transfer_transaction );
}

std::vector<std::string> split_string( const std::string &str )
Expand Down Expand Up @@ -192,7 +189,7 @@ int main( int argc, char *argv[] )
std::string own_wallet_address( argv[2] );
std::string pubs_address( argv[3] );

auto maybe_account = sgns::AccountManager{}.CreateAccount( own_wallet_address, 0 );
auto maybe_account = sgns::AccountManager{}.CreateAccount( own_wallet_address, 100 );

const std::string processingGridChannel = "GRID_CHANNEL_ID";

Expand Down Expand Up @@ -223,7 +220,19 @@ int main( int argc, char *argv[] )
auto crdtOptions = sgns::crdt::CrdtOptions::DefaultOptions();
globalDB->Init( crdtOptions );

sgns::TransactionManager transaction_manager( globalDB, io, account );
sgns::base::Buffer root_hash;
root_hash.put(std::vector<uint8_t>(32ul, 1));
auto hasher_ = std::make_shared<sgns::crypto::HasherImpl>();
std::string db_path_ = "bc-963/";
auto header_repo_ = std::make_shared<sgns::blockchain::KeyValueBlockHeaderRepository>(globalDB, hasher_, db_path_);
auto maybe_block_storage = sgns::blockchain::KeyValueBlockStorage::create(root_hash,globalDB,hasher_,header_repo_,[](auto &) {});

if (!maybe_block_storage)
{
std::cout << "Error initializing blockchain" << std::endl;
return -1;
}
sgns::TransactionManager transaction_manager( globalDB, io, account,maybe_block_storage.value() );
transaction_manager.Start();

//Run ASIO
Expand All @@ -248,4 +257,4 @@ int main( int argc, char *argv[] )
}
iothread.join();
return 0;
}
}
5 changes: 4 additions & 1 deletion example/account_handling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ add_executable(account_handling
# ipfs-lite-cpp::ipld_node
# ipfs-lite-cpp::ipfs_merkledag_service
# ipfs-lite-cpp::graphsync
sgns_account
blockchain_common
block_header_repository
block_storage
logger
#processing_service
crdt_globaldb
p2p::p2p_basic_host
p2p::p2p_default_network
Expand Down
268 changes: 0 additions & 268 deletions example/account_handling/TransactionManager.hpp

This file was deleted.

3 changes: 2 additions & 1 deletion example/graphsync_app/graphsync_acceptance_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <ipfs_lite/ipfs/graphsync/impl/graphsync_impl.hpp>
#include <ipfs_lite/ipld/impl/ipld_node_impl.hpp>
#include "outcome/outcome.hpp"

void runEventLoop(const std::shared_ptr<boost::asio::io_context>& io,
size_t max_milliseconds) {
Expand Down Expand Up @@ -82,7 +83,7 @@ void TestDataService::insertNode(TestDataService::Storage& dst,
dst[node->getCID()] = node->getRawBytes();
}

sgns::outcome::result<size_t> TestDataService::select(
outcome::result<size_t> TestDataService::select(
const sgns::CID& cid,
gsl::span<const uint8_t> selector,
std::function<bool(const sgns::CID& cid, const sgns::common::Buffer& data)> handler)
Expand Down
Loading

0 comments on commit bfefb7f

Please sign in to comment.