public byte[] Serialize(NewBlockMessage message)
        {
            int       contentLength = _blockDecoder.GetLength(message.Block, RlpBehaviors.None) + Rlp.LengthOf((UInt256)message.TotalDifficulty);
            int       totalLength   = Rlp.LengthOfSequence(contentLength);
            RlpStream rlpStream     = new RlpStream(totalLength);

            rlpStream.StartSequence(contentLength);
            rlpStream.Encode(message.Block);
            rlpStream.Encode(message.TotalDifficulty);
            return(rlpStream.Data);
        }
Ejemplo n.º 2
0
        public BlockForRpc(Block block, bool includeFullTransactionData)
        {
            _isAuRaBlock = block.Header.AuRaSignature != null;
            Author       = block.Author ?? block.Beneficiary;
            Difficulty   = block.Difficulty;
            ExtraData    = block.ExtraData;
            GasLimit     = block.GasLimit;
            GasUsed      = block.GasUsed;
            Hash         = block.Hash;
            LogsBloom    = block.Bloom;
            Miner        = block.Beneficiary;
            if (!_isAuRaBlock)
            {
                MixHash = block.MixHash;
                Nonce   = new byte[8];
                BinaryPrimitives.WriteUInt64BigEndian(Nonce, block.Nonce);
            }
            else
            {
                Step      = block.Header.AuRaStep;
                Signature = block.Header.AuRaSignature;
            }

            Number           = block.Number;
            ParentHash       = block.ParentHash;
            ReceiptsRoot     = block.ReceiptsRoot;
            Sha3Uncles       = block.OmmersHash;
            Size             = _blockDecoder.GetLength(block, RlpBehaviors.None);
            StateRoot        = block.StateRoot;
            Timestamp        = block.Timestamp;
            TotalDifficulty  = block.TotalDifficulty ?? 0;
            Transactions     = includeFullTransactionData ? block.Transactions.Select((t, idx) => new TransactionForRpc(block.Hash, block.Number, idx, t)).ToArray() : block.Transactions.Select(t => t.Hash).OfType <object>().ToArray();
            TransactionsRoot = block.TxRoot;
            Uncles           = block.Ommers.Select(o => o.Hash);
        }
Ejemplo n.º 3
0
        public byte[] Improved3()
        {
            int       length = _blockDecoder.GetLength(_block, RlpBehaviors.None);
            RlpStream stream = new RlpStream(length);

            _blockDecoder.Encode(stream, _block);
            return(Bytes.Empty);
        }
        public void Serialize(IByteBuffer byteBuffer, NewBlockMessage message)
        {
            int       contentLength = _blockDecoder.GetLength(message.Block, RlpBehaviors.None) + Rlp.LengthOf(message.TotalDifficulty);
            RlpStream rlpStream     = new NettyRlpStream(byteBuffer);

            int totalLength = Rlp.LengthOfSequence(contentLength);

            byteBuffer.EnsureWritable(totalLength, true);

            rlpStream.StartSequence(contentLength);
            rlpStream.Encode(message.Block);
            rlpStream.Encode(message.TotalDifficulty);
        }
Ejemplo n.º 5
0
        public BlockForRpc(Block block, bool includeFullTransactionData)
        {
            var isAuRaBlock = block.Header.AuRaSignature != null;

            Author     = block.Author;
            Difficulty = block.Difficulty;
            ExtraData  = block.ExtraData;
            GasLimit   = block.GasLimit;
            GasUsed    = block.GasUsed;
            Hash       = block.Hash;
            LogsBloom  = block.Bloom;
            Miner      = block.Beneficiary;
            if (!isAuRaBlock)
            {
                MixHash = block.MixHash;
                Nonce   = ((BigInteger)block.Nonce).ToBigEndianByteArray().PadLeft(8);
            }
            else
            {
                Step      = block.Header.AuRaStep;
                Signature = block.Header.AuRaSignature;
            }

            Number       = block.Number;
            ParentHash   = block.ParentHash;
            ReceiptsRoot = block.ReceiptsRoot;
            Sha3Uncles   = block.OmmersHash;
            Size         = _blockDecoder.GetLength(block, RlpBehaviors.None);
            StateRoot    = block.StateRoot;

            Timestamp       = block.Timestamp;
            TotalDifficulty = block.TotalDifficulty ?? 0;
            Transactions    = includeFullTransactionData
                ? block.Transactions.Select((t, idx) => { return(new TransactionForRpc(block.Hash, block.Number, idx, t)); }).ToArray()
                : (object[])block.Transactions.Select(t => t.Hash).AsEnumerable();

            TransactionsRoot = block.TransactionsRoot;
            Uncles           = block.Ommers.Select(o => o.Hash);
        }
Ejemplo n.º 6
0
        public void Get_length_null()
        {
            BlockDecoder decoder = new BlockDecoder();

            Assert.AreEqual(1, decoder.GetLength(null, RlpBehaviors.None));
        }