private async Task SendNodesInfoToGroupAsync(ChatId chatid) { var wc = new WebClient(); var json = wc.DownloadString(LyraGlobal.SelectNode(_network) + "LyraNode/GetBillboard"); var bb = JsonConvert.DeserializeObject<BillBoardData>(json); var sb = new StringBuilder(); sb.AppendLine($"*Consensus Algorithm (PBFT) Settings*"); sb.AppendLine($"Total Needed Minimal Node Number: {ProtocolSettings.Default.ConsensusTotalNumber}"); sb.AppendLine($"Consensus Win Number: {ProtocolSettings.Default.ConsensusWinNumber}"); sb.AppendLine($"Maxmimum Failed Node Number: {ProtocolSettings.Default.ConsensusNumber}"); sb.AppendLine($"Current Running Node Count: {bb.AllNodes.Count}"); sb.AppendLine($"Current Nodes can do Authorizing: {bb.AllNodes.Count(a => a.Value.ableToAuthorize)}"); var cando = bb.canDoConsensus ? "Yes" : "No"; sb.AppendLine($"Consensus Can be Made Now: {cando}"); sb.AppendLine("\n*Fully Functional Nodes List*\n"); sb.AppendLine("`" + bb.AllNodes.Values.Where(a => a.ableToAuthorize) .Select(b => b.accountID.Shorten()).Aggregate((c, d) => c + "\n" + d) + "`"); sb.AppendLine("\n*Nodes which has trouble*\n"); sb.AppendLine("`" + bb.AllNodes.Values.Where(a => !a.ableToAuthorize) .Aggregate(new StringBuilder(), (c, n) => c.AppendLine(n.accountID.Shorten() + ": " + n.FailReasons.Select(a => "[" + a + "]").Aggregate((a, b) => a + b)), sb => sb.ToString()) + "`"); await SendGroupMessageAsync(chatid, sb.ToString()); }
private async Task SendHeight(ChatId chatid) { var wc = new WebClient(); var json = wc.DownloadString(LyraGlobal.SelectNode(_network) + "LyraNode/GetSyncState"); var bb = JsonConvert.DeserializeObject<GetSyncStateAPIResult>(json); await SendGroupMessageAsync(chatid, $"Current Height: *{bb.NewestBlockUIndex}*"); }
private async Task SendNodesInfoToGroupAsync() { var wc = new WebClient(); var json = wc.DownloadString(LyraGlobal.SelectNode("devnet") + "LyraNode/GetBillboard"); var bb = JsonConvert.DeserializeObject <BillBoard>(json); var sb = new StringBuilder(); foreach (var node in bb.AllNodes.Values) { sb.AppendLine($"{node.AccountID}"); sb.AppendLine($"Staking Balance: {node.Balance}"); sb.AppendLine($"Last Staking Time: {node.LastStaking}"); sb.AppendLine(); } await SendGroupMessageAsync(sb.ToString()); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _waitOrder = new AutoResetEvent(false); try { var networkId = LyraNodeConfig.GetNetworkId(); _log.LogInformation($"{LyraGlobal.PRODUCTNAME} {LyraGlobal.NODE_VERSION} Mode: {Neo.Settings.Default.LyraNode.Lyra.Mode}: Starting node daemon for {networkId}."); // something must be initialized first Wallet PosWallet; string lyrawalletfolder = Wallet.GetFullFolderName(networkId, "wallets"); if (!Directory.Exists(lyrawalletfolder)) { Directory.CreateDirectory(lyrawalletfolder); } var walletStore = new SecuredWalletStore(lyrawalletfolder); if (!walletStore.Exists(Neo.Settings.Default.LyraNode.Lyra.Wallet.Name)) { _log.LogInformation($"Creating wallet for {networkId}."); (var privateKey, var publicKey) = Signatures.GenerateWallet(); _log.LogInformation($"The new wallet {Neo.Settings.Default.LyraNode.Lyra.Wallet.Name} for {networkId} was created."); //Console.WriteLine($"Private Key: {privateKey}"); _log.LogInformation($"Account ID: {publicKey}"); walletStore.Create(Neo.Settings.Default.LyraNode.Lyra.Wallet.Name, Neo.Settings.Default.LyraNode.Lyra.Wallet.Password, networkId, privateKey, publicKey, ""); _log.LogInformation($"Wallet saved to: {lyrawalletfolder}{Neo.Settings.Default.LyraNode.Lyra.Wallet.Name}.lyrawallet"); } PosWallet = Wallet.Open(walletStore, Neo.Settings.Default.LyraNode.Lyra.Wallet.Name, Neo.Settings.Default.LyraNode.Lyra.Wallet.Password, LyraRestClient.Create(networkId, "", "NodeService", "1.0", LyraGlobal.SelectNode(networkId) + "Node/")); _log.LogInformation($"Staking wallet: {PosWallet.AccountId}"); PosWallet.SetVoteFor(PosWallet.AccountId); var blcokcount = await _store.GetBlockCountAsync(); if (blcokcount > 0 && networkId == "devnet") // not genesis { try { await PosWallet.SyncAsync(null); } catch { } } var localNode = DagSystem.ActorSystem.ActorOf(Neo.Network.P2P.LocalNode.Props()); Dag = new DagSystem(_hostEnv, _store, _lyraEventContext, PosWallet, localNode); _ = Task.Run(async() => await Dag.StartAsync()).ConfigureAwait(false); await Task.Delay(30000); } catch (Exception ex) { _log.LogCritical($"NodeService: Error Initialize! {ex}"); } while (!stoppingToken.IsCancellationRequested) { // do work if (_waitOrder.WaitOne(1000)) { _waitOrder.Reset(); } else { // no new order. do house keeping. } } }