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); }
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 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); }
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); }
/// <summary> /// Checks if current bloom is contained in the input bloom. /// </summary> /// <param name="bloom">Other bloom</param> /// <returns></returns> public bool IsIn(Bloom bloom) { for (var i = 0; i < Length; i++) { var curByte = _data[i]; if ((curByte & bloom.Data[i]) != curByte) { return(false); } } return(true); }
public static Bloom GetBloom(this LogEvent logEvent) { var bloom = new Bloom(); bloom.AddValue(logEvent.Address); bloom.AddValue(logEvent.Name.GetBytes()); foreach (var t in logEvent.Indexed) { bloom.AddValue(t.ToByteArray()); } return(bloom); }
public void UpdateBloom() { var bloom = new Bloom(); foreach (var le in Logs) { bloom.AddValue(le.Address); foreach (var t in le.Topics) { bloom.AddValue(t.ToByteArray()); } } Bloom = ByteString.CopyFrom(bloom.Data); }
public Bloom(Bloom bloom) : this(bloom.Data) { }