static void Main(string[] args) { try { PublicID = "ID[" + Guid.NewGuid() + "]"; var appSettings = System.Configuration.ConfigurationManager.AppSettings; LicenseKey = appSettings["License"]; var localHost = appSettings["Host"]; var peers = new List <string>(); //get all the peers to broadcast from appsettings keys appSettings.AllKeys.ToList().Where(k => k.StartsWith("Peer")) .ToList().ForEach(delegate(string key) { peers.Add(appSettings[key]); }); //Create servers for local comms, and global comms var hexHost = new GlobalInterfaceServer(localHost, peers); //use same local host endpoint for jinx host endpoint var jinxHost = new LocalInterfaceServer( localHost.Replace("HexChainService", "JinxService"), appSettings["clientBinding"]); //create a new thread to launch the local webservice host Thread jinxHostThread = new Thread(jinxHost.Listen); jinxHostThread.Start(); //create a new hexchain and add to //hexchains concurrent list var hexchain = new BlockChain(); hexchain.difficulty = 2; HexChains.Add(hexchain); //create a new thread to launch the global webservice host Thread hexHostThread = new Thread(hexHost.Listen); hexHostThread.Start(); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine("HexChain Node has shutdown."); Console.Read(); }
static void Main(string[] args) { try { PublicID = "ID[" + Guid.NewGuid() + "]"; var appSettings = System.Configuration.ConfigurationManager.AppSettings; LicenseKey = appSettings["License"]; var localHost = appSettings["Host"]; var peers = new List <string>(); //get all the peers to broadcast from appsettings keys appSettings.AllKeys.ToList().Where(k => k.StartsWith("Peer")) .ToList().ForEach(delegate(string key) { peers.Add(appSettings[key]); }); //Create servers for local comms, and global comms var hexHost = new GlobalInterfaceServer(localHost, peers); //use same local host endpoint for jinx host endpoint var jinxHost = new LocalInterfaceServer( localHost.Replace("HexChainService", "JinxService"), appSettings["clientBinding"]); //Start the local interface web service (SOAP) jinxHost.Create(); jinxHost.Open(); //Start the global interface web service (REST) hexHost.Create(); hexHost.Open(); Console.WriteLine("Press any key to start discovery of peers..."); Console.ReadLine(); hexHost.Discovery(); //create a new hexchain and add to //hexchains concurrent list var hexchain = new BlockChain(); hexchain.difficulty = 2; HexChains.Add(hexchain); //do work handling input from jinx client //process any global values coming in while (true) { //read from the hexchain any global messages string transm; var newTrans = HexChainBuffer.TryDequeue(out transm); if (newTrans) { //send this transaction to all the other nodes //hexHost.Broadcast(transm, BroadcastMode.Send); var trans = JsonConvert.DeserializeObject <Transaction>(transm); //try to mine the block with the transaction //and add it to the blockchain HexChains.First().addBlock(trans); var block = HexChains.First().getLatestBlock(); //check if the block added was valid if (HexChains.First().IsChainValid()) { //broadcast the block so everyone can mine it var jsonBlock = JsonConvert.SerializeObject(block, Formatting.Indented); //give all the peers a valid block hexHost.Broadcast(jsonBlock, BroadcastMode.SendValidBlock); Console.WriteLine("Valid Block Added :\n\t{0}", block.hash); } else { HexChains.First().chain.RemoveAt(HexChains.First().chain.Count); Console.WriteLine("Invalid Block Rejected :\n\t{0}", block.hash); } } } hexHost.Close(); jinxHost.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine("HexChain Node has shutdown."); Console.Read(); }