Esempio n. 1
0
        // Returns the list of blocks starting from given hash
        public BlocksData BlocksStable(string hash)
        {
            const int limit = 100;

            if (string.IsNullOrEmpty(hash))
            {
                hash = _indexService.GetIndexData(Net).LastBlocks[0].Hash;
            }

            var lastBlock = _indexService.GetIndexData(Net).LastBlockData.LastBlock;
            var lastPage  = ConvUtils.GetNumPages(lastBlock, limit);

            using (var client = CreateApi())
            {
                var blocks        = client.PoolListGetStable(ConvUtils.ConvertHashBack(hash), limit + 1).Pools.Select(p => new BlockInfo(p)).ToList();
                var blocksLimited = blocks.Take(limit).ToList();

                var result = new BlocksData
                {
                    Blocks       = blocksLimited,
                    HaveNextPage = blocks.Count > limit,
                    LastPage     = lastPage,
                    NumStr       = blocksLimited.Any() ? $"{blocksLimited.Last().Number} - {blocksLimited.First().Number} of total {lastBlock}" : "-",
                    LastBlock    = lastBlock
                };
                return(result);
            }
        }
        public TransactionsData PoolTransactions(string hash, int page, int txcount)
        {
            const int numPerPage = 50;

            if (page <= 0)
            {
                page = 1;
            }
            using (var client = CreateApi())
            {
                var lastPage = ConvUtils.GetNumPages(txcount, numPerPage);
                if (page > lastPage)
                {
                    page = lastPage;
                }
                var result = new TransactionsData
                {
                    Page         = page,
                    LastPage     = lastPage,
                    HaveNextPage = page < lastPage
                };
                var offset = numPerPage * (page - 1);
                var poolTr = client.PoolTransactionsGet(ConvUtils.ConvertHashBack(hash), offset, numPerPage);
                var i      = offset + 1;
                foreach (var t in poolTr.Transactions)
                {
                    var tInfo = new TransactionInfo(i, t.Id, t.Trxn);
                    result.Transactions.Add(tInfo);
                    i++;
                }
                result.NumStr = poolTr.Transactions.Any() ? $"{offset + 1} - {offset + poolTr.Transactions.Count} of {txcount}" : "0";
                return(result);
            }
        }
Esempio n. 3
0
        // Gets the list of network nodes by network id
        public NodesData GetNodes(string network, int page, int limit)
        {
            if (limit < 10 || limit > 100)
            {
                limit = 25;
            }
            if (page <= 0)
            {
                page = 1;
            }

            var offset = limit * (page - 1);

            var nodes      = _states[network].Nodes;
            var nodesCount = nodes.Count;
            var listNodes  = nodes.Skip(offset).Take(limit).ToList();

            // Prepare the result and return
            var result = new NodesData
            {
                Page         = page,
                Nodes        = listNodes,
                OnlineCount  = nodes.Count(n => n.Active),
                OfflineCount = nodes.Count(n => !n.Active),
                HaveNextPage = nodesCount > offset + limit,
                LastPage     = ConvUtils.GetNumPages(nodesCount, limit),
                NumStr       = nodesCount > 0 ? $"{offset + 1} - {offset + listNodes.Count} of {nodesCount}" : "0"
            };

            return(result);
        }
Esempio n. 4
0
        // Returns the list of blocks on given page, from cache
        public BlocksData Blocks(int page, int limit)
        {
            if (limit < 10 || limit > 100)
            {
                limit = 25;
            }
            if (page <= 0)
            {
                page = 1;            // Page
            }
            var lastBlock = _indexService.GetIndexData(Net).LastBlockData.LastBlock;
            var lastPage  = ConvUtils.GetNumPages(IndexService.SizeOutAll, limit);

            // Get the list of cached blocks, from given page (we cache last 100K blocks)
            var blocks = _indexService.GetPools(Net, (page - 1) * limit, limit);

            // Prepare all data for page and return
            var result = new BlocksData
            {
                Page         = page,
                Blocks       = blocks,
                HaveNextPage = page < lastPage,
                LastPage     = lastPage,
                NumStr       = blocks.Any() ? $"{blocks.Last().Number} - {blocks.First().Number} of total {lastBlock}" : "-",
                LastBlock    = lastBlock
            };

            return(result);
        }
Esempio n. 5
0
        // Gets the list of token transfers by given account id, token id, and page,
        // 7zfr7JY5jyZuHZaTbWGBLdv1WVqHKz3nHgfZcTAjLVBY
        public object AccountTokenTransfers(string account, string token, int page, int limit)
        {
            if (limit < 10 || limit > 100)
            {
                limit = 25;
            }
            if (page <= 0)
            {
                page = 1;
            }

            using (var client = CreateApi())
            {
                // Get the list of transactions from the API
                var offset    = limit * (page - 1);
                var transfers = client.TokenWalletTransfersGet(Base58Encoding.Decode(token),
                                                               Base58Encoding.Decode(account), offset, limit);
                var lastPage = ConvUtils.GetNumPages(transfers.Count, limit);
                var count    = transfers.Transfers.Count;

                // Prepare the result
                return(new
                {
                    Page = page,
                    Transfers = transfers.Transfers.Select((t, i) => new TokenTransfer(t)).ToList(),
                    HaveNextPage = page < lastPage,
                    LastPage = lastPage,
                    NumStr = count > 0 ? $"{offset + 1} - {offset + count} of {offset + count}" : "-"
                });
            }
        }
Esempio n. 6
0
        // Returns the list of Tokens on given page (id), from API
        public object Tokens2(int page, int limit)
        {
            if (limit < 10 || limit > 100)
            {
                limit = 25;
            }
            if (page <= 0)
            {
                page = 1;            // Page
            }
            var offset = (page - 1) * limit;

            using (var client = CreateApi())
            {
                var tokensListResult = client.TokensListGet(offset, limit);
                var tokens           = tokensListResult.Tokens.Select((t, i) => new TokenInfo2(t)).ToList();
                var lastPage         = ConvUtils.GetNumPages(tokensListResult.Count, limit);

                // Prepare all data for page and return
                return(new
                {
                    Tokens = tokens,
                    Page = page,
                    HaveNextPage = page < lastPage,
                    LastPage = lastPage,
                    NumStr = tokens.Count > 0 ? $"{(page - 1) * limit + 1} - {(page - 1) * limit + tokens.Count} of {tokensListResult.Count}" : "-"
                });
            }
        }
Esempio n. 7
0
        // Gets the list of holders by given token id, and page,
        public object TokenHolders(string id, int page, int limit)
        {
            if (limit < 10 || limit > 100)
            {
                limit = 25;
            }
            if (page <= 0)
            {
                page = 1;
            }

            using (var client = CreateApi())
            {
                // Get the list of holders from the API
                var offset   = limit * (page - 1);
                var holders  = client.TokenHoldersGet(Base58Encoding.Decode(id), offset, limit);
                var lastPage = ConvUtils.GetNumPages(holders.Count, limit);
                var count    = holders.Holders.Count;

                // Prepare the result
                return(new
                {
                    Page = page,
                    Holders = holders.Holders.Select((t, i) => new TokenHolder(t)).ToList(),
                    HaveNextPage = page < lastPage,
                    LastPage = lastPage,
                    NumStr = count > 0 ? $"{offset + 1} - {offset + count} of {offset + count}" : "-"
                });
            }
        }
Esempio n. 8
0
        // Returns the list of Tokens on given page (id), from db
        public object Tokens(int page, int limit)
        {
            if (limit < 10 || limit > 100)
            {
                limit = 25;
            }
            if (page <= 0)
            {
                page = 1;            // Page
            }
            using (var db = CsmonDbContext.Create())
            {
                var tokensCount = db.Tokens.Count();
                var lastPage    = ConvUtils.GetNumPages(tokensCount, limit);

                var tokens = db.Tokens.Skip((page - 1) * limit).Take(limit).ToList();
                // Prepare all data for page and return
                var result = new
                {
                    Tokens       = tokens,
                    Page         = page,
                    HaveNextPage = page < lastPage,
                    LastPage     = lastPage,
                    NumStr       = tokensCount > 0 ? $"{(page - 1) * limit + 1} - {(page - 1) * limit + tokens.Count} of {tokensCount}" : "-"
                };

                for (var i = 1; i <= result.Tokens.Count; i++)
                {
                    result.Tokens[i - 1].Index = i + (page - 1) * limit;
                }

                return(result);
            }
        }
Esempio n. 9
0
        // Returns the list of Accounts on given page, from cache
        public object Accounts(int page, int limit, int sort)
        {
            if (limit < 10 || limit > 100)
            {
                limit = 25;
            }
            if (page <= 0)
            {
                page = 1;            // Page
            }
            using (var client = CreateApi())
            {
                // Get the list accounts
                var accounts = client.WalletsGet(0, long.MaxValue, (sbyte)(sort / 2), sort % 2 > 0);

                var lastPage = ConvUtils.GetNumPages(accounts.Wallets.Count, limit);

                var accountsLimited = accounts.Wallets.Skip((page - 1) * limit).Take(limit)
                                      .Select(w => new AccountData(w)).ToList();

                // Prepare all data for page and return
                return(new
                {
                    Accounts = accountsLimited,
                    Page = page,
                    HaveNextPage = page < lastPage,
                    LastPage = lastPage,
                    NumStr = accounts.Wallets.Any() ? $"{(page - 1) * limit + 1} - {(page-1)*limit + accountsLimited.Count} of total {accounts.Wallets.Count}" : "-"
                });
            }
        }
Esempio n. 10
0
        // Returns the list of txs on given page, from cache
        public TransactionsData Txs(int page, int limit)
        {
            if (limit < 10 || limit > 100)
            {
                limit = 25;
            }
            if (page <= 0)
            {
                page = 1;            // Page
            }
            // Get the list of cached blocks, from given page (we cache last 100K blocks)
            var txs = _indexService.GetTxs(Net, (page - 1) * limit, limit);

            // Prepare all data for page and return
            var offset   = limit * (page - 1);
            var stats    = _indexService.GetStatData(Net);
            var lastPage = ConvUtils.GetNumPages(IndexService.SizeOutAll, limit);

            var result = new TransactionsData
            {
                Page         = page,
                Transactions = txs,
                HaveNextPage = page < lastPage,
                LastPage     = lastPage,
                NumStr       = txs.Any() ? $"{offset + 1} - {offset + txs.Count} of {stats.Total.AllTransactions.Value}" : "-",
                TxCount      = stats.Total.AllTransactions.Value
            };

            return(result);
        }
Esempio n. 11
0
        // Gets pool transactions from API by given block hash, page
        // txcount is for making a label
        public TransactionsData PoolTransactions(string hash, int page, int limit, int txcount)
        {
            if (limit < 10 || limit > 100)
            {
                limit = 25;
            }
            if (page <= 0)
            {
                page = 1;
            }

            using (var client = CreateApi())
            {
                // Calculate last page
                var lastPage = ConvUtils.GetNumPages(txcount, limit);
                if (page > lastPage)
                {
                    page = lastPage;
                }

                // Prepare result
                var result = new TransactionsData
                {
                    Page         = page,
                    LastPage     = lastPage,
                    HaveNextPage = page < lastPage
                };

                // Get the list of transactions from API
                var offset = limit * (page - 1);
                var poolTr = client.PoolTransactionsGet(ConvUtils.ConvertHashBack(hash), offset, limit);
                var i      = offset + 1;

                // Fill result with transactions
                foreach (var t in poolTr.Transactions)
                {
                    var tInfo = new TransactionInfo(i, t.Id, t.Trxn);
                    result.Transactions.Add(tInfo);
                    i++;
                }

                // Make label that above transactions table, it's simpler to make it here, and return the result
                result.NumStr = poolTr.Transactions.Any() ? $"{offset + 1} - {offset + poolTr.Transactions.Count} of {txcount}" : "0";
                return(result);
            }
        }
Esempio n. 12
0
        // 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"
                });
            }
        }
Esempio n. 13
0
        public LedgersData Ledgers(int id)
        {
            const int limit = 100;

            if (id <= 0)
            {
                id = 1;
            }
            var ledgers  = _indexService.GetPools(Net, (id - 1) * limit, limit);
            var lastPage = ConvUtils.GetNumPages(IndexService.SizeOutAll, limit);
            var result   = new LedgersData
            {
                Page         = id,
                Ledgers      = ledgers,
                HaveNextPage = id < lastPage,
                LastPage     = lastPage,
                NumStr       = ledgers.Any() ? $"{ledgers.Last().Number} - {ledgers.First().Number}" : "-"
            };

            return(result);
        }