Пример #1
0
        private BlockBase CreateAcceptAssetTransitionBlock(byte[] transactionKey, byte[] assetCommitment, byte[] blindingFactor, byte[] assetId, ulong tagId)
        {
            if (_clientState.IsConfidential())
            {
                return(null);
            }

            List <TransactionalOutcomingBlock> outcomingBlocks = _dataAccessService.GetOutcomingTransactionBlocks();

            List <TransactionalOutcomingBlock> acceptanceBlocks = outcomingBlocks?.Where(b => b.BlockType == BlockTypes.Transaction_AcceptAssetTransition).ToList();

            List <byte[]> assetIds = new List <byte[]>();
            List <ulong>  amounts  = new List <ulong>();

            if (acceptanceBlocks != null)
            {
                TransactionalOutcomingBlock outcomingBlock = acceptanceBlocks.OrderByDescending(b => b.Height).First();
                AcceptAssetTransitionBlock  acceptAsset    = (AcceptAssetTransitionBlock)_blockParsersRepositoriesRepository.
                                                             GetBlockParsersRepository(PacketType.Transactional).
                                                             GetInstance(BlockTypes.Transaction_AcceptAssetTransition).
                                                             Parse(outcomingBlock.Content);

                assetIds = new List <byte[]>(acceptAsset.AssetIds);
                amounts  = new List <ulong>(acceptAsset.AssetAmounts);
            }

            int index = assetIds.FindIndex(a => a.Equals32(assetId));

            if (index >= 0)
            {
                amounts[index]++;
            }
            else
            {
                assetIds.Add(assetId);
                amounts.Add(1);
            }

            AcceptAssetTransitionBlock block = new AcceptAssetTransitionBlock
            {
                AssetIds               = assetIds.ToArray(),
                AssetAmounts           = amounts.ToArray(),
                TagId                  = tagId,
                UptodateFunds          = 0,
                AcceptedTransactionKey = transactionKey,
                AcceptedCommitment     = assetCommitment,
                AcceptedBlindingFactor = blindingFactor,
                AcceptedAssetId        = assetId
            };

            FillHeightInfo(block);
            FillSyncData(block);
            FillRawData(block);

            return(block);
        }
Пример #2
0
        public void StoreOutcomingTransitionTransactionalBlock(ulong syncBlockHeight, ulong combinedRegistryBlockHeight, ulong blockHeight, ushort blockType, Span <byte> owner, ulong tagId, Span <byte> content, Span <byte> transactionKey, Span <byte> commitment, Span <byte> destinationKey)
        {
            TransactionalOutcomingBlock transactionalOutcomingBlock = new TransactionalOutcomingBlock
            {
                SyncBlockHeight             = syncBlockHeight,
                CombinedRegistryBlockHeight = combinedRegistryBlockHeight,
                Height        = blockHeight,
                BlockType     = blockType,
                TagId         = tagId,
                Content       = content.ToArray(),
                Owner         = GetOrAddIdentity(owner),
                Output        = GetOrAddUtxoOutput(tagId, commitment, destinationKey),
                ThisBlockHash = GetOrAddBlockHash(_hashCalculation.CalculateHash(content.ToArray())),
                IsTransition  = false
            };

            lock (_sync)
            {
                _dataContext.TransactionalOutcomingBlocks.Add(transactionalOutcomingBlock);
                _dataContext.SaveChanges();
            }
        }