protected BlockBodiesMessage FulfillBlockBodiesRequest(GetBlockBodiesMessage getBlockBodiesMessage)
        {
            IReadOnlyList <Keccak> hashes = getBlockBodiesMessage.BlockHashes;

            Block[] blocks = new Block[hashes.Count];

            ulong sizeEstimate = 0;

            for (int i = 0; i < hashes.Count; i++)
            {
                blocks[i]     = SyncServer.Find(hashes[i]);
                sizeEstimate += MessageSizeEstimator.EstimateSize(blocks[i]);

                if (sizeEstimate > SoftOutgoingMessageSizeLimit)
                {
                    break;
                }
            }

            return(new BlockBodiesMessage(blocks));
        }
        protected ReceiptsMessage FulfillReceiptsRequest(GetReceiptsMessage getReceiptsMessage)
        {
            TxReceipt[][] txReceipts = new TxReceipt[getReceiptsMessage.Hashes.Count][];

            ulong sizeEstimate = 0;

            for (int i = 0; i < getReceiptsMessage.Hashes.Count; i++)
            {
                txReceipts[i] = SyncServer.GetReceipts(getReceiptsMessage.Hashes[i]);
                for (int j = 0; j < txReceipts[i].Length; j++)
                {
                    sizeEstimate += MessageSizeEstimator.EstimateSize(txReceipts[i][j]);
                }

                if (sizeEstimate > SoftOutgoingMessageSizeLimit)
                {
                    break;
                }
            }

            return(new ReceiptsMessage(txReceipts));
        }
        public void Estimate_tx_receipt_size()
        {
            TxReceipt txReceipt = Build.A.Receipt.TestObject;

            MessageSizeEstimator.EstimateSize(txReceipt).Should().Be(256 + 32);
        }
        public void Estimate_tx_with_data_size()
        {
            Transaction tx = Build.A.Transaction.WithData(new byte[7]).TestObject;

            MessageSizeEstimator.EstimateSize(tx).Should().Be(107);
        }
        public void Estimate_tx_size()
        {
            Transaction tx = Build.A.Transaction.TestObject;

            MessageSizeEstimator.EstimateSize(tx).Should().Be(100);
        }
 public void Estimate_null_tx_size()
 {
     MessageSizeEstimator.EstimateSize((Transaction)null).Should().Be(0);
 }
 public void Estimate_null_block_size()
 {
     MessageSizeEstimator.EstimateSize((Block)null).Should().Be(0);
 }
        public void Estimate_block_size()
        {
            var block = Build.A.Block.WithTransactions(100, MuirGlacier.Instance).TestObject;

            MessageSizeEstimator.EstimateSize(block).Should().Be(10512);
        }
 public void Estimate_null_header_size()
 {
     MessageSizeEstimator.EstimateSize((BlockHeader)null).Should().Be(0);
 }
        public void Estimate_header_size()
        {
            var header = Build.A.BlockHeader.TestObject;

            MessageSizeEstimator.EstimateSize(header).Should().Be(512);
        }