Пример #1
0
        static bool UpdateDefault(IConfiguration configuration)
        {
            var settings = new CliSettings(configuration.GetSection("ApplicationConfiguration"));

            settings.Protocol = ProtocolSettings.Load("config".GetEnvConfigPath());
            return(null == Interlocked.CompareExchange(ref _default, settings, null));
        }
Пример #2
0
        static void Main()
        {
            RpcClient rpcClient = new RpcClient(new Uri("http://*****:*****@"D:\Work\neo_code\neo-node\neo-cli\bin\Debug\net5.0\1.json", "1").Result);

            ContractAPIDemo contractAPIDemo = new ContractAPIDemo(rpcClient);

            contractAPIDemo.Run();

            PolicyAPIDemo policyAPIDemo = new PolicyAPIDemo(rpcClient);

            policyAPIDemo.Run();

            RpcClientDemo rpcClientDemo = new RpcClientDemo(rpcClient);

            rpcClientDemo.Run();

            Console.ReadKey();
        }
Пример #3
0
        public async void Start(string[] args)
        {
            if (NeoSystem != null)
            {
                return;
            }
            bool verifyImport = true;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "/noverify":
                case "--noverify":
                    verifyImport = false;
                    break;
                }
            }

            _ = new Logger();

            NeoSystem = new NeoSystem(ProtocolSettings.Load("config.json"), Settings.Default.Storage.Engine, Settings.Default.Storage.Path);

            NeoSystem.AddService(this);

            LocalNode = NeoSystem.LocalNode.Ask <LocalNode>(new LocalNode.GetInstance()).Result;

            foreach (var plugin in Plugin.Plugins)
            {
                // Register plugins commands

                RegisterCommand(plugin, plugin.Name);
            }

            using (IEnumerator <Block> blocksBeingImported = GetBlocksFromFile().GetEnumerator())
            {
                while (true)
                {
                    List <Block> blocksToImport = new List <Block>();
                    for (int i = 0; i < 10; i++)
                    {
                        if (!blocksBeingImported.MoveNext())
                        {
                            break;
                        }
                        blocksToImport.Add(blocksBeingImported.Current);
                    }
                    if (blocksToImport.Count == 0)
                    {
                        break;
                    }
                    await NeoSystem.Blockchain.Ask <Blockchain.ImportCompleted>(new Blockchain.Import
                    {
                        Blocks = blocksToImport,
                        Verify = verifyImport
                    });

                    if (NeoSystem is null)
                    {
                        return;
                    }
                }
            }
            NeoSystem.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
                {
                    OpenWallet(Settings.Default.UnlockWallet.Path, Settings.Default.UnlockWallet.Password);
                }
                catch (FileNotFoundException)
                {
                    Console.WriteLine($"Warning: wallet file \"{Settings.Default.UnlockWallet.Path}\" not found.");
                }
                catch (System.Security.Cryptography.CryptographicException)
                {
                    Console.WriteLine($"Failed to open file \"{Settings.Default.UnlockWallet.Path}\"");
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"error: {ex.GetBaseException().Message}");
                }
            }
        }
Пример #4
0
        private dynamic dispatchEngineMethod(EngineMethod method, dynamic args)
        {
            switch (method)
            {
            case EngineMethod.create:
                TriggerType trigger   = (TriggerType)args.trigger;
                long        gas       = long.Parse((string)args.gas);
                IVerifiable container = null;
                if (args.container != null)
                {
                    container = deserializeContainer(args.container);
                }
                Block persistingBlock = null;
                if (args.persistingBlock != null)
                {
                    persistingBlock = new Block();
                    using (MemoryStream ms = new MemoryStream(args.persistingBlock))
                        using (BinaryReader reader = new BinaryReader(ms))
                        {
                            persistingBlock.Deserialize(reader);
                        }
                }
                ProtocolSettings settings = ProtocolSettings.Default;
                if (args.settings != null)
                {
                    settings = ProtocolSettings.Load(parseConfig(args.settings));
                }

                return(this._create(trigger, container, this.selectSnapshot(args.snapshot, false), persistingBlock, settings, gas));

            case EngineMethod.execute:
                return(this._execute());

            case EngineMethod.loadscript:
                Script    script          = new Script((byte[])args.script);
                CallFlags flags           = (CallFlags)((byte)args.flags);
                UInt160   scriptHash      = null;
                int       initialPosition = 0;
                int       rvcount         = -1;

                if (args.scriptHash != null)
                {
                    scriptHash = UInt160.Parse((string)args.scriptHash);
                }

                if (args.initialPosition != null)
                {
                    initialPosition = (int)args.initialPosition;
                }

                if (args.rvcount != null)
                {
                    rvcount = (int)args.rvcount;
                }

                return(this._loadScript(script, flags, scriptHash, rvcount, initialPosition));

            case EngineMethod.loadcontract:
                UInt160   contractHash   = new UInt160((byte[])args.hash);
                string    contractMethod = (string)args.method;
                CallFlags contractFlags  = (CallFlags)((byte)args.flags);
                int       pcount         = (int)args.pcount;

                return(this._loadContract(contractHash, contractMethod, pcount, contractFlags));

            case EngineMethod.getvmstate:
                return(this._getVMState());

            case EngineMethod.getresultstack:
                return(this._getResultStack());

            case EngineMethod.gettrigger:
                return(this._getTrigger());

            case EngineMethod.getgasconsumed:
                return(this._getGasConsumed());

            case EngineMethod.getnotifications:
                return(this._getNotifications());

            case EngineMethod.getlogs:
                return(this._getLogs());

            case EngineMethod.getfaultexception:
                return(this._getFaultException());

            case EngineMethod.dispose_engine:
                this.disposeEngine();

                return(true);

            case EngineMethod.push:
                return(this._push((string)args.item));

            default:
                throw new InvalidOperationException();
            }
        }
Пример #5
0
 public void TestSetup()
 {
     keyPair          = new KeyPair(Wallet.GetPrivateKeyFromWIF("KyXwTh1hB76RRMquSvnxZrJzQx7h9nQP2PCRL38v6VDb5ip3nf1p"));
     scriptHash       = Contract.CreateSignatureRedeemScript(keyPair.PublicKey).ToScriptHash();
     protocolSettings = ProtocolSettings.Load("protocol.json");
 }