Search in sources :

Example 11 with Bloom

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();
}
Also used : AionAddress(org.aion.types.AionAddress) Bloom(org.aion.base.Bloom) Test(org.junit.Test) BlockchainIntegrationTest(org.aion.zero.impl.blockchain.BlockchainIntegrationTest)

Example 12 with Bloom

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();
}
Also used : Bloom(org.aion.base.Bloom) Test(org.junit.Test) BlockchainIntegrationTest(org.aion.zero.impl.blockchain.BlockchainIntegrationTest)

Example 13 with Bloom

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();
}
Also used : Bloom(org.aion.base.Bloom) Test(org.junit.Test) BlockchainIntegrationTest(org.aion.zero.impl.blockchain.BlockchainIntegrationTest)

Example 14 with Bloom

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;
}
Also used : AionTxInfo(org.aion.zero.impl.types.AionTxInfo) Log(org.aion.types.Log) Bloom(org.aion.base.Bloom) AionTransaction(org.aion.base.AionTransaction) AionTxReceipt(org.aion.base.AionTxReceipt)

Aggregations

Bloom (org.aion.base.Bloom)14 Test (org.junit.Test)9 AionTxReceipt (org.aion.base.AionTxReceipt)8 ArrayList (java.util.ArrayList)5 AionTxExecSummary (org.aion.base.AionTxExecSummary)5 BlockchainIntegrationTest (org.aion.zero.impl.blockchain.BlockchainIntegrationTest)5 AionTransaction (org.aion.base.AionTransaction)2 AionAddress (org.aion.types.AionAddress)2 Log (org.aion.types.Log)2 BigInteger (java.math.BigInteger)1 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)1 AionTxInfo (org.aion.zero.impl.types.AionTxInfo)1 Block (org.aion.zero.impl.types.Block)1 RetValidPreBlock (org.aion.zero.impl.types.RetValidPreBlock)1