void RunInternal(string[] args) { if (!LoadConfiguration(args)) return; connectionManager = new ConnectionManager(); inventoryManager = new InventoryManager(); executor = new Executor(); miner = new Mining(); connectionManager.NewConnectionEstablished += NewPeer; connectionManager.MessageReceived += HandleMessage; executor.BlockExecuted += _ => miner.Notify(); inventoryManager.ConnectionManager = connectionManager; inventoryManager.Executor = executor; executor.InventoryManager = inventoryManager; miner.ConnectionManager = connectionManager; miner.InventoryManager = inventoryManager; miner.Executor = executor; inventoryManager.Blocks.Add(genesis.Id, genesis.Original); executor.ProcessBlock(genesis); if (!storage.IsNull()) { executor.BlockExecuted += block => storage.Save(block.Id, block.Original); foreach ((var id, var data) in storage.LoadAll()) inventoryManager.TryLoadBlock(id, data); } connectionManager.Start(config.ListenOn); var t = Task.Run(async () => { foreach (var ep in config.InitialEndpoints) await connectionManager.ConnectToAsync(ep); }); if (config.Mining) { miner.RecipientAddress = ByteString.CopyFrom(myKeys.Address); miner.Start(); } var host = new WebHostBuilder() .UseKestrel() .UseUrls("http://*:8080") .Configure(app => app.Run(Handle)) .Build(); host.Run(); Console.ReadLine(); connectionManager.Dispose(); }
void RunInternal(string[] args) { if (!LoadConfiguration(args)) { return; } connectionManager = new ConnectionManager(); // ブロックチェーンの対外管理 inventoryManager = new InventoryManager(); // 自分のブロックチェーンの管理 executor = new Executor(); // ブロックの実行の実体化 miner = new Mining(); // マイニング実体化 // それぞれのインスタンス間のやりとり connectionManager.NewConnectionEstablished += NewPeer; connectionManager.MessageReceived += HandleMessage; executor.BlockExecuted += miner.Notify; inventoryManager.ConnectionManager = connectionManager; inventoryManager.Executor = executor; executor.InventoryManager = inventoryManager; miner.ConnectionManager = connectionManager; miner.InventoryManager = inventoryManager; miner.Executor = executor; inventoryManager.Blocks.Add(genesis.Id, genesis.Original); // genesisをinventryに追加 executor.ProcessBlock(genesis); connectionManager.Start(config.ListenOn); var t = Task.Run(async() => { foreach (var ep in config.InitialEndpoints) { await connectionManager.ConnectToAsync(ep); } }); if (config.Mining) { miner.RecipientAddress = ByteString.CopyFrom(myKeys.Address); miner.Start(); } Console.ReadLine(); connectionManager.Dispose(); }
void RunInternal(string[] args) { if (!LoadConfiguration(args)) { return; } connectionManager = new ConnectionManager(); // inventoryManager = new InventoryManager(); //自分自身がどんなブロックを持ってるか管理する executor = new Executor(); // miner = new Mining(); //マイニング処理用のもじゅーる connectionManager.NewConnectionEstablished += NewPeer; connectionManager.MessageReceived += HandleMessage; executor.BlockExecuted += miner.Notify; inventoryManager.ConnectionManager = connectionManager; inventoryManager.Executor = executor; executor.InventoryManager = inventoryManager; miner.ConnectionManager = connectionManager; miner.InventoryManager = inventoryManager; miner.Executor = executor; inventoryManager.Blocks.Add(genesis.Id, genesis.Original);//inventorymanagerにgenesisブロックを executor.ProcessBlock(genesis.Original, genesis.PreviousHash); connectionManager.Start(config.ListenOn); var t = Task.Run(async() => { foreach (var ep in config.InitialEndpoints) { await connectionManager.ConnectToAsync(ep); } }); if (config.Mining) { miner.RecipientAddress = ByteString.CopyFrom(myKeys.Address); miner.Start(); } Console.ReadLine(); connectionManager.Dispose(); }
void RunInternal(string[] args) { if (!LoadConfiguration(args)) { return; } connectionManager = new ConnectionManager(); inventoryManager = new InventoryManager(); executor = new Executor(); miner = new Mining(); storage = new Storage(config.StoragePath, executor); connectionManager.NewConnectionEstablished += NewPeer; connectionManager.MessageReceived += HandleMessage; executor.BlockExecuted += miner.Notify; //executor.BlockExecuted += savfile; inventoryManager.ConnectionManager = connectionManager; inventoryManager.Executor = executor; executor.InventoryManager = inventoryManager; miner.ConnectionManager = connectionManager; miner.InventoryManager = inventoryManager; miner.Executor = executor; inventoryManager.Blocks.Add(genesis.Id, genesis.Original); executor.ProcessBlock(genesis); //process saved blocks foreach (var(id, block) in storage.LoadAll()) { inventoryManager.TryLoadBlock(id, block); } //add save handler executor.BlockExecuted += storage.SaveBlock; //read all blocks connectionManager.Start(config.ListenOn); var t = Task.Run(async() => { foreach (var ep in config.InitialEndpoints) { await connectionManager.ConnectToAsync(ep); } }); if (config.Mining) { miner.RecipientAddress = hwallet.Wallets[0].Address; miner.Start(); } var web = new WebHostBuilder() .UseKestrel() .UseUrls("http://*:8881") .Configure(app => app.Run(Handle)) .Build(); web.Run(); Console.ReadLine(); connectionManager.Dispose(); }