internal TransferSupplyCommandHandler(ISkuRepository skuRepository, ITransactionRepository transactionRepo, ITransactionCreator transactionCreator, string netId) { _skuRepository = skuRepository; _transactionRepo = transactionRepo; _transactionCreator = transactionCreator; _netId = netId; }
internal TransactionGeneratorCommandHandler(Miner miner, ITransactionCreator txCreator, ISkuRepository skuRepo, IBlockchainRepository blockchainRepo) { _miner = miner; _txCreator = txCreator; _skuRepo = skuRepo; _blockchainRepo = blockchainRepo; }
public SaleProcessor(IMerchantConfigurationAcquirerFinder merchantConfigurationAcquirerFinder, IAcquirerServiceFactory acquirerServiceFactory, ITransactionCreator transactionService) { MerchantConfigurationAcquirerFinder = merchantConfigurationAcquirerFinder ?? throw new ArgumentNullException(nameof(merchantConfigurationAcquirerFinder)); AcquirerServiceFactory = acquirerServiceFactory ?? throw new ArgumentNullException(nameof(acquirerServiceFactory)); TransactionCreator = transactionService ?? throw new ArgumentNullException(nameof(transactionService)); }
public AntifraudProcessor(ISaleProcessor saleProcessor, IClearSaleService clearSaleService, ITransactionCreator transactionCreator, ApplicationDbContext dbContext) { SaleProcessor = saleProcessor ?? throw new ArgumentNullException(nameof(saleProcessor)); ClearSaleService = clearSaleService ?? throw new ArgumentNullException(nameof(clearSaleService)); TransactionCreator = transactionCreator ?? throw new ArgumentNullException(nameof(transactionCreator)); DbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); }
private static void GetServices(IServiceProvider services, out IBlockchainRepository blockchainRepo, out ITransactionRepository transactionRepo, out ITransactionCreator transactionCreator, out ITimestamper timestamper, out ISkuRepository skuRepository, out INetworkManager networkManager, out ILoggerFactory loggerFactory, out ISkuRepository skuRepo, out Miner miner) { blockchainRepo = services.GetService <IBlockchainRepository>(); transactionRepo = services.GetService <ITransactionRepository>(); transactionCreator = services.GetService <ITransactionCreator>(); timestamper = services.GetService <ITimestamper>(); skuRepository = services.GetService <ISkuRepository>(); networkManager = services.GetService <INetworkManager>(); loggerFactory = services.GetService <ILoggerFactory>(); skuRepo = services.GetService <ISkuRepository>(); miner = services.GetService <Miner>(); }
public Miner(string netId, string minerWalletPubKey, string minerWalletPrivKey, IBlockchainRepository blockchainRepo, ITransactionRepository transactionRepo, ITransactionCreator transactionCreator, ITransactionValidator transactionValidator, IDifficultyCalculator difficultyCalculator, IPowBlockCreator blockCreator, IBlockValidator blockValidator, ConcurrentTransactionPool txPool, ILoggerFactory loggerFactory) { _logger = loggerFactory.CreateLogger <Miner>(); _walletPubKey = minerWalletPubKey; _walletPrivKey = minerWalletPrivKey; _blockchainRepo = blockchainRepo; _networkIdentifier = netId; _blockchain = _blockchainRepo.GetChainByNetId(_networkIdentifier); _transactionRepo = transactionRepo; _transactionCreator = transactionCreator; _transactionValidator = transactionValidator; _difficultyCalculator = difficultyCalculator; _blockCreator = blockCreator; _blockValidator = blockValidator; _txPool = txPool; EventPublisher.GetInstance().OnUnvalidatedTransactionReceived += OnUnvalidatedTransactionReceived; EventPublisher.GetInstance().OnUnvalidatedBlockCreated += OnUnvalidatedBlockCreated; difficulty = _difficultyCalculator.CalculateCurrentDifficulty(_blockchain); }
internal TransferTokensCommandHandler(ITransactionRepository transactionRepo, ITransactionCreator transactionCreator) { _transactionRepo = transactionRepo; _transactionCreator = transactionCreator; }
public Miner(IBlockchain blockChain, ITransactionCreator transactionCreator) { this.blockChain = blockChain; this.transactionCreator = transactionCreator; }
internal CreateSkuCommandHandler(ITransactionRepository transactionRepo, ITransactionCreator transactionCreator) { _transactionRepo = transactionRepo; _transactionCreator = transactionCreator; }
public static void Main(string[] args) { CryptographyCommandhandler cryptographyCmdHandler = new CryptographyCommandhandler(new KeyGenerator()); cryptographyCmdHandler.HandleGenerateKeysCommand(out string walletPubKey, out string walletPrivKey); PushKeyPair(walletPubKey, walletPrivKey); Console.WriteLine("Your new public key: " + walletPubKey); Console.WriteLine("Your new private key: " + walletPrivKey); Console.WriteLine("Loading blockchain.."); var networkIdentifier = "testnet"; var services = SetupDI(networkIdentifier, walletPubKey, walletPrivKey); ushort listeningPort = NetworkConstants.DefaultListeningPort; IPAddress publicIP = IPAddress.Parse("127.0.0.1"); // Our public IP so other nodes can find us, todo if (args.Length > 1 && args[0] == "-port") { listeningPort = ushort.Parse(args[1]); } IBlockchainRepository blockchainRepo = services.GetService <IBlockchainRepository>(); ITransactionRepository transactionRepo = services.GetService <ITransactionRepository>(); ITransactionCreator transactionCreator = services.GetService <ITransactionCreator>(); ITimestamper timestamper = services.GetService <ITimestamper>(); ISkuRepository skuRepository = services.GetService <ISkuRepository>(); INetworkManager networkManager = services.GetService <INetworkManager>(); ILoggerFactory loggerFactory = services.GetService <ILoggerFactory>(); ISkuRepository skuRepo = services.GetService <ISkuRepository>(); Miner miner = services.GetService <Miner>(); _logger = loggerFactory.CreateLogger <Program>(); Blockchain blockchain = blockchainRepo.GetChainByNetId(networkIdentifier); // Command handlers, only large commands are handles by these separate handlers. AccountsCommandHandler accountsCmdHandler = new AccountsCommandHandler(transactionRepo, networkIdentifier); SkusCommandHandler skusCmdHandler = new SkusCommandHandler(blockchainRepo, timestamper, skuRepository, networkIdentifier); TransactionsCommandHandler transactionsCmdHandler = new TransactionsCommandHandler(transactionRepo, networkIdentifier); TransactionPoolCommandHandler txpoolCmdHandler = new TransactionPoolCommandHandler(); TransferTokensCommandHandler transferTokensCmdHandler = new TransferTokensCommandHandler(transactionRepo, transactionCreator); CreateSkuCommandHandler createSkuCmdHandler = new CreateSkuCommandHandler(transactionRepo, transactionCreator); TransferSupplyCommandHandler transferSupplyCmdHandler = new TransferSupplyCommandHandler(skuRepository, transactionRepo, transactionCreator, networkIdentifier); NetworkingCommandHandler networkingCmdHandler = new NetworkingCommandHandler(); TransactionGeneratorCommandHandler txGeneratorCmdHandler = new TransactionGeneratorCommandHandler(miner, transactionCreator, skuRepo, blockchainRepo); CreateSupplyCommandHandler createSupplyCmdHandler = new CreateSupplyCommandHandler(skuRepository, transactionRepo, transactionCreator, networkIdentifier); DestroySupplyCommandHandler destroySupplyCmdHandler = new DestroySupplyCommandHandler(skuRepository, transactionRepo, transactionCreator, networkIdentifier); _logger.LogInformation("Loaded blockchain. Current height: {Height}", blockchain.CurrentHeight == -1 ? "GENESIS" : blockchain.CurrentHeight.ToString()); networkManager.AcceptConnections(publicIP, listeningPort, new CancellationTokenSource()); networkManager.ConnectToPeer(new NetworkNode(ConnectionType.Outbound, new IPEndPoint(IPAddress.Parse("127.0.0.1"), 12345))); PrintConsoleCommands(); var skuTransactions = 0; var txpool = ConcurrentTransactionPool.GetInstance(); EventPublisher.GetInstance().OnValidTransactionReceived += (object sender, TransactionReceivedEventArgs txargs) => { if (txargs.Transaction.Action == TransactionAction.CreateSku.ToString()) { skuTransactions++; } if (skuTransactions > 200000 && txpool.Count() < 1) { miner.StopMining(true); txGeneratorCmdHandler.HandleStopCommand(); } }; var input = ""; while (input != "exit") { input = Console.ReadLine().ToLower(); switch (input) { case "help": PrintConsoleCommands(); break; case "transactiongenerator startandmine": txGeneratorCmdHandler.HandleStartCommand(true); break; case "transactiongenerator start": txGeneratorCmdHandler.HandleStartCommand(false); break; case "transactiongenerator stop": txGeneratorCmdHandler.HandleStopCommand(); break; case "generatekeys": cryptographyCmdHandler.HandleGenerateKeysCommand(out walletPubKey, out walletPrivKey); PushKeyPair(walletPubKey, walletPrivKey); Console.WriteLine("Your new public key: " + walletPubKey); Console.WriteLine("Your new private key: " + walletPrivKey); Console.Write("> "); break; case "accounts": case "users": case "balances": accountsCmdHandler.HandleCommand(); break; case "skus": skusCmdHandler.HandleCommand(); break; case "txpool": case "transactionpool": case "pendingtransactions": txpoolCmdHandler.HandleCommand(miner.TransactionPool); break; case "transactions": transactionsCmdHandler.HandleCommand(); break; case "startmining": miner.StartMining(); Console.Write("> "); break; case "stopmining": miner.StopMining(true); PrintConsoleCommands(); break; case "resetblockchain": networkManager.Dispose(); _logger.LogWarning("All network connections shut down."); miner.StopMining(false); blockchainRepo.Delete(networkIdentifier); _logger.LogInformation("Local blockchain file deleted as requested by user"); Console.WriteLine("Please restart the logistichain executable now to reload a fresh blockchain instance!"); break; case "transfertokens": transferTokensCmdHandler.HandleCommand(networkIdentifier); break; case "createsku": createSkuCmdHandler.HandleCommand(networkIdentifier); break; case "transfersupply": transferSupplyCmdHandler.HandleCommand(); break; case "createsupply": createSupplyCmdHandler.HandleCommand(); break; case "destroysupply": destroySupplyCmdHandler.HandleCommand(); break; case "networking setport": listeningPort = networkingCmdHandler.HandleSetPortCommand(listeningPort); break; case "networking setaddress": publicIP = networkingCmdHandler.HandleSetAddressCommand(publicIP); break; case "networking connect": networkingCmdHandler.HandleConnectCommand(networkManager); break; case "networking disconnect": networkingCmdHandler.HandleDisconnectCommand(networkManager); break; case "networking pool": networkingCmdHandler.HandleListPoolCommand(NetworkNodesPool.GetInstance(loggerFactory)); break; case "networking stop": networkManager.Dispose(); break; case "networking start": if (networkManager.IsDisposed) { networkManager = GetService <INetworkManager>(services); } networkManager.AcceptConnections(publicIP, listeningPort, new CancellationTokenSource()); break; case "networking restart": networkManager.Dispose(); Thread.Sleep(1000); networkManager = GetService <INetworkManager>(services); networkManager.AcceptConnections(publicIP, listeningPort, new CancellationTokenSource()); break; default: Console.WriteLine("I don't recognize that command."); Console.Write("> "); break; } } }