Beispiel #1
0
        private ExtendedBlockInformation FetchExtendedBlockInformation(BlockFeature blockFeature, Block block)
        {
            var id           = block.Header.GetHash().ToString();
            var extendedInfo = Configuration.GetCacheTable <ExtendedBlockInformation>().ReadOne(id);

            if (extendedInfo != null)
            {
                return(extendedInfo);
            }
            ChainedBlock chainedBlock = blockFeature.GetChainedBlock(Chain);

            if (chainedBlock == null)
            {
                return(null);
            }
            if (block.Transactions.Count == 0)
            {
                block = GetBlock(blockFeature, false);
                if (block == null || block.Transactions.Count == 0)
                {
                    return(null);
                }
            }
            extendedInfo = new ExtendedBlockInformation()
            {
                BlockReward      = block.Transactions[0].TotalOut,
                BlockSubsidy     = GetBlockSubsidy(chainedBlock.Height),
                Size             = GetSize(block, TransactionOptions.All),
                StrippedSize     = GetSize(block, TransactionOptions.None),
                TransactionCount = block.Transactions.Count
            };
            Configuration.GetCacheTable <ExtendedBlockInformation>().Create(id, extendedInfo, true);
            return(extendedInfo);
        }
Beispiel #2
0
        private Block GetBlock(BlockFeature blockFeature, bool headerOnly)
        {
            var chainedBlock = blockFeature.GetChainedBlock(Chain);
            var hash         = chainedBlock == null ? blockFeature.BlockId : chainedBlock.HashBlock;

            if (hash == null)
            {
                return(null);
            }
            var client = Configuration.Indexer.CreateIndexerClient();

            return(headerOnly ? GetHeader(hash, client) : client.GetBlock(hash));
        }
Beispiel #3
0
        private ChainedBlock AtBlock(BlockFeature at)
        {
            var atBlock = Chain.Tip;

            if (at != null)
            {
                var chainedBlock = at.GetChainedBlock(Chain);
                if (chainedBlock == null)
                {
                    throw new FormatException("'at' not found in the blockchain");
                }
                atBlock = chainedBlock;
            }
            return(atBlock);
        }
Beispiel #4
0
        private Block GetBlock(BlockFeature blockFeature, bool headerOnly)
        {
            var chainedBlock = blockFeature.GetChainedBlock(Chain);
            var hash         = chainedBlock == null ? blockFeature.BlockId : chainedBlock.HashBlock;

            if (hash == null)
            {
                return(null);
            }
            if (chainedBlock != null && chainedBlock.Height == 0)
            {
                return(headerOnly ? new NBitcoin.Block(Network.GetGenesis().Header) : Network.GetGenesis());
            }
            var client = Configuration.Indexer.CreateIndexerClient();

            return(headerOnly ? GetHeader(hash, client) : client.GetBlock(hash));
        }