public StateService(IOptions <DbSettings> dbOptions, IMainStatsState mainStats) { this.MainStats = mainStats; Stopwatch stopwatch = Stopwatch.StartNew(); this.db = StateOfNeoContext.Create(dbOptions.Value.DefaultConnection); this.Contracts = new ContractsState(); this.GetLatestTimestamp(); this.LoadTransactionTypes(); this.LoadLastActiveAddresses(); this.LoadLastTransactions(); this.LoadTransactionsMainChart(); this.LoadCreatedAddressesMainChart(); this.LoadActiveAddressesMainChart(); this.LoadBlockTimesMainChart(); this.LoadConsensusRewardsMainChart(); this.LoadBlockSizesMainChart(); stopwatch.Stop(); Log.Information($"{nameof(StateService)} initialization {stopwatch.ElapsedMilliseconds} ms"); }
public void Run() { var addresses = this.db.Addresses .OrderByDescending(x => x.CreatedOn) .Select(x => x.PublicAddress) .ToList(); var contracts = this.db.SmartContracts.ToList(); var bcAddresses = Blockchain.Singleton.GetSnapshot().Accounts; var updatedAddressesCount = 0; foreach (var address in addresses) { var addressUpdated = GetAddressAssets(address, this.db); if (addressUpdated != null) { updatedAddressesCount++; if (this.db.ChangeTracker.Entries().Count() > 10_000) { Log.Information($"Updated {updatedAddressesCount} out of {addresses.Count}. {addresses.Count - updatedAddressesCount} to go!"); this.db.SaveChanges(); this.db.Dispose(); this.db = StateOfNeoContext.Create(this.connectionString); Log.Information($"Save changes done"); } } } }
public BalanceUpdater(IOptions <DbSettings> dbSettings) { this.connectionString = dbSettings.Value.DefaultConnection; this.db = StateOfNeoContext.Create(this.connectionString); this.Run(); }
public SmartContractEngine(IOptions <DbSettings> dbSettings) { this.connectionString = dbSettings.Value.DefaultConnection; this.db = StateOfNeoContext.Create(this.connectionString); this.EnsureAllContractsFromLastSnapshot(); this.contracts = this.db.SmartContracts.ToList(); }
public NodeSynchronizer( RPCNodeCaller rPCNodeCaller, IOptions <NetSettings> netsettings, IOptions <DbSettings> dbSettings) { this.db = StateOfNeoContext.Create(dbSettings.Value.DefaultConnection); this.rPCNodeCaller = rPCNodeCaller; this.netsettings = netsettings; }
public async Task Run() { var db = StateOfNeoContext.Create(this.connectionString); // NEO var neoAsset = db.Assets.FirstOrDefault(x => x.Name == "NEO"); if (neoAsset != null) { neoAsset.CreatorAddressId = Blockchain.GoverningToken.Admin.ToAddress(); db.Assets.Update(neoAsset); } // GAS var gasAsset = db.Assets.FirstOrDefault(x => x.Name == "GAS"); if (gasAsset != null) { gasAsset.CreatorAddressId = Blockchain.UtilityToken.Admin.ToAddress(); db.Assets.Update(gasAsset); } // GlobalAssets var globalAssets = db.Assets .Where(x => x.GlobalType.HasValue) .Where(x => x.CreatorAddressId != null) .ToList(); var registerTransactions = db.RegisterTransactions.ToList(); foreach (var regTx in registerTransactions) { var jsonName = JObject.Parse(regTx.Name.Substring(1, regTx.Name.Length - 2)); var name = jsonName["name"]?.AsString(); var asset = globalAssets.FirstOrDefault(x => x.Name == name); if (asset != null) { asset.CreatorAddressId = regTx.AdminAddress; db.Assets.Update(asset); } } Nep5CreatorUpdate(db); await db.SaveChangesAsync(); }
static void Main(string[] args) { var connectionString = "Server=.\\;Database=neo-monitor-main;Trusted_Connection=True;MultipleActiveResultSets=true"; var db = StateOfNeoContext.Create(connectionString); var items = db.Blocks.Where(x => x.DailyStamp == 0).Take(50_000).ToList(); var count = 0; var iteration = 1; while (items.Any()) { var sw = System.Diagnostics.Stopwatch.StartNew(); foreach (var item in items) { var date = item.Timestamp.ToUnixDate(); var hourStamp = new DateTime(date.Year, date.Month, date.Day, date.Hour, 0, 0).ToUnixTimestamp(); var dayStamp = new DateTime(date.Year, date.Month, date.Day).ToUnixTimestamp(); var monthStamp = new DateTime(date.Year, date.Month, 1).ToUnixTimestamp(); item.HourlyStamp = hourStamp; item.DailyStamp = dayStamp; item.MonthlyStamp = monthStamp; } db.SaveChanges(); sw.Stop(); Console.WriteLine($"{iteration} - {sw.ElapsedMilliseconds}"); count += 50_000; if (count % 150_000 == 0) { db = StateOfNeoContext.Create(connectionString); } items = db.Blocks.Where(x => x.DailyStamp == 0).Take(50_000).ToList(); iteration++; } db.SaveChanges(); }
public MainStatsState(IOptions <DbSettings> dbOptions) { Stopwatch stopwatch = Stopwatch.StartNew(); this.db = StateOfNeoContext.Create(dbOptions.Value.DefaultConnection); this.TotalStats = this.db.TotalStats.FirstOrDefault(); this.GetHeaderStats(); if (this.TotalStats == null) { this.TotalStats = new TotalStats { BlockCount = this.headerStats.Height, Timestamp = this.headerStats.Timestamp }; this.db.TotalStats.Add(this.TotalStats); this.db.SaveChanges(); } this.GetTotalBlocksCount(); this.GetTotalBlocksTimesCount(); this.GetTotalBlocksSizesCount(); this.GetTotalAddressCount(); this.GetTotalAssetsCount(); this.GetTotalClaimed(); this.GetTotalTxCount(); this.GetTotalGasAndNeoTxCount(); this.GetTotalNep5TxCount(); this.db.SaveChanges(); this.db.Dispose(); stopwatch.Stop(); Log.Information($"{nameof(MainStatsState)} initialization {stopwatch.ElapsedMilliseconds} ms"); }
public BlockchainBalances(IOptions <DbSettings> dbSettings) { this.connectionString = dbSettings.Value.DefaultConnection; this.db = StateOfNeoContext.Create(this.connectionString); }
public async Task Run() { var sw = Stopwatch.StartNew(); Log.Information($"SmartContractEngine Run method started at {DateTime.UtcNow}"); var dbContracts = this.db.SmartContracts.ToList(); var blocksWithTransactions = this.db.Transactions .Include(x => x.InvocationTransaction) .Where(x => x.Type == Neo.Network.P2P.Payloads.TransactionType.InvocationTransaction) .Where(x => x.InvocationTransaction.SmartContractId == null || x.InvocationTransaction.TransactionHash == null) .Select(x => new { x.BlockId, x.Hash, x.InvocationTransactionId }) .GroupBy(x => x.BlockId) .ToList(); var i = 1; var swCounter = Stopwatch.StartNew(); foreach (var blockWithTransactions in blocksWithTransactions) { var block = Blockchain.Singleton.GetBlock(UInt256.Parse(blockWithTransactions.Key)); foreach (var dbTransaction in blockWithTransactions.ToList()) { if (i % 100_000 == 0) { this.db.SaveChanges(); Log.Information($"For 100_000 transactions time it took was {swCounter.ElapsedMilliseconds}"); i = 1; swCounter.Restart(); } var dbInvocationTransaction = this.db.InvocationTransactions .FirstOrDefault(x => x.Id == dbTransaction.InvocationTransactionId); if (dbInvocationTransaction != null) { if (dbInvocationTransaction.SmartContractId != null) { continue; } } else { dbInvocationTransaction = new Data.Models.Transactions.InvocationTransaction(); } var blockTx = block.Transactions.FirstOrDefault(x => x.Hash.ToString() == dbTransaction.Hash); if (blockTx != null) { var unboxed = blockTx as Neo.Network.P2P.Payloads.InvocationTransaction; var appResult = this.GetExecutionResult(unboxed); var scHash = appResult; if (appResult == null) { continue; } var sc = this.contracts.FirstOrDefault(x => x.Hash == scHash.ToString()); if (sc != null) { if (sc.Timestamp == 0 || sc.Timestamp > block.Timestamp) { sc.Timestamp = block.Timestamp; } dbInvocationTransaction.ContractHash = sc.Hash; dbInvocationTransaction.SmartContractId = sc.Id; dbInvocationTransaction.TransactionHash = dbTransaction.Hash; } i++; } } if (this.db.ChangeTracker.Entries().Count() > 10_000) { Log.Information($"{nameof(this.db.ChangeTracker)} entries > 10_000 next is save changes"); await this.db.SaveChangesAsync(); Log.Information($"Save changes done!"); sw.Stop(); Log.Information($"Took {sw.ElapsedMilliseconds} ms for this iteration"); sw.Reset(); sw.Start(); this.db.Dispose(); this.db = StateOfNeoContext.Create(this.connectionString); } } Log.Information($"SmartContractEngine Run method ENDED at {DateTime.UtcNow}"); }