Exemple #1
0
        public async Task <IActionResult> List(int page = 1, int pageSize = 10, bool global = true)
        {
            var result = await this.paginating.GetPage <Asset, AssetListViewModel>(
                page,
                pageSize,
                x => x.Hash == AssetConstants.NeoAssetId || x.Hash == AssetConstants.GasAssetId,
                x => global == true?x.GlobalType != null : x.GlobalType == null);

            if (!global)
            {
                for (int i = 0; i < result.Count; i++)
                {
                    var asset = result[i];
                    if (asset.Type == AssetType.NEP5)
                    {
                        try
                        {
                            var total = BlockchainBalances.GetTotalSupply(asset.Hash);
                            asset.TotalSupply = total;
                        }
                        catch (System.Exception e)
                        {
                            Log.Warning($"Total supply could not be called for {asset.Name} with hash {asset.Hash}");
                        }
                    }
                }
            }

            return(this.Ok(result.ToListResult()));
        }
Exemple #2
0
        public IActionResult Get(string address)
        {
            //var result = this.addresses.Find<AddressDetailsViewModel>(address);
            var result = AutoMapper.Mapper.Map <AddressDetailsViewModel>(BlockchainBalances.GetAddressAssets(address, this.db));

            if (result == null)
            {
                return(this.BadRequest("Invalid address."));
            }

            return(this.Ok(result));
        }
Exemple #3
0
        private void UpdateNeoAndGasBalances(IEnumerable <AddressListViewModel> result)
        {
            var resultList = result.ToList();

            for (int i = 0; i < resultList.Count; i++)
            {
                var balancesFromSnapshot = BlockchainBalances.GetGlobalAssets(resultList[i].Address);
                var balancesList         = resultList[i].Balances.ToList();

                for (int j = 0; j < balancesList.Count; j++)
                {
                    if (balancesList[j].Name.ToLower() == "gas")
                    {
                        var gasKey = UInt256.Parse(AssetConstants.GasAssetId);
                        if (balancesFromSnapshot != null)
                        {
                            if (balancesFromSnapshot.ContainsKey(gasKey))
                            {
                                var balance = balancesFromSnapshot[gasKey];
                                balancesList[j].Balance = (decimal)balance;
                            }
                            else
                            {
                                balancesList[j].Balance = 0;
                            }
                        }
                    }
                    else if (balancesList[j].Name.ToLower() == "neo")
                    {
                        var neoKey = UInt256.Parse(AssetConstants.NeoAssetId);
                        if (balancesFromSnapshot != null)
                        {
                            if (balancesFromSnapshot.ContainsKey(neoKey))
                            {
                                var balance = balancesFromSnapshot[neoKey];
                                balancesList[j].Balance = (decimal)balance;
                            }
                            else
                            {
                                balancesList[j].Balance = 0;
                            }
                        }
                    }
                }
            }
        }
Exemple #4
0
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            SmartContractEngine smartContractEngine,
            StateOfNeoSeedData seeder,
            StateOfNeoContext ctx,
            IServiceProvider services,
            IOptions <NetSettings> netSettings,
            IOptions <ImportBlocksSettings> importSettings,
            IHubContext <StatsHub> statsHub,
            IHubContext <PeersHub> peersHub,
            IHubContext <TransactionsHub> txHub,
            IHubContext <NotificationHub> notificationHub,
            BlockchainBalances blockChainBalances,
            RPCNodeCaller nodeCaller,
            NodeCache nodeCache,
            IStateService state
            )
        {
            nodeCache.AddPeerToCache(ctx.Peers.ToList());
            var connectionString = this.Configuration.GetConnectionString("DefaultConnection");

            Program.NeoSystem.ActorSystem.ActorOf(BlockPersister.Props(
                                                      Program.NeoSystem.Blockchain,
                                                      connectionString,
                                                      state,
                                                      statsHub,
                                                      txHub,
                                                      notificationHub,
                                                      blockChainBalances,
                                                      netSettings.Value.Net));

            Program.NeoSystem.ActorSystem.ActorOf(NodePersister.Props(
                                                      Program.NeoSystem.Blockchain,
                                                      connectionString,
                                                      netSettings.Value.Net,
                                                      nodeCaller));

            Program.NeoSystem.ActorSystem.ActorOf(NodeFinder.Props(
                                                      Program.NeoSystem.Blockchain,
                                                      connectionString,
                                                      netSettings.Value,
                                                      peersHub,
                                                      nodeCache));

            //    Program.NeoSystem.ActorSystem.ActorOf(NotificationsListener.Props(Program.NeoSystem.Blockchain, connectionString));

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseCors(builder =>
            {
                builder
                .WithOrigins("http://localhost:8111", "http://localhost:4200")
                .AllowAnyMethod()
                .AllowAnyHeader()
                .AllowCredentials();
            });

            app.UseStaticFiles();

            app.UseSignalR(routes =>
            {
                routes.MapHub <StatsHub>("/hubs/stats");
                routes.MapHub <TransactionsHub>("/hubs/tx");
                routes.MapHub <PeersHub>("/hubs/peers");
                routes.MapHub <NotificationHub>("/hubs/notification");
            });

            Task.Run(() => smartContractEngine.Run());

            seeder.Init();

            app.UseMvc();
        }