Search in sources :

Example 1 with BytesKey

use of com.hedera.services.utils.BytesKey in project hedera-services by hashgraph.

the class CodeCache method getIfPresent.

public Code getIfPresent(final Address address) {
    final var cacheKey = new BytesKey(address.toArray());
    var code = cache.getIfPresent(cacheKey);
    if (code == null) {
        final var bytecode = entityAccess.fetchCodeIfPresent(accountIdFromEvmAddress(address));
        if (bytecode != null) {
            code = new Code(bytecode, Hash.hash(bytecode));
            cache.put(cacheKey, code);
        }
    }
    return code;
}
Also used : BytesKey(com.hedera.services.utils.BytesKey) Code(org.hyperledger.besu.evm.Code)

Example 2 with BytesKey

use of com.hedera.services.utils.BytesKey in project hedera-services by hashgraph.

the class CodeCacheTest method bytesKeyEquals.

@Test
void bytesKeyEquals() {
    BytesKey key1 = new BytesKey("abc".getBytes());
    BytesKey key2 = new BytesKey("abc".getBytes());
    assertEquals(key1, key2);
    assertEquals(key1, key1);
    // Workaround to sonar code-smells. It should NOT be an error to use assertTrue/assertFalse.
    boolean eq1 = key1.equals(null);
    boolean eq2 = key1.equals("abc");
    assertEquals(eq1, eq2);
}
Also used : BytesKey(com.hedera.services.utils.BytesKey) Test(org.junit.jupiter.api.Test)

Aggregations

BytesKey (com.hedera.services.utils.BytesKey)2 Code (org.hyperledger.besu.evm.Code)1 Test (org.junit.jupiter.api.Test)1