From 51023e9baf0613e2abe4b6a7668f3fe4a40bca11 Mon Sep 17 00:00:00 2001 From: Twiineenock Date: Thu, 23 Apr 2026 09:19:20 +0300 Subject: [PATCH] feat: Add ContractLog data model and repository interface This commit introduces the core data model (ContractLog) and the ContractLogRepository interface to support querying smart contract events from the Hiero Mirror Node. This establishes the public API surface for the feature, and is aligned strictly with the Hedera Mirror Node REST API JSON responses. Signed-off-by: Twiineenock --- .../java/org/hiero/base/data/ContractLog.java | 34 +++++++++++++++++++ .../mirrornode/ContractLogRepository.java | 24 +++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 hiero-enterprise-base/src/main/java/org/hiero/base/data/ContractLog.java create mode 100644 hiero-enterprise-base/src/main/java/org/hiero/base/mirrornode/ContractLogRepository.java 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)); + } +}