Example #1
0
        public Task <(Transaction tx, RpcApplicationLog?appLog)> GetTransactionAsync(UInt256 txHash)
        {
            try
            {
                if (disposedValue)
                {
                    return(Task.FromException <(Transaction, RpcApplicationLog?)>(new ObjectDisposedException(nameof(OfflineNode))));
                }

                var tx = NativeContract.Ledger.GetTransaction(neoSystem.StoreView, txHash);
                if (tx == null)
                {
                    return(Task.FromException <(Transaction, RpcApplicationLog?)>(new Exception("Unknown Transaction")));
                }

                var jsonLog = ExpressAppLogsPlugin.GetAppLog(rocksDbStorageProvider, txHash);
                var result  = jsonLog != null
                    ? (tx, RpcApplicationLog.FromJson(jsonLog, ProtocolSettings))
                    : (tx, null);

                return(Task.FromResult(result));
            }
            catch (Exception ex)
            {
                return(Task.FromException <(Transaction, RpcApplicationLog?)>(ex));
            }
        }
Example #2
0
        public async Task RunAsync(IExpressStore store, ExpressConsensusNode node, uint secondsPerBlock, bool enableTrace, TextWriter writer, CancellationToken token)
        {
            if (IsRunning(node))
            {
                throw new Exception("Node already running");
            }

            chain.InitalizeProtocolSettings(secondsPerBlock);

            await writer.WriteLineAsync(store.GetType().Name).ConfigureAwait(false);

            var tcs = new TaskCompletionSource <bool>();

            _ = Task.Run(() =>
            {
                try
                {
                    var defaultAccount = node.Wallet.Accounts.Single(a => a.IsDefault);
                    using var mutex    = new Mutex(true, GLOBAL_PREFIX + defaultAccount.ScriptHash);

                    var wallet          = DevWallet.FromExpressWallet(node.Wallet);
                    var multiSigAccount = node.Wallet.Accounts.Single(a => a.IsMultiSigContract());

                    var dbftPlugin        = new Neo.Consensus.DBFTPlugin();
                    var logPlugin         = new Node.LogPlugin(writer);
                    var storageProvider   = new Node.ExpressStorageProvider((IStore)store);
                    var appEngineProvider = enableTrace ? new Node.ExpressApplicationEngineProvider() : null;
                    var appLogsPlugin     = new Node.ExpressAppLogsPlugin(store);

                    using var system     = new Neo.NeoSystem(storageProvider.Name);
                    var rpcSettings      = new Neo.Plugins.RpcServerSettings(port: node.RpcPort);
                    var rpcServer        = new Neo.Plugins.RpcServer(system, rpcSettings);
                    var expressRpcServer = new ExpressRpcServer(store, multiSigAccount);
                    rpcServer.RegisterMethods(expressRpcServer);
                    rpcServer.RegisterMethods(appLogsPlugin);
                    rpcServer.StartRpcServer();

                    system.StartNode(new Neo.Network.P2P.ChannelsConfig
                    {
                        Tcp       = new IPEndPoint(IPAddress.Loopback, node.TcpPort),
                        WebSocket = new IPEndPoint(IPAddress.Loopback, node.WebSocketPort),
                    });
                    dbftPlugin.Start(wallet);

                    token.WaitHandle.WaitOne();
                }
                catch (Exception ex)
                {
                    tcs.SetException(ex);
                }
                finally
                {
                    tcs.TrySetResult(true);
                }
            });
            await tcs.Task.ConfigureAwait(false);
        }
Example #3
0
        public async Task RunAsync(IStorageProvider store, ExpressConsensusNode node, bool enableTrace, TextWriter writer, CancellationToken token)
        {
            if (IsRunning(node))
            {
                throw new Exception("Node already running");
            }

            var tcs = new TaskCompletionSource <bool>();

            _ = Task.Run(() =>
            {
                try
                {
                    var defaultAccount = node.Wallet.Accounts.Single(a => a.IsDefault);
                    using var mutex    = new Mutex(true, GLOBAL_PREFIX + defaultAccount.ScriptHash);

                    var wallet          = DevWallet.FromExpressWallet(ProtocolSettings, node.Wallet);
                    var multiSigAccount = wallet.GetMultiSigAccounts().Single();

                    var logPlugin             = new Node.LogPlugin(writer);
                    var storageProviderPlugin = new Node.StorageProviderPlugin(store);
                    var appEngineProvider     = enableTrace ? new Node.ExpressApplicationEngineProvider() : null;
                    var dbftPlugin            = new Neo.Consensus.DBFTPlugin(GetConsensusSettings(chain));
                    var appLogsPlugin         = new Node.ExpressAppLogsPlugin(store);

                    using var neoSystem  = new Neo.NeoSystem(ProtocolSettings, storageProviderPlugin.Name);
                    var rpcSettings      = GetRpcServerSettings(chain, node);
                    var rpcServer        = new Neo.Plugins.RpcServer(neoSystem, rpcSettings);
                    var expressRpcServer = new ExpressRpcServer(neoSystem, store, multiSigAccount.ScriptHash);
                    rpcServer.RegisterMethods(expressRpcServer);
                    rpcServer.RegisterMethods(appLogsPlugin);
                    rpcServer.StartRpcServer();

                    neoSystem.StartNode(new Neo.Network.P2P.ChannelsConfig
                    {
                        Tcp       = new IPEndPoint(IPAddress.Loopback, node.TcpPort),
                        WebSocket = new IPEndPoint(IPAddress.Loopback, node.WebSocketPort),
                    });
                    dbftPlugin.Start(wallet);

                    // DevTracker looks for a string that starts with "Neo express is running" to confirm that the instance has started
                    // Do not remove or re-word this console output:
                    writer.WriteLine($"Neo express is running ({store.GetType().Name})");

                    token.WaitHandle.WaitOne();
                }
                catch (Exception ex)
                {
                    tcs.SetException(ex);
                }
                finally
                {
                    tcs.TrySetResult(true);
                }
            });
            await tcs.Task.ConfigureAwait(false);
Example #4
0
        public OfflineNode(IExpressStore store, Wallet nodeWallet, ExpressChain chain, bool enableTrace)
        {
            this.nodeWallet           = nodeWallet;
            this.chain                = chain;
            this.store                = store;
            applicationEngineProvider = enableTrace ? new ExpressApplicationEngineProvider() : null;
            storageProvider           = new ExpressStorageProvider((IStore)store);
            _         = new ExpressAppLogsPlugin(store);
            neoSystem = new NeoSystem(storageProvider.Name);

            ApplicationEngine.Log += OnLog !;
        }
Example #5
0
        public OfflineNode(ProtocolSettings settings, RocksDbStorageProvider rocksDbStorageProvider, Wallet nodeWallet, ExpressChain chain, bool enableTrace)
        {
            this.nodeWallet             = nodeWallet;
            this.chain                  = chain;
            this.rocksDbStorageProvider = rocksDbStorageProvider;
            applicationEngineProvider   = enableTrace ? new ExpressApplicationEngineProvider() : null;
            consensusNodesKeys          = new Lazy <KeyPair[]>(() => chain.ConsensusNodes
                                                               .Select(n => n.Wallet.DefaultAccount ?? throw new Exception())
                                                               .Select(a => new KeyPair(a.PrivateKey.HexToBytes()))
                                                               .ToArray());

            var storageProviderPlugin = new StorageProviderPlugin(rocksDbStorageProvider);

            _         = new ExpressAppLogsPlugin(rocksDbStorageProvider);
            neoSystem = new NeoSystem(settings, storageProviderPlugin.Name);

            ApplicationEngine.Log += OnLog !;
        }
Example #6
0
        public JObject GetApplicationLog(JArray _params)
        {
            UInt256 hash = UInt256.Parse(_params[0].AsString());

            return(ExpressAppLogsPlugin.TryGetAppLog(store, hash) ?? throw new RpcException(-100, "Unknown transaction"));
        }