public void UpdateBloom_Test()
        {
            var transactionResult = new TransactionResult();

            transactionResult.UpdateBloom();
            transactionResult.Bloom.ShouldBe(ByteString.Empty);

            var logEvent1 = new LogEvent
            {
                Address = SampleAddress.AddressList[0],
                Name    = "LogEvent1"
            };
            var logEvent2 = new LogEvent
            {
                Address = SampleAddress.AddressList[1],
                Name    = "LogEvent2"
            };

            transactionResult.Logs.Add(new[] { logEvent1, logEvent2 });
            transactionResult.UpdateBloom();
            var bloom = new Bloom();

            bloom.Combine(new List <Bloom> {
                logEvent1.GetBloom(), logEvent2.GetBloom()
            });
            transactionResult.Bloom.ShouldBe(ByteString.CopyFrom(bloom.Data));
        }
        public static void UpdateBloom(this TransactionResult transactionResult)
        {
            var bloom = new Bloom();

            bloom.Combine(transactionResult.Logs.Select(l => l.GetBloom()));
            transactionResult.Bloom = ByteString.CopyFrom(bloom.Data);
        }
Esempio n. 3
0
        public async Task <Block> AttachBlock(long previousBlockHeight, Hash previousBlockHash,
                                              List <Transaction> transactions = null, List <TransactionResult> transactionResults = null)
        {
            if (transactions == null || transactions.Count == 0)
            {
                transactions = new List <Transaction>();
            }

            if (transactions.Count == 0)
            {
                transactions.Add(GenerateTransaction());
            }

            if (transactionResults == null)
            {
                transactionResults = new List <TransactionResult>();
            }

            if (transactionResults.Count == 0)
            {
                foreach (var transaction in transactions)
                {
                    transactionResults.Add(GenerateTransactionResult(transaction, TransactionResultStatus.Mined));
                }
            }

            var newBlock = GenerateBlock(previousBlockHeight, previousBlockHash, transactions);

            var bloom = new Bloom();

            foreach (var transactionResult in transactionResults)
            {
                transactionResult.UpdateBloom();
                if (transactionResult.Status == TransactionResultStatus.Mined)
                {
                    bloom.Combine(new[] { new Bloom(transactionResult.Bloom.ToByteArray()) });
                }
            }

            newBlock.Header.Bloom = ByteString.CopyFrom(bloom.Data);

            foreach (var transactionResult in transactionResults)
            {
                await _transactionResultService.AddTransactionResultAsync(transactionResult, newBlock.Header);
            }

            await _blockchainService.AddBlockAsync(newBlock);

            await _blockchainService.AddTransactionsAsync(transactions);

            var chain = await _blockchainService.GetChainAsync();

            await _blockchainService.AttachBlockToChainAsync(chain, newBlock);

            return(newBlock);
        }
Esempio n. 4
0
        public static void UpdateBloom(this TransactionResult transactionResult)
        {
            // TODO: What should be the default value for bloom if there is no log
//            if (transactionResult.Logs.Count == 0)
//            {
//                return;
//            }
            var bloom = new Bloom();

            bloom.Combine(transactionResult.Logs.Select(l => l.GetBloom()));
            transactionResult.Bloom = ByteString.CopyFrom(bloom.Data);
        }