use of org.aion.base.Bloom in project aion by aionnetwork.
the class BloomFilterTest method testContainsAddress.
@Test
public void testContainsAddress() {
AionAddress addr = AddressUtils.wrapAddress("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
Bloom bloom = BloomFilter.create(addr.toByteArray());
assertThat(BloomFilter.containsAddress(bloom, addr)).isTrue();
}
use of org.aion.base.Bloom in project aion by aionnetwork.
the class BloomFilterTest method testSimpleAddSearchBloom.
@Test
public void testSimpleAddSearchBloom() {
String input = "hello world";
Bloom bloom = BloomFilter.create(input.getBytes());
assertThat(BloomFilter.containsString(bloom, input)).isTrue();
}
use of org.aion.base.Bloom in project aion by aionnetwork.
the class BloomFilterTest method testContainsEvent2.
@Test
public void testContainsEvent2() {
String evt = "Created(uint128,address)";
byte[] someEvent = HashUtil.h256(evt.getBytes());
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.
// inelegant (distributing chain singleton ref. into here), tradeoff for efficiency and ease of
// impl.
// rationale: this way, we only retrieve logs from DB for transactions that the bloom
// filter gives a positive match for;
public boolean onBlock(Block blk, IAionBlockchain chain) {
if (matchBloom(new Bloom(blk.getLogBloom()))) {
int txIndex = 0;
for (AionTransaction txn : blk.getTransactionsList()) {
// The if condition checks the contract create and call transactions
if ((txn.getDestinationAddress() != null && matchesContractAddress(txn.getDestinationAddress().toByteArray())) || txn.isContractCreationTransaction()) {
// now that we know that our filter might match with some logs in this
// transaction, go ahead
// and retrieve the txReceipt from the chain
AionTxInfo txInfo = chain.getTransactionInfo(txn.getTransactionHash());
AionTxReceipt receipt = txInfo.getReceipt();
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, txn, logIndex, true)));
}
logIndex++;
}
}
}
txIndex++;
}
}
return true;
}
Aggregations