BitSharp.Core.DataDecoder.DecodeBlock C# (CSharp) Method

DecodeBlock() public static method

public static DecodeBlock ( BinaryReader reader ) : BitSharp.Core.Domain.Block
reader System.IO.BinaryReader
return BitSharp.Core.Domain.Block
        public static Block DecodeBlock(BinaryReader reader)
        {
            var header = DecodeBlockHeader(null, reader.ReadExactly(80));

            var blockTxesCount = reader.ReadVarInt().ToIntChecked();
            var blockTxes = ImmutableArray.CreateBuilder<BlockTx>(blockTxesCount);
            for (var i = 0; i < blockTxesCount; i++)
            {
                var txBytes = ReadTransaction(reader);
                var encodedTx = DecodeEncodedTx(null, txBytes);
                var blockTx = new BlockTx(i, encodedTx);

                blockTxes.Add(blockTx);

            }

            return new Block(header, blockTxes.MoveToImmutable());
        }

Same methods

DataDecoder::DecodeBlock ( UInt256 blockHash, byte buffer, int offset ) : BitSharp.Core.Domain.Block

Usage Example

Example #1
0
        private Block GetEntry(string name)
        {
            Block block;

            if (blocks.TryGetValue(name, out block))
            {
                return(block);
            }

            var entry = zip.GetEntry(name);

            if (entry == null)
            {
                return(null);
            }

            using (var blockStream = entry.Open())
                using (var blockReader = new BinaryReader(blockStream))
                {
                    block = DataDecoder.DecodeBlock(blockReader);
                }

            blocks[name] = block;

            return(block);
        }