Ejemplo n.º 1
0
        public TransactionalBlock GetLastTransactionalBlock(TransactionalIdentity transactionalIdentity)
        {
            if (transactionalIdentity == null)
            {
                throw new ArgumentNullException(nameof(transactionalIdentity));
            }

            lock (_sync)
            {
                return(_dataContext.TransactionalBlocks.Where(b => b.Identity == transactionalIdentity).OrderByDescending(b => b.BlockHeight).FirstOrDefault());
            }
        }
Ejemplo n.º 2
0
        public TransactionalIdentity AddTransactionalIdentity(AccountIdentity accountIdentity)
        {
            lock (_sync)
            {
                TransactionalIdentity transactionalIdentity = new TransactionalIdentity
                {
                    Identity = accountIdentity
                };

                _dataContext.TransactionalIdentities.Add(transactionalIdentity);

                return(transactionalIdentity);
            }
        }
Ejemplo n.º 3
0
        public TransactionalBlock GetLastTransactionalBlock(AccountIdentity accountIdentity)
        {
            TransactionalBlock transactionalBlock = null;

            if (accountIdentity == null)
            {
                throw new ArgumentNullException(nameof(accountIdentity));
            }

            TransactionalIdentity transactionalIdentity = GetTransactionalIdentity(accountIdentity);

            if (transactionalIdentity != null)
            {
                transactionalBlock = GetLastTransactionalBlock(transactionalIdentity);
            }

            return(transactionalBlock);
        }
Ejemplo n.º 4
0
        public void AddTransactionalBlock(IKey key, ulong syncBlockHeight, ushort blockType, ulong blockHeight, byte[] blockContent)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            if (blockContent == null)
            {
                throw new ArgumentNullException(nameof(blockContent));
            }

            TransactionalIdentity transactionalIdentity = GetTransactionalIdentity(key);

            if (transactionalIdentity == null)
            {
                AccountIdentity accountIdentity = GetOrAddIdentity(key);
                transactionalIdentity = AddTransactionalIdentity(accountIdentity);
            }

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

            TransactionalBlock transactionalBlock = new TransactionalBlock()
            {
                Identity        = transactionalIdentity,
                HashKey         = blockHashKey,
                SyncBlockHeight = syncBlockHeight,
                BlockContent    = blockContent,
                BlockHeight     = blockHeight,
                BlockType       = blockType
            };

            lock (_sync)
            {
                _dataContext.BlockHashKeys.Add(blockHashKey);
                _dataContext.TransactionalBlocks.Add(transactionalBlock);
            }
        }