public override void ReadWriteCore(CoinStream stream)
        {
            stream.ReadWrite(ref _BlockId);
            ulong indexes_size = (ulong)_Indices.Count;

            stream.ReadWriteAsVarInt(ref indexes_size);
            if (!stream.Serializing)
            {
                ulong i            = 0;
                ulong indicesCount = 0;
                while ((ulong)_Indices.Count < indexes_size)
                {
                    indicesCount = Math.Min(1000UL + (ulong)indicesCount, (ulong)indexes_size);
                    for (; i < indicesCount; i++)
                    {
                        ulong index = 0;
                        stream.ReadWriteAsVarInt(ref index);
                        if (index > Int32.MaxValue)
                        {
                            throw new FormatException("indexes overflowed 31-bits");
                        }
                        _Indices.Add((int)index);
                    }
                }

                int offset = 0;
                for (var ii = 0; ii < _Indices.Count; ii++)
                {
                    if ((ulong)(_Indices[ii]) + (ulong)(offset) > Int32.MaxValue)
                    {
                        throw new FormatException("indexes overflowed 31-bits");
                    }
                    _Indices[ii] = _Indices[ii] + offset;
                    offset       = _Indices[ii] + 1;
                }
            }
            else
            {
                for (var i = 0; i < _Indices.Count; i++)
                {
                    int index = _Indices[i] - (i == 0 ? 0 : (_Indices[i - 1] + 1));
                    stream.ReadWrite(ref index);
                }
            }
        }
Пример #2
0
        public override void ReadWriteCore(CoinStream stream)
        {
            stream.ReadWrite(ref _Header);
            stream.ReadWrite(ref _Nonce);

            var shorttxids_size = (uint)_ShortIds.Count;

            stream.ReadWriteAsVarInt(ref shorttxids_size);
            if (!stream.Serializing)
            {
                ulong i = 0;
                ulong shottxidsCount = 0;
                while (_ShortIds.Count < shorttxids_size)
                {
                    shottxidsCount = Math.Min(1000UL + (ulong)shottxidsCount, (ulong)shorttxids_size);
                    for (; i < shottxidsCount; i++)
                    {
                        uint   lsb = 0;
                        ushort msb = 0;
                        stream.ReadWrite(ref lsb);
                        stream.ReadWrite(ref msb);
                        _ShortIds.Add(((ulong)(msb) << 32) | (ulong)(lsb));
                    }
                }
            }
            else
            {
                for (var i = 0; i < _ShortIds.Count; i++)
                {
                    uint   lsb = (uint)(_ShortIds[i] & 0xffffffff);
                    ushort msb = (ushort)((_ShortIds[i] >> 32) & 0xffff);
                    stream.ReadWrite(ref lsb);
                    stream.ReadWrite(ref msb);
                }
            }

            ulong txn_size = (ulong)PrefilledTransactions.Count;

            stream.ReadWriteAsVarInt(ref txn_size);

            if (!stream.Serializing)
            {
                ulong i            = 0;
                ulong indicesCount = 0;
                while ((ulong)PrefilledTransactions.Count < txn_size)
                {
                    indicesCount = Math.Min(1000UL + (ulong)indicesCount, (ulong)txn_size);
                    for (; i < indicesCount; i++)
                    {
                        ulong index = 0;
                        stream.ReadWriteAsVarInt(ref index);
                        if (index > Int32.MaxValue)
                        {
                            throw new FormatException("indexes overflowed 32-bits");
                        }
                        Transaction tx = null;
                        stream.ReadWrite(ref tx);
                        PrefilledTransactions.Add(new PrefilledTransaction()
                        {
                            Index       = (int)index,
                            Transaction = tx
                        });
                    }
                }

                int offset = 0;
                for (var ii = 0; ii < PrefilledTransactions.Count; ii++)
                {
                    if ((ulong)(PrefilledTransactions[ii].Index) + (ulong)(offset) > Int32.MaxValue)
                    {
                        throw new FormatException("indexes overflowed 31-bits");
                    }
                    PrefilledTransactions[ii].Index = PrefilledTransactions[ii].Index + offset;
                    offset = PrefilledTransactions[ii].Index + 1;
                }
            }
            else
            {
                for (var i = 0; i < PrefilledTransactions.Count; i++)
                {
                    uint index = checked ((uint)(PrefilledTransactions[i].Index - (i == 0 ? 0 : (PrefilledTransactions[i - 1].Index + 1))));
                    stream.ReadWriteAsVarInt(ref index);
                    Transaction tx = PrefilledTransactions[i].Transaction;
                    stream.ReadWrite(ref tx);
                }
            }

            if (!stream.Serializing)
            {
                UpdateShortTxIDSelector();
            }
        }