Пример #1
0
        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);
            }
        }
Пример #2
0
        public TransactionsData PoolTransactions(string hash, int page)
        {
            if (page <= 0)
            {
                page = 1;
            }
            using (var client = CreateApi())
            {
                var result = new TransactionsData {
                    Page = page
                };
                const int numPerPage = 50;
                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, $"{hash}.{i}", t.Trxn);
                    result.Transactions.Add(tInfo);
                    i++;
                }

                return(result);
            }
        }
Пример #3
0
 public TransactionInfo TransactionInfo(string id)
 {
     using (var client = CreateApi())
     {
         var ids  = id.Split('.');
         var trId = new TransactionId()
         {
             Index    = int.Parse(ids[1]) - 1,
             PoolHash = ConvUtils.ConvertHashBack(ids[0])
         };
         var tr    = client.TransactionGet(trId);
         var tInfo = new TransactionInfo(0, null, tr.Transaction.Trxn)
         {
             Id = id, Found = tr.Found
         };
         if (!tr.Found)
         {
             return(tInfo);
         }
         if (string.IsNullOrEmpty(tInfo.PoolHash))
         {
             return(tInfo);
         }
         var pool = client.PoolInfoGet(ConvUtils.ConvertHashBack(tInfo.PoolHash), 0);
         tInfo.Time = ConvUtils.UnixTimeStampToDateTime(pool.Pool.Time);
         return(tInfo);
     }
 }
Пример #4
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);
            }
        }
Пример #5
0
 public DateTime GetTransactionTime(string id)
 {
     using (var client = CreateApi())
     {
         var poolHash = id.Split(".")[0];
         var pool     = client.PoolInfoGet(ConvUtils.ConvertHashBack(poolHash), 0);
         return(ConvUtils.UnixTimeStampToDateTime(pool.Pool.Time));
     }
 }
Пример #6
0
        // Gets transaction time by transaction id
        public DateTime GetTransactionTime(string id)
        {
            using (var client = CreateApi())
            {
                // Extract block hash from transaction id
                var poolHash = id.Split(".")[0];

                // Get block data from API
                var pool = client.PoolInfoGet(ConvUtils.ConvertHashBack(poolHash), 0);

                // Return block time - this is also a transaction time
                return(ConvUtils.UnixTimeStampToDateTime(pool.Pool.Time));
            }
        }
Пример #7
0
        public TransactionsData PoolData(string id)
        {
            using (var client = CreateApi())
            {
                var poolHash = ConvUtils.ConvertHashBack(id);
                var pool     = client.PoolInfoGet(poolHash, 0);

                var result = new TransactionsData
                {
                    Page  = 1,
                    Found = pool.IsFound,
                    Info  = new PoolInfo(pool.Pool)
                };
                return(result);
            }
        }
Пример #8
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);
            }
        }
Пример #9
0
        // Gets block data from API by given hash (id)
        public TransactionsData PoolData(string id)
        {
            using (var client = CreateApi())
            {
                // Get data from node
                var poolHash = ConvUtils.ConvertHashBack(id);
                var pool     = client.PoolInfoGet(poolHash, 0);

                // Prepare and return result
                var result = new TransactionsData
                {
                    Page  = 1,
                    Found = pool.IsFound,
                    Info  = new BlockInfo(pool.Pool)
                };
                return(result);
            }
        }
Пример #10
0
        // Gets transaction data from API by given transaction id
        public TransactionInfo TransactionInfo(string id)
        {
            using (var client = CreateApi())
            {
                // Prepare transaction id for request
                var ids  = id.Split('.');
                var trId = new TransactionId()
                {
                    Index    = int.Parse(ids[1]) - 1,
                    PoolHash = ConvUtils.ConvertHashBack(ids[0])
                };

                // Get data from API
                var tr = client.TransactionGet(trId);

                // Prepare the result
                var tInfo = new TransactionInfo(0, null, tr.Transaction.Trxn)
                {
                    Id = id, Found = tr.Found
                };

                // if transaction was not found, return the result
                if (!tr.Found)
                {
                    return(tInfo);
                }

                // Otherwise, request block data and store block time in the result
                if (string.IsNullOrEmpty(tInfo.PoolHash))
                {
                    return(tInfo);
                }
                var pool = client.PoolInfoGet(ConvUtils.ConvertHashBack(tInfo.PoolHash), 0);
                tInfo.Time = ConvUtils.UnixTimeStampToDateTime(pool.Pool.Time);

                // return the result
                return(tInfo);
            }
        }