diff --git a/hiero-enterprise-base/src/main/java/org/hiero/base/data/ContractLog.java b/hiero-enterprise-base/src/main/java/org/hiero/base/data/ContractLog.java new file mode 100644 index 00000000..fa499e77 --- /dev/null +++ b/hiero-enterprise-base/src/main/java/org/hiero/base/data/ContractLog.java @@ -0,0 +1,34 @@ +package org.hiero.base.data; + +import com.hedera.hashgraph.sdk.ContractId; +import java.time.Instant; +import java.util.List; +import java.util.Objects; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; + +/** Represents a smart contract log/event emitted during a contract execution. */ +public record ContractLog( + @Nullable String address, + @Nullable String bloom, + @NonNull ContractId contractId, + @Nullable ContractId rootContractId, + @NonNull Instant consensusTimestamp, + @NonNull String data, + int index, + @NonNull List topics, + @NonNull String blockHash, + long blockNumber, + @NonNull String transactionHash, + int transactionIndex) { + + public ContractLog { + Objects.requireNonNull(contractId, "contractId must not be null"); + Objects.requireNonNull(consensusTimestamp, "consensusTimestamp must not be null"); + Objects.requireNonNull(data, "data must not be null"); + Objects.requireNonNull(topics, "topics must not be null"); + topics = List.copyOf(topics); + Objects.requireNonNull(blockHash, "blockHash must not be null"); + Objects.requireNonNull(transactionHash, "transactionHash must not be null"); + } +} diff --git a/hiero-enterprise-base/src/main/java/org/hiero/base/mirrornode/ContractLogRepository.java b/hiero-enterprise-base/src/main/java/org/hiero/base/mirrornode/ContractLogRepository.java new file mode 100644 index 00000000..aa615c6b --- /dev/null +++ b/hiero-enterprise-base/src/main/java/org/hiero/base/mirrornode/ContractLogRepository.java @@ -0,0 +1,24 @@ +package org.hiero.base.mirrornode; + +import com.hedera.hashgraph.sdk.ContractId; +import java.util.Objects; +import org.hiero.base.HieroException; +import org.hiero.base.data.ContractLog; +import org.hiero.base.data.Page; +import org.jspecify.annotations.NonNull; + +/** + * Repository for querying smart contract logs (events) from a Hiero network. This provides an + * easy-to-use API for observing events emitted by deployed smart contracts via the Hiero Mirror + * Node. + */ +public interface ContractLogRepository { + + @NonNull Page findByContractId(@NonNull ContractId contractId) throws HieroException; + + @NonNull + default Page findByContractId(@NonNull String contractId) throws HieroException { + Objects.requireNonNull(contractId, "contractId must not be null"); + return findByContractId(ContractId.fromString(contractId)); + } +}