Example #1
0
        public BlockBase Get(IDataKey key)
        {
            if (key is SyncHashKey syncHashKey)
            {
                UtxoConfidentialBlock utxoConfidential = DataAccessService.Instance.GetUtxoConfidentialBySyncAndHash(syncHashKey.SyncBlockHeight, syncHashKey.Hash);

                return _mapperFactory.GetInstance<UtxoConfidentialBlock, BlockBase>().Translate(utxoConfidential);
            }

            return null;
        }
Example #2
0
        public PacketBase Get(IDataKey key)
        {
            if (key is SyncHashKey syncHashKey)
            {
                UtxoConfidentialBlock utxoConfidential = DataAccessService.Instance.GetUtxoConfidentialBySyncAndHash(syncHashKey.SyncBlockHeight, syncHashKey.Hash);

                if (utxoConfidential != null)
                {
                    return(_mapperFactory.GetInstance <UtxoConfidentialBlock, PacketBase>().Translate(utxoConfidential));
                }
            }

            return(null);
        }
Example #3
0
        public UtxoConfidentialBlock GetUtxoConfidentialBySyncAndHash(ulong syncBlockHeight, Memory <byte> hash)
        {
            IEnumerable <BlockHashKey> blockHashKeys = _dataContext.BlockHashKeys.Where(b => b.SyncBlockHeight == syncBlockHeight);

            foreach (BlockHashKey item in blockHashKeys)
            {
                ArraySegment <byte> arraySegment = hash.ToArraySegment();

                if (item.Hash.Equals32(arraySegment.Array, arraySegment.Offset, 32))
                {
                    UtxoConfidentialBlock utxoConfidentialBlock = _dataContext.UtxoConfidentialBlocks.FirstOrDefault(b => b.HashKey.BlockHashKeyId == item.BlockHashKeyId);

                    return(utxoConfidentialBlock);
                }
            }

            return(null);
        }
Example #4
0
        public bool AddUtxoConfidentialBlock(IKey keyImage, ulong syncBlockHeight, ushort blockType, byte[] destinationKey, byte[] blockContent)
        {
            if (_keyImages.Contains(keyImage))
            {
                return(false);
            }

            _keyImages.Add(keyImage);

            lock (_sync)
            {
                UtxoConfidentialKeyImage utxoConfidentialKeyImage = new UtxoConfidentialKeyImage {
                    KeyImage = keyImage.Value.ToArray()
                };

                BlockHashKey blockHashKey = new BlockHashKey
                {
                    SyncBlockHeight = syncBlockHeight,
                    Hash            = _defaultHashCalculation.CalculateHash(blockContent)
                };

                UtxoConfidentialBlock utxoConfidentialBlock = new UtxoConfidentialBlock
                {
                    KeyImage        = utxoConfidentialKeyImage,
                    HashKey         = blockHashKey,
                    SyncBlockHeight = syncBlockHeight,
                    BlockType       = blockType,
                    DestinationKey  = destinationKey,
                    BlockContent    = blockContent
                };

                _dataContext.UtxoConfidentialKeyImages.Add(utxoConfidentialKeyImage);
                _dataContext.BlockHashKeys.Add(blockHashKey);
                _dataContext.UtxoConfidentialBlocks.Add(utxoConfidentialBlock);
            }

            return(true);
        }