use of org.aion.base.Bloom in project aion by aionnetwork.
the class BlockUtil method calcLogBloom.
public static byte[] calcLogBloom(List<AionTxReceipt> receipts) {
Objects.requireNonNull(receipts);
if (receipts.isEmpty()) {
return new byte[Bloom.SIZE];
}
Bloom retBloomFilter = new Bloom();
for (AionTxReceipt receipt : receipts) {
retBloomFilter.or(receipt.getBloomFilter());
}
return retBloomFilter.getBloomFilterBytes();
}
use of org.aion.base.Bloom in project aion by aionnetwork.
the class BloomFilterTest method testCompositeBloomFiltering.
@Test
public void testCompositeBloomFiltering() {
AionAddress addr = AddressUtils.wrapAddress("BEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEFFFF");
byte[] someEvent = HashUtil.h256(BigInteger.ONE.toByteArray());
byte[] anotherEvent = HashUtil.h256(BigInteger.TWO.toByteArray());
Bloom bloom = BloomFilter.create(addr.toByteArray(), someEvent, anotherEvent);
assertThat(BloomFilter.containsAddress(bloom, addr)).isTrue();
assertThat(BloomFilter.containsEvent(bloom, someEvent)).isTrue();
// test filtering composite
Bloom compositeTargetBloom = BloomFilter.create(someEvent, anotherEvent);
assertThat(BloomFilter.contains(bloom, compositeTargetBloom)).isTrue();
}
use of org.aion.base.Bloom in project aion by aionnetwork.
the class BloomFilterTest method testContainsEvent.
@Test
public void testContainsEvent() {
byte[] someEvent = HashUtil.h256(BigInteger.TEN.toByteArray());
Bloom bloom = BloomFilter.create(someEvent);
assertThat(BloomFilter.containsEvent(bloom, someEvent)).isTrue();
}
use of org.aion.base.Bloom in project aion by aionnetwork.
the class FltrLg method onBlock.
// -------------------------------------------------------------------------------
@Override
public boolean onBlock(BlockSummary bs) {
List<AionTxReceipt> receipts = ((AionBlockSummary) bs).getReceipts();
Block blk = bs.getBlock();
if (matchBloom(new Bloom(blk.getLogBloom()))) {
int txIndex = 0;
for (AionTxReceipt receipt : receipts) {
AionTransaction tx = receipt.getTransaction();
// The if condition checks the contract create and call transactions
if ((tx.getDestinationAddress() != null && matchesContractAddress(tx.getDestinationAddress().toByteArray())) || tx.isContractCreationTransaction()) {
if (matchBloom(receipt.getBloomFilter())) {
int logIndex = 0;
for (Log logInfo : receipt.getLogInfoList()) {
if (matchBloom(LogUtility.createBloomFilterForLog(logInfo)) && matchesExactly(logInfo)) {
add(new EvtLg(new TxRecptLg(logInfo, blk, txIndex, receipt.getTransaction(), logIndex, true)));
}
logIndex++;
}
}
}
txIndex++;
}
}
return true;
}
use of org.aion.base.Bloom in project aion by aionnetwork.
the class FltrLg method initBlooms.
// -------------------------------------------------------------------------------
private void initBlooms() {
if (filterBlooms != null)
return;
List<byte[][]> addrAndTopics = new ArrayList<>(topics);
addrAndTopics.add(contractAddresses);
filterBlooms = new Bloom[addrAndTopics.size()][];
for (int i = 0; i < addrAndTopics.size(); i++) {
byte[][] orTopics = addrAndTopics.get(i);
if (orTopics == null || orTopics.length == 0) {
// always matches
filterBlooms[i] = new Bloom[] { new Bloom() };
} else {
filterBlooms[i] = new Bloom[orTopics.length];
for (int j = 0; j < orTopics.length; j++) {
filterBlooms[i][j] = BloomFilter.create(orTopics[j]);
}
}
}
}
Aggregations