private static void Main(string[] args) { Dictionary <string, string> param = new Dictionary <string, string>(); for (int i = 0; i < args.Length; i++) { int jj = args[i].IndexOf(':'); if (jj != -1) { param.TryAdd(args[i].Substring(0, jj).Replace("-", ""), args[i].Substring(jj + 1, args[i].Length - (jj + 1))); } else { param.TryAdd(args[i].Replace("-", ""), "true"); } } param.TryAdd("configure", ""); param.TryAdd("node", "All"); param.TryAdd("wallet", "./Data/wallet.json"); param.TryAdd("db", "./Data/LevelDB"); param.TryAdd("node", "All"); if (param.TryGetValue("index", out string index)) { param["wallet"] = param["wallet"].Replace(".json", $"{index}.json"); param["db"] = param["db"] + index; } if (param.ContainsKey("miner")) { RandomXSharp.RandomX.randomx_init(param.ContainsKey("fullmem")); Entity.Root.AddComponent <Miner>().Init(param); Update(); return; } RandomXSharp.RandomX.randomx_init(false); //RandomXSharp.RandomX.Test1(args); //return; //Wallet.Import(""); //return; //BigHelper.Test(); //return; //CalculatePower.Test(); //return; //Wallet.Test2(); //return; //Wallet.Test3(); //return; // 测试代码 //LuaVMEnv.TestRapidjson(args); //LuaVMEnv.TestLib(args); //LuaVMEnv.TestCoroutine(args); //LuaVMEnv.Test_number(args); //LevelDBStore.test_delete(args); //LevelDBStore.test_undo(args); //LevelDBStore.Export2CSV_Block(args); //LevelDBStore.test_ergodic(args); //return; //Log.Info(Environment.CurrentDirectory); if (param.TryGetValue("makeSnapshot", out string _)) { LevelDBStore.MakeSnapshot(param); return; } string walletFile = param["wallet"]; Wallet wallet = Wallet.GetWallet(walletFile); if (wallet == null) { return; } if (param.TryGetValue("makeGenesis", out string _)) { Consensus.MakeGenesis(); return; } //DisbleQuickEditMode(); Console.Clear(); Console.CursorVisible = false; #if !RELEASE Console.Title = $"SmartX 配置: {param["configure"]} {index} Address: {wallet.GetCurWallet().ToAddress()} Debug"; #else Console.Title = $"SmartX 配置: {param["configure"]} {index} Address: {wallet.GetCurWallet().ToAddress()} Release"; #endif Log.Debug($"address: {wallet.GetCurWallet().ToAddress()}"); string NodeKey = param["node"]; // 异步方法全部会回调到主线程 SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); AssemblyHelper.AddAssembly("Base", typeof(AssemblyHelper).Assembly); AssemblyHelper.AddAssembly("App", typeof(Program).Assembly); // check contract var contractHash = FileHelper.HashDirectory("Data/Contract", CryptoHelper.Sha256); if (contractHash != "da4d968db3d8a7360873221cb917c9fcb073600968c2e88a22640b90c529d0f1") { Log.Debug($"contractHash error: {contractHash}"); #if RELEASE return; #endif } // 读取配置文件 try { StreamReader sr = new StreamReader(new FileStream(param["configure"], FileMode.Open, FileAccess.Read, FileShare.ReadWrite), System.Text.Encoding.UTF8); string strTxt = sr.ReadToEnd(); strTxt = strTxt.Replace("0.0.0.0", NodeManager.GetIpV4()); sr.Close(); sr.Dispose(); JToken jd = JToken.Parse(strTxt); jdNode = jd[NodeKey]; } catch (Exception e) { Log.Info(e.ToString()); Log.Error($"configure file: {param["configure"]} on exists ro json foramt error."); Console.ReadKey(); return; } if (jdNode != null) { Log.Debug("启动: " + jdNode["appType"]); // DNS List <string> list = JsonHelper.FromJson <List <string> >(jdNode["NodeSessions"].ToString()); for (int ii = 0; ii < list.Count; ii++) { list[ii] = NetworkHelper.DnsToIPEndPoint(list[ii]); } jdNode["NodeSessions"] = JsonHelper.ToJson(list); if (!string.IsNullOrEmpty(index)) { if (jdNode["HttpRpc"] != null) { jdNode["HttpRpc"]["ComponentNetworkHttp"]["address"] = ((string)jdNode["HttpRpc"]["ComponentNetworkHttp"]["address"]).Replace("8101", (8100 + int.Parse(index)).ToString()); } if (jdNode["HttpPool"] != null) { jdNode["HttpPool"]["ComponentNetworkHttp"]["address"] = ((string)jdNode["HttpPool"]["ComponentNetworkHttp"]["address"]).Replace("9101", (9100 + int.Parse(index)).ToString()); } if (jdNode["SmartxRpc"] != null) { jdNode["SmartxRpc"]["ComponentNetworkHttp"]["address"] = ((string)jdNode["SmartxRpc"]["ComponentNetworkHttp"]["address"]).Replace("5000", ((5000 - 1) + int.Parse(index)).ToString()); } if (jdNode["ComponentNetworkInner"] != null) { jdNode["ComponentNetworkInner"]["address"] = ((string)jdNode["ComponentNetworkInner"]["address"]).Replace("58601", (58600 + int.Parse(index)).ToString()); } if (jdNode["RelayNetwork"] != null) { jdNode["RelayNetwork"]["ComponentNetworkInner"]["address"] = ((string)jdNode["RelayNetwork"]["ComponentNetworkInner"]["address"]).Replace("57601", (57600 + int.Parse(index)).ToString()); } if (jdNode["Pool"] != null) { jdNode["Pool"]["db_path"] = ((string)jdNode["Pool"]["db_path"]) + index; } if (jdNode["HttpPoolRelay"] != null) { jdNode["HttpPoolRelay"]["number"] = jdNode["HttpPoolRelay"]["number"].ToString().Replace("Pool1", "Pool" + index); } } // 数据库路径 if (jdNode["LevelDBStore"] != null && args.Length >= 3) { jdNode["LevelDBStore"]["db_path"] = param["db"]; } Entity.Root.AddComponent <ComponentStart>(jdNode); } //TransferProcess.Test(); Update(); }