Example #1
0
        // 启动应用链
        public bool StartAppChain(string hashString, int port, int wsport)
        {
            UInt160 chainHash = UInt160.Parse(hashString);

            AppChainState state = Blockchain.Root.Store.GetAppChains().TryGet(chainHash);

            if (state != null)
            {
                string path = string.Format("AppChain/{0}_{1}", Message.Magic.ToString("X8"), hashString);

                string fullPath = relativePath.Length > 0 ? relativePath + path : Path.GetFullPath(path);

                Directory.CreateDirectory(fullPath);

                Store appStore = new LevelDBStore(fullPath);

                CreateZoroSystem(chainHash, appStore);

                StartNode(chainHash, port, wsport);

                return(true);
            }

            return(false);
        }
Example #2
0
        public static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            XDocument xdoc = null;

            /*
             * try
             * {
             *  xdoc = XDocument.Load("https://bhpa.io/client/update.xml");
             * }
             * catch { }
             * if (xdoc != null)
             * {
             *  Version version = Assembly.GetExecutingAssembly().GetName().Version;
             *  Version minimum = Version.Parse(xdoc.Element("update").Attribute("minimum").Value);
             *  if (version < minimum)
             *  {
             *      using (UpdateDialog dialog = new UpdateDialog(xdoc))
             *      {
             *          dialog.ShowDialog();
             *      }
             *      return;
             *  }
             * }
             * if (!InstallCertificate()) return;
             */

            using (LevelDBStore store = new LevelDBStore(Settings.Default.Paths.Chain))
                using (BhpSystem = new BhpSystem(store))
                {
                    Application.Run(MainForm = new MainForm(xdoc));
                }
        }
Example #3
0
 public NeoSystem StartUpNode()
 {
     _store  = new LevelDBStore(Path.GetFullPath(Settings.Default.Paths.Chain));
     _system = new NeoSystem(_store);
     _system.StartNode(
         port: Settings.Default.P2P.Port,
         wsPort: Settings.Default.P2P.WsPort,
         minDesiredConnections: Settings.Default.P2P.MinDesiredConnections,
         maxConnections: Settings.Default.P2P.MaxConnections,
         maxConnectionsPerAddress: Settings.Default.P2P.MaxConnectionsPerAddress);
     if (Settings.Default.UnlockWallet.IsActive)
     {
         try
         {
             Program.Wallet = OpenWallet(GetIndexer(), Settings.Default.UnlockWallet.Path, Settings.Default.UnlockWallet.Password);
         }
         catch (CryptographicException)
         {
             Console.WriteLine($"failed to open file \"{Settings.Default.UnlockWallet.Path}\"");
         }
         if (Settings.Default.UnlockWallet.StartConsensus && Program.Wallet != null)
         {
             OnStartConsensusCommand(null);
         }
     }
     return(_system);
 }
Example #4
0
        public static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            XDocument xdoc = null;

            try
            {
                xdoc = XDocument.Load("https://raw.githubusercontent.com/neo-project/neo-gui/master/update.xml");
            }
            catch { }
            if (xdoc != null)
            {
                Version version = Assembly.GetExecutingAssembly().GetName().Version;
                Version minimum = Version.Parse(xdoc.Element("update").Attribute("minimum").Value);
                if (version < minimum)
                {
                    using (UpdateDialog dialog = new UpdateDialog(xdoc))
                    {
                        dialog.ShowDialog();
                    }
                    return;
                }
            }
            if (!InstallCertificate())
            {
                return;
            }
            using (LevelDBStore store = new LevelDBStore(Settings.Default.Paths.Chain))
                using (NeoSystem = new NeoSystem(store))
                {
                    Application.Run(MainForm = new MainForm(xdoc));
                }
        }
Example #5
0
        protected internal override void OnStart(string[] args)
        {
            store  = new LevelDBStore(Path.GetFullPath(Settings.Default.Paths.Chain));
            system = new KronaSystem(store);
            system.StartNode(
                port: Settings.Default.P2P.Port,
                wsPort: Settings.Default.P2P.WsPort,
                minDesiredConnections: Settings.Default.P2P.MinDesiredConnections,
                maxConnections: Settings.Default.P2P.MaxConnections,
                maxConnectionsPerAddress: Settings.Default.P2P.MaxConnectionsPerAddress);
            if (Settings.Default.UnlockWallet.IsActive)
            {
                try
                {
                    if (!File.Exists(Settings.Default.UnlockWallet.Path))
                    {
                        throw new CryptographicException();
                    }
                    Program.Wallet = OpenWallet(GetIndexer(), Settings.Default.UnlockWallet.Path, Settings.Default.UnlockWallet.Password);
                }
                catch (CryptographicException)
                {
                    Console.WriteLine($"failed to open file \"{Settings.Default.UnlockWallet.Path}\"");
                }
                if (Settings.Default.UnlockWallet.StartConsensus && Program.Wallet != null)
                {
                    OnStartConsensusCommand(null);
                }
            }
            bool useRPC = false;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "/rpc":
                case "--rpc":
                case "-r":
                    useRPC = true;
                    break;

                case "/noninteractive":
                case "--noninteractive":
                case "-noninteractive":
                    PreRun();
                    break;
                }
            }
            if (useRPC)
            {
                system.StartRpc(Settings.Default.RPC.BindAddress,
                                Settings.Default.RPC.Port,
                                wallet: Program.Wallet,
                                sslCert: Settings.Default.RPC.SslCert,
                                password: Settings.Default.RPC.SslCertPassword,
                                maxConcurrentConnections: Settings.Default.RPC.MaxConcurrentConnections);
            }
        }
        private void InitializeNeoSystem()
        {
            LevelDBStore store = new LevelDBStore(Settings.Paths.Chain);

            NeoSystem = new NeoSystem(store);

            NeoSystem.ActorSystem.ActorOf(NotificationBroadcaster.Props(NeoSystem.Blockchain));
            NeoSystem.StartNode(Settings.P2P.Port, Settings.P2P.WsPort);
        }
        private static void InitializeNeoSystem(string[] args)
        {
            LevelDBStore store = new LevelDBStore(NeoSettings.Default.DataDirectoryPath);

            NeoSystem = new NeoSystem(store);
            NeoSystem.StartNode(NeoSettings.Default.NodePort, NeoSettings.Default.WsPort);

            CreateWebHostBuilder(args).Build().Run();
        }
        private void Test()
        {
            string WIF       = Config.getValue("WIF");
            string targetWIF = Config.getValue("targetWIF");

            keypair          = ZoroHelper.GetKeyPairFromWIF(WIF);
            scriptHash       = ZoroHelper.GetPublicKeyHash(keypair.PublicKey);
            targetscripthash = ZoroHelper.GetPublicKeyHashFromWIF(targetWIF);

            string   path     = Config.getValue("LevelDB");
            Store    appStore = new LevelDBStore(path);
            Snapshot snapshot = appStore.GetSnapshot();

            Console.WriteLine("请输入数量:");
            var param = Console.ReadLine();

            int count = int.Parse(param);

            if (count <= 0)
            {
                return;
            }

            Random             rnd  = new Random();
            DateTime           dt   = DateTime.Now;
            List <Transaction> txns = new List <Transaction>();

            for (int i = 0; i < count; i++)
            {
                txns.Add(MakeTestTransaction(rnd));
            }

            Console.Write("maketxn, ");
            PrintTimeCost(dt);

            dt = DateTime.Now;
            foreach (var tx in txns)
            {
                tx.Verify(snapshot);
            }

            Console.Write("verify, ");
            PrintTimeCost(dt);

            dt = DateTime.Now;
            foreach (var tx in txns)
            {
                tx.Reverify(snapshot);
            }

            Console.Write("reverify, ");
            PrintTimeCost(dt);

            snapshot.Dispose();
            appStore.Dispose();
        }
Example #9
0
        protected internal override void OnStart(string[] args)
        {
            bool useRPC = false;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "/rpc":
                case "--rpc":
                case "-r":
                    useRPC = true;
                    break;
                }
            }
            store  = new LevelDBStore(Path.GetFullPath(Settings.Default.Paths.Chain));
            system = new BhpSystem(store);
            system.StartNode(Settings.Default.P2P.Port, Settings.Default.P2P.WsPort);
            if (Settings.Default.UnlockWallet.IsActive)
            {
                try
                {
                    Program.Wallet = OpenWallet(GetIndexer(), Settings.Default.UnlockWallet.Path, Settings.Default.UnlockWallet.Password);
                }
                catch (CryptographicException)
                {
                    Console.WriteLine($"failed to open file \"{Settings.Default.UnlockWallet.Path}\"");
                }
                if (Settings.Default.UnlockWallet.StartConsensus && Program.Wallet != null)
                {
                    OnStartConsensusCommand(null);
                }
            }
            if (useRPC)
            {
                system.StartRpc(IPAddress.Any, Settings.Default.RPC.Port,
                                wallet: Program.Wallet,
                                walletPassword: Settings.Default.UnlockWallet.Password,
                                isAutoLock: Settings.Default.UnlockWallet.AutoLock,
                                sslCert: Settings.Default.RPC.SslCert,
                                password: Settings.Default.RPC.SslCertPassword);


                //BindAddress
                //system.StartRpc(Settings.Default.RPC.BindAddress,
                //    Settings.Default.RPC.Port,
                //    wallet: Program.Wallet,
                //    sslCert: Settings.Default.RPC.SslCert,
                //    password: Settings.Default.RPC.SslCertPassword);
            }
        }
Example #10
0
        protected internal override void OnStart(string[] args)
        {
            bool useRPC = false;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "/rpc":
                case "--rpc":
                case "-r":
                    useRPC = true;
                    break;
                }
            }
            store  = new LevelDBStore(Path.GetFullPath(Settings.Default.Paths.Chain));
            system = new NeoSystem(store);
            system.StartNode(new ChannelsConfig
            {
                Tcp                      = new IPEndPoint(IPAddress.Any, Settings.Default.P2P.Port),
                WebSocket                = new IPEndPoint(IPAddress.Any, Settings.Default.P2P.WsPort),
                MinDesiredConnections    = Settings.Default.P2P.MinDesiredConnections,
                MaxConnections           = Settings.Default.P2P.MaxConnections,
                MaxConnectionsPerAddress = Settings.Default.P2P.MaxConnectionsPerAddress
            });
            if (Settings.Default.UnlockWallet.IsActive)
            {
                try
                {
                    Program.Wallet = OpenWallet(Settings.Default.UnlockWallet.Path, Settings.Default.UnlockWallet.Password);
                }
                catch (CryptographicException)
                {
                    Console.WriteLine($"failed to open file \"{Settings.Default.UnlockWallet.Path}\"");
                }
                if (Settings.Default.UnlockWallet.StartConsensus && Program.Wallet != null)
                {
                    OnStartConsensusCommand(null);
                }
            }
            if (useRPC)
            {
                system.StartRpc(Settings.Default.RPC.BindAddress,
                                Settings.Default.RPC.Port,
                                wallet: Program.Wallet,
                                sslCert: Settings.Default.RPC.SslCert,
                                password: Settings.Default.RPC.SslCertPassword,
                                maxGasInvoke: Settings.Default.RPC.MaxGasInvoke);
            }
        }
Example #11
0
        public void TestLevelDb()
        {
            using var plugin = new LevelDBStore();
            TestPersistenceDelete(plugin.GetStore(path_leveldb));
            // Test all with the same store

            TestStorage(plugin.GetStore(path_leveldb));

            // Test with different storages

            TestPersistenceWrite(plugin.GetStore(path_leveldb));
            TestPersistenceRead(plugin.GetStore(path_leveldb), true);
            TestPersistenceDelete(plugin.GetStore(path_leveldb));
            TestPersistenceRead(plugin.GetStore(path_leveldb), false);
        }
Example #12
0
        static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var seeds = Settings.Default.SeedNode.Seeds;

            ProtocolSettings.InitSeed(seeds);
            LevelDBStore store = new LevelDBStore(Settings.Default.Paths.Chain);

            OXSystem = new OXSystem(store);
            Application.Run(MainForm = new MainForm());
            Application.Run(new MainForm());
        }
Example #13
0
        static void Main(string arg)
        {
            // input argument is a stringified JSON object
            // This needs to be Neo 3 version
            JObject jsonArg = JObject.Parse(arg);

            // create new invocation transaction with input args
            InvocationTransaction tx_invocation = new InvocationTransaction
            {
                Version    = 1,
                Script     = new byte[0],
                Gas        = new Fixed8(),
                Attributes = new TransactionAttribute[0],
                Inputs     = new CoinReference[0],
                Outputs    = new TransactionOutput[0]
            };
            // can we use a dummy snapshot?
            Snapshot          snapshot = new LevelDBStore("").GetSnapshot();
            long              gasIn    = Convert.ToInt64("10.3423"); // replace with GAS argument
            Fixed8            gas      = new Fixed8(gasIn);
            ApplicationEngine engine   = new ApplicationEngine(TriggerType.Application, tx_invocation, snapshot, gas);

            engine.LoadScript(tx_invocation.Script);
            engine.Execute();
            if (!engine.State.HasFlag(VMState.FAULT))
            {
                engine.Service.Commit();
            }

            string trigger     = TriggerType.Application.ToString();
            string scriptHash  = tx_invocation.Script.ToScriptHash().ToString();
            string engineState = engine.State.ToString();
            string gasConsumed = engine.GasConsumed.ToString();

            string[] notifications = engine.Service.Notifications.ToArray();
            string[] resultStack   = ResultStackToStringArray(engine.ResultStack);


            // output can be stringified JSON object or deliminated results
            // does JObject have stringify?

            Console.WriteLine($"{trigger}${scriptHash}${engineState}${gasConsumed}${resultStack}${notifications}");
        }
Example #14
0
        static void RunMain(string[] args)
        {
            Parser clp = new Parser();

            _parsed = clp.ParseArguments <CLSettings>(args);


            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            XDocument xdoc = null;

            try
            {
                xdoc = XDocument.Load("https://neo.org/client/update.xml");
            }
            catch
            {
            }

            if (xdoc != null)
            {
                Version version = Assembly.GetExecutingAssembly().GetName().Version;
                Version minimum = Version.Parse(xdoc.Element("update").Attribute("minimum").Value);
                if (version < minimum)
                {
                    using (UpdateDialog dialog = new UpdateDialog(xdoc))
                    {
                        dialog.ShowDialog();
                    }
                    return;
                }
            }
            if (!InstallCertificate())
            {
                return;
            }
            using (LevelDBStore store = new LevelDBStore(Settings.Default.Paths.Chain))
                using (NeoSystem = new NeoSystem(store))
                {
                    Application.Run(MainForm = new MainForm(xdoc));
                }
        }
Example #15
0
        private void FollowAppChain(Blockchain blockchain, string hashString)
        {
            UInt160 chainHash = UInt160.Parse(hashString);

            AppChainState state = blockchain.Store.GetAppChains().TryGet(chainHash);

            if (state != null)
            {
                string path = string.Format(Settings.Default.AppChains.Path, hashString);

                Store appStore = new LevelDBStore(Path.GetFullPath(path));

                ZoroSystem appSystem = new ZoroSystem(chainHash, appStore, ActorSystem);

                AppChainSystems[chainHash] = appSystem;

                appSystem.StartNode(state.TcpPort, state.WsPort);
            }
        }
Example #16
0
        protected internal void OnStart()
        {
            string chainPath    = Settings.Default.Paths.Chain;
            string relativePath = Settings.Default.Paths.RelativePath;
            string path         = relativePath.Length > 0 ? relativePath + chainPath : Path.GetFullPath(chainPath);

            store  = new LevelDBStore(path);
            system = new ZoroChainSystem(store, Settings.Default.Paths.RelativePath);

            system.StartNode(UInt160.Zero, Settings.Default.P2P.Port, Settings.Default.P2P.WsPort);

            if (Settings.Default.RPC.IsActive)
            {
                system.StartRpc(IPAddress.Any,
                                Settings.Default.RPC.Port,
                                wallet: Program.Wallet,
                                sslCert: Settings.Default.RPC.SslCert,
                                password: Settings.Default.RPC.SslCertPassword);
            }
        }
Example #17
0
        /// <summary>
        /// TODO: Need to refactor to use CommandLineParser lib
        /// </summary>
        /// <param name="args">Arguments.</param>
        protected internal override void OnStart(string[] args)
        {
            bool useRPC = false;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "/rpc":
                case "--rpc":
                case "-r":
                    useRPC = true;
                    break;
                }
            }
            store  = new LevelDBStore(Path.GetFullPath(Configs.Default.Paths.Chain));
            system = new TrustEDUNetwork(store);
            system.StartNode(Configs.Default.P2P.Port, Configs.Default.P2P.WsPort);
            if (Configs.Default.UnlockWallet.IsActive)
            {
                try
                {
                    Program.Wallet = OpenWallet(GetIndexer(), Configs.Default.UnlockWallet.Path, Configs.Default.UnlockWallet.Password);
                }
                catch (CryptographicException)
                {
                    Console.WriteLine($"failed to open file \"{Configs.Default.UnlockWallet.Path}\"");
                }
                if (Configs.Default.UnlockWallet.StartConsensus && Program.Wallet != null)
                {
                    OnStartConsensusCommand(null);
                }
            }
            if (useRPC)
            {
                system.StartRpc(IPAddress.Parse("127.0.0.1"), Configs.Default.RPC.Port,
                                wallet: Program.Wallet,
                                sslCert: Configs.Default.RPC.SslCert,
                                password: Configs.Default.RPC.SslCertPassword);
            }
        }
Example #18
0
        protected internal override void OnStart(string[] args)
        {
            bool useRPC     = false;
            bool disableLog = false;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "/rpc":
                case "--rpc":
                case "-r":
                    useRPC = true;
                    break;

                case "/disableLog":
                case "--disableLog":
                case "-logoff":
                    disableLog = true;
                    break;
                }
            }

            if (disableLog)
            {
                PluginManager.EnableLog(false);
            }

            string chainPath    = Settings.Default.Paths.Chain;
            string relativePath = Settings.Default.Paths.RelativePath;
            string path         = relativePath.Length > 0 ? relativePath + chainPath : Path.GetFullPath(chainPath);

            store  = new LevelDBStore(path);
            system = new ZoroChainSystem(store, Settings.Default.Paths.RelativePath);

            if (Settings.Default.UnlockWallet.IsActive)
            {
                try
                {
                    //Task.Factory.StartNew(() => HttpServer.HttpServerStart(Settings.Default.UnlockWallet.HttpAddress));
                    //Settings.Default.UnlockWallet.Password = ReadPassword("Wallet password");
                    //Console.WriteLine($"http server start \"{Settings.Default.UnlockWallet.HttpAddress}\"");
                    Program.Wallet = OpenWallet(Settings.Default.UnlockWallet.Path, Settings.Default.UnlockWallet.Password);
                }
                catch (CryptographicException)
                {
                    //Console.WriteLine($"failed to start http server \"{Settings.Default.UnlockWallet.HttpAddress}\"");
                    Console.WriteLine($"failed to open file \"{Settings.Default.UnlockWallet.Path}\"");
                }
            }

            system.StartNode(UInt160.Zero, Settings.Default.P2P.Port, Settings.Default.P2P.WsPort);
            if (Settings.Default.UnlockWallet.StartConsensus && Program.Wallet != null)
            {
                OnStartConsensusCommand(null);
            }
            if (useRPC)
            {
                system.StartRpc(IPAddress.Any,
                                Settings.Default.RPC.Port,
                                wallet: Program.Wallet,
                                sslCert: Settings.Default.RPC.SslCert,
                                password: Settings.Default.RPC.SslCertPassword);
            }
        }