public void Add(BlockChip blockChip)
        {
            if (isReadOnly && writeCount == 0)
            {
                return;
            }

            Interlocked.Increment(ref writeCount);
            try {
                if (blockChip.RestoreCount != RestoreCount)
                {
                    goto Invalid;
                }
                if (blockChip.TotalCount != TotalCount)
                {
                    goto Invalid;
                }
                if (blockChip.Data.Length != ChipDataBytes)
                {
                    goto Invalid;
                }
                if (blockChip.BlockBytes != BlockBytes)
                {
                    goto Invalid;
                }
                if (datas[blockChip.Index] is not null)
                {
                    goto Invalid;
                }
                if (blockChip.Verify(PublicKey) is false)
                {
                    goto Invalid;
                }

                datas[blockChip.Index] = blockChip.Data;
                if (Interlocked.Increment(ref count) == RestoreCount)
                {
                    CanRestore = true;
                }
                return;
            } finally {
                if (Interlocked.Decrement(ref writeCount) == 0 && CanRestore)
                {
                    isReadOnly = true;
                    restoreTaskSource.TrySetResult(null);
                }
            }

            Invalid:
            throw new InvalidBlockChipException();
        }
        public BlockChipCollection(BlockChip firstChip, Bytes <Address> address, PublicKey publicKey)
        {
            Id                     = firstChip.Id;
            TotalCount             = firstChip.TotalCount;
            RestoreCount           = firstChip.RestoreCount;
            datas                  = new byte[]?[TotalCount];
            datas[firstChip.Index] = firstChip.Data;
            ChipDataBytes          = firstChip.Data.Length;
            BlockBytes             = firstChip.BlockBytes;

            if (firstChip.Verify(publicKey) is false)
            {
                throw new InvalidBlockChipException();
            }

            Address   = address;
            PublicKey = publicKey;

            count = 1;
        }
示例#3
0
        public void Add(BlockChip blockChip)
        {
            if (isReadOnly && writeCount == 0)
            {
                return;
            }

            Interlocked.Increment(ref writeCount);
            try {
                if (blockChip.RestoreCount != RestoreCount)
                {
                    goto Invalid;
                }
                if (blockChip.TotalCount != TotalCount)
                {
                    goto Invalid;
                }
                if (blockChip.Data.Length != ChipDataBytes)
                {
                    goto Invalid;
                }
                if (blockChip.BlockBytes != BlockBytes)
                {
                    goto Invalid;
                }
                if (datas[blockChip.Index] is { })
                {
                    goto Invalid;
                }
                if (blockChip.Verify(PublicKey) is false)
                {
                    goto Invalid;
                }

                datas[blockChip.Index] = blockChip.Data;
                if (Interlocked.Increment(ref count) == RestoreCount)
                {
                    CanRestore = true;
                }
                return;
            } finally {