public ContractsData GetContracts(int page) { const int numPerPage = 20; if (page <= 0) { page = 1; } var result = new ContractsData { Page = page }; using (var client = CreateApi()) { var offset = numPerPage * (page - 1); var res = client.SmartContractsAllListGet(offset, numPerPage + 1); result.HaveNextPage = res.SmartContractsList.Count > numPerPage; var count = Math.Min(numPerPage, res.SmartContractsList.Count); for (var i = 0; i < count; i++) { var c = res.SmartContractsList[i]; var cInfo = new ContractLinkInfo(i + offset + 1, Base58Encoding.Encode(c.Address)); result.Contracts.Add(cInfo); } } result.NumStr = result.Contracts.Any() ? $"{result.Contracts.First().Index} - {result.Contracts.Last().Index}" : "0"; return(result); }
// Gets the list of smart contracts on given page from node public object GetContracts(int page, int limit) { if (limit < 10 || limit > 100) { limit = 25; } if (page <= 0) { page = 1; } var stats = _indexService.GetStatData(Net); var lastPage = ConvUtils.GetNumPages(stats.Total.SmartContracts.Value, limit); var lastContract = stats.Total.SmartContracts.Value; using (var client = CreateApi()) { // Get data from API var offset = limit * (page - 1); var res = client.SmartContractsAllListGet(offset, limit + 1); // Fill result with data var count = Math.Min(limit, res.SmartContractsList.Count); var contracts = new List <ContractLinkInfo>(); for (var i = 0; i < count; i++) { var c = res.SmartContractsList[i]; var cInfo = new ContractLinkInfo(i + offset + 1, Base58Encoding.Encode(c.Address)); contracts.Add(cInfo); } return(new { Contracts = contracts, Page = page, HaveNextPage = page < lastPage, LastPage = lastPage, NumStr = contracts.Any() ? $"{contracts.First().Index} - {contracts.Last().Index} of total {lastContract}" : "0" }); } }
public ContractsData GetContracts(int page) { if (page <= 0) { page = 1; } var result = new ContractsData { Page = page }; if (Net == "tetris") { using (var client = CreateApi()) { var offset = result.NumPerPage * (page - 1); var res = client.SmartContractsAllListGet(offset, result.NumPerPage + 1); result.HaveNextPage = res.SmartContractsList.Count > result.NumPerPage; var count = Math.Min(result.NumPerPage, res.SmartContractsList.Count); for (var i = 0; i < count; i++) { var c = res.SmartContractsList[i]; var cInfo = new ContractLinkInfo(i + offset + 1, c.Address); result.Contracts.Add(cInfo); } } } else { using (var db = ApiFab.GetDbContext()) { var i = 1; foreach (var s in db.Smarts.Where(s => s.Network == Net)) { result.Contracts.Add(new ContractLinkInfo(i++, s.Address)); } } } return(result); }