Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions hiero-enterprise-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
<groupId>com.hedera.hashgraph</groupId>
<artifactId>sdk</artifactId>
</dependency>
<dependency>
<groupId>com.open-elements.solidity</groupId>
<artifactId>abi-parser</artifactId>
</dependency>
<dependency>
<groupId>org.web3j</groupId>
<artifactId>abi</artifactId>
</dependency>
<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>dotenv-java</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.openelements.hiero.base.data;

import com.hedera.hashgraph.sdk.ContractId;
import com.openelements.hiero.smartcontract.abi.model.AbiParameterType;
import java.util.List;
import java.util.Objects;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

public record ContractEventInstance(@NonNull ContractId contractId, @Nullable String eventName,
@NonNull List<ParameterInstance> parameters) {

public ContractEventInstance {
Objects.requireNonNull(contractId, "contractId must be provided");
Objects.requireNonNull(parameters, "parameters must be provided");
}

public record ParameterInstance(@NonNull String name, @NonNull AbiParameterType type, @NonNull byte[] value) {

public ParameterInstance {
Objects.requireNonNull(name, "name must be provided");
Objects.requireNonNull(type, "type must be provided");
Objects.requireNonNull(value, "value must be provided");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.openelements.hiero.base.data;

import com.hedera.hashgraph.sdk.ContractId;
import com.openelements.hiero.base.solidity.SolidityTools;
import com.openelements.hiero.smartcontract.abi.model.AbiEvent;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Objects;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

/**
* Represents a log entry for a contract.
*
* @param address The hex encoded EVM address of the contract. example:
* {@code 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef} - pattern:
* {@code ^0x[0-9A-Fa-f]{40}$}
* @param bloom The hex encoded bloom filter of the contract log. example:
* {@code 0x549358c4c2e573e02410ef7b5a5ffa5f36dd7398}
* @param contractId Network entity ID in the format of shard.realm.num example: {@code 0.0.1234}
* @param data The hex encoded data of the contract log - example:
* {@code 0x00000000000000000000000000000000000000000000000000000000000000fa}
* @param index The index of the contract log in the chain of logs for an execution
* @param topics A list of hex encoded topics associated with this log event. example:
* {@code List [ "0xf4757a49b326036464bec6fe419a4ae38c8a02ce3e68bf0809674f6aab8ad300" ]}
* @param block_hash The hex encoded block (record file chain) hash. example:
* {@code
* 0x553f9311833391c0a3b2f9ed64540a89f2190a511986cd94889f1c0cf7fa63e898b1c6730f14a61755d1fb4ca05fb073}
* @param blockNumber The block height calculated as the number of record files starting from zero since network
* start.
* @param rootContractId The executed contract that created this contract log. pattern:
* {@code ^\d{1,10}\.\d{1,10}\.\d{1,10}$}. example: {@code 0.0.1234}
* @param timestamp A Unix timestamp in seconds.nanoseconds format. pattern: {@code ^\d{1,10}(\.\d{1,9})?$}.
* example: {@code 1586567700.453054000}
* @param transactionHash A hex encoded transaction hash. example:
* {@code 0x397022d1e5baeb89d0ab66e6bf602640610e6fb7e55d78638db861e2c6339aa9}
* @param transactionIndex The position of the transaction in the block
*/
public record ContractLog(@NonNull String address, @Nullable String bloom, @Nullable ContractId contractId,
@Nullable String data, long index,
@NonNull List<String> topics, @NonNull String block_hash, long blockNumber,
@Nullable ContractId rootContractId, @NonNull String timestamp,
@NonNull String transactionHash,
@Nullable Long transactionIndex) {

public ContractLog {
Objects.requireNonNull(address, "address must not be null");
Objects.requireNonNull(topics, "topics must not be null");
Objects.requireNonNull(block_hash, "block_hash must not be null");
Objects.requireNonNull(timestamp, "timestamp must not be null");
Objects.requireNonNull(transactionHash, "transactionHash must not be null");
}

public ZonedDateTime getTimestamp() {
String[] parts = timestamp.split("\\.");
long seconds = Long.parseLong(parts[0]);
int nanoseconds = parts.length > 1 ? Integer.parseInt(parts[1]) : 0;
Instant instant = Instant.ofEpochSecond(seconds, nanoseconds);
return ZonedDateTime.ofInstant(instant, ZoneOffset.UTC);
}

public boolean isEventOfType(final @NonNull AbiEvent event) {
Objects.requireNonNull(event, "event");
if (event.anonymous()) {
throw new IllegalStateException("Cannot check anonymous event");
}
if (topics.isEmpty()) {
return false;
}
final String eventHashAsHex = event.createEventSignatureHashAsHex();
return topics.get(0).equals(eventHashAsHex);
}

public ContractEventInstance asEventInstance(final @NonNull AbiEvent event) {
Objects.requireNonNull(event, "event must not be null");
if (!isEventOfType(event)) {
throw new IllegalArgumentException("Event does not match log");
}
return SolidityTools.asEventInstance(this, event);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.openelements.hiero.base.data;

public enum Order {
ASC,
DESC
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
package com.openelements.hiero.base.mirrornode;

import com.hedera.hashgraph.sdk.ContractId;
import com.openelements.hiero.base.data.ContractLog;
import com.openelements.hiero.base.data.Order;
import com.openelements.hiero.base.data.Page;
import com.openelements.hiero.smartcontract.abi.model.AbiEvent;
import java.time.ZonedDateTime;
import java.util.Objects;
import org.jspecify.annotations.NonNull;

public interface ContractRepository {

default Page<ContractLog> findLogsByContract(@NonNull String contractId) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContract(ContractId.fromString(contractId));
}

default Page<ContractLog> findLogsByContract(@NonNull String contractId, @NonNull Order order) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContract(ContractId.fromString(contractId), order);
}

default Page<ContractLog> findLogsByContract(@NonNull String contractId, @NonNull AbiEvent abiEvent) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContract(ContractId.fromString(contractId), abiEvent);
}

default Page<ContractLog> findLogsByContract(@NonNull String contractId, @NonNull AbiEvent abiEvent,
@NonNull Order order) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContract(ContractId.fromString(contractId), abiEvent, order);
}

default Page<ContractLog> findLogsByContract(@NonNull String contractId, int pageLimit) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContract(ContractId.fromString(contractId), pageLimit);
}

default Page<ContractLog> findLogsByContract(@NonNull String contractId, @NonNull Order order, int pageLimit) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContract(ContractId.fromString(contractId), order, pageLimit);
}

default Page<ContractLog> findLogsByContract(@NonNull String contractId, @NonNull AbiEvent abiEvent,
int pageLimit) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContract(ContractId.fromString(contractId), abiEvent, pageLimit);
}

default Page<ContractLog> findLogsByContract(@NonNull String contractId, @NonNull AbiEvent abiEvent,
@NonNull Order order, int pageLimit) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContract(ContractId.fromString(contractId), abiEvent, order, pageLimit);
}

default Page<ContractLog> findLogsByContract(@NonNull ContractId contractId) {
return findLogsByContract(contractId, Order.DESC);
}

default Page<ContractLog> findLogsByContract(@NonNull ContractId contractId, @NonNull AbiEvent abiEvent) {
return findLogsByContract(contractId, abiEvent, Order.DESC);
}

default Page<ContractLog> findLogsByContract(@NonNull ContractId contractId, int pageLimit) {
return findLogsByContract(contractId, Order.DESC, pageLimit);
}

default Page<ContractLog> findLogsByContract(@NonNull ContractId contractId, @NonNull AbiEvent abiEvent,
int pageLimit) {
return findLogsByContract(contractId, abiEvent, Order.DESC, pageLimit);
}

Page<ContractLog> findLogsByContract(@NonNull ContractId contractId, @NonNull Order order);

Page<ContractLog> findLogsByContract(@NonNull ContractId contractId, @NonNull AbiEvent abiEvent,
@NonNull Order order);

Page<ContractLog> findLogsByContract(@NonNull ContractId contractId, @NonNull Order order, int pageLimit);

Page<ContractLog> findLogsByContract(@NonNull ContractId contractId, @NonNull AbiEvent abiEvent,
@NonNull Order order, int pageLimit);


default Page<ContractLog> findLogsByContractBeforeTimestamp(@NonNull String contractId, ZonedDateTime timestamp) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContractBeforeTimestamp(ContractId.fromString(contractId), timestamp);
}

default Page<ContractLog> findLogsByContractBeforeTimestamp(@NonNull String contractId, @NonNull Order order,
ZonedDateTime timestamp) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContractBeforeTimestamp(ContractId.fromString(contractId), order, timestamp);
}

default Page<ContractLog> findLogsByContractBeforeTimestamp(@NonNull String contractId, @NonNull AbiEvent abiEvent,
ZonedDateTime timestamp) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContractBeforeTimestamp(ContractId.fromString(contractId), abiEvent, timestamp);
}

default Page<ContractLog> findLogsByContractBeforeTimestamp(@NonNull String contractId, @NonNull AbiEvent abiEvent,
@NonNull Order order, ZonedDateTime timestamp) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContractBeforeTimestamp(ContractId.fromString(contractId), abiEvent, order, timestamp);
}

default Page<ContractLog> findLogsByContractBeforeTimestamp(@NonNull String contractId, int pageLimit,
ZonedDateTime timestamp) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContractBeforeTimestamp(ContractId.fromString(contractId), pageLimit, timestamp);
}

default Page<ContractLog> findLogsByContractBeforeTimestamp(@NonNull String contractId, @NonNull Order order,
int pageLimit, ZonedDateTime timestamp) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContractBeforeTimestamp(ContractId.fromString(contractId), order, pageLimit, timestamp);
}

default Page<ContractLog> findLogsByContractBeforeTimestamp(@NonNull String contractId, @NonNull AbiEvent abiEvent,
int pageLimit, ZonedDateTime timestamp) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContractBeforeTimestamp(ContractId.fromString(contractId), abiEvent, pageLimit, timestamp);
}

default Page<ContractLog> findLogsByContractBeforeTimestamp(@NonNull String contractId, @NonNull AbiEvent abiEvent,
@NonNull Order order, int pageLimit, ZonedDateTime timestamp) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContractBeforeTimestamp(ContractId.fromString(contractId), abiEvent, order, pageLimit,
timestamp);
}

default Page<ContractLog> findLogsByContractBeforeTimestamp(@NonNull ContractId contractId,
ZonedDateTime timestamp) {
return findLogsByContractBeforeTimestamp(contractId, Order.DESC, timestamp);
}

default Page<ContractLog> findLogsByContractBeforeTimestamp(@NonNull ContractId contractId,
@NonNull AbiEvent abiEvent, ZonedDateTime timestamp) {
return findLogsByContractBeforeTimestamp(contractId, abiEvent, Order.DESC, timestamp);
}

default Page<ContractLog> findLogsByContractBeforeTimestamp(@NonNull ContractId contractId, int pageLimit,
ZonedDateTime timestamp) {
return findLogsByContractBeforeTimestamp(contractId, Order.DESC, pageLimit, timestamp);
}

default Page<ContractLog> findLogsByContractBeforeTimestamp(@NonNull ContractId contractId,
@NonNull AbiEvent abiEvent,
int pageLimit, ZonedDateTime timestamp) {
return findLogsByContractBeforeTimestamp(contractId, abiEvent, Order.DESC, pageLimit, timestamp);
}

Page<ContractLog> findLogsByContractBeforeTimestamp(@NonNull ContractId contractId, @NonNull Order order,
ZonedDateTime timestamp);

Page<ContractLog> findLogsByContractBeforeTimestamp(@NonNull ContractId contractId, @NonNull AbiEvent abiEvent,
@NonNull Order order, ZonedDateTime timestamp);

Page<ContractLog> findLogsByContractBeforeTimestamp(@NonNull ContractId contractId, @NonNull Order order,
int pageLimit, ZonedDateTime timestamp);

Page<ContractLog> findLogsByContractBeforeTimestamp(@NonNull ContractId contractId, @NonNull AbiEvent abiEvent,
@NonNull Order order, int pageLimit, ZonedDateTime timestamp);

default Page<ContractLog> findLogsByContractAfterTimestamp(@NonNull String contractId, ZonedDateTime timestamp) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContractAfterTimestamp(ContractId.fromString(contractId), timestamp);
}

default Page<ContractLog> findLogsByContractAfterTimestamp(@NonNull String contractId, @NonNull Order order,
ZonedDateTime timestamp) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContractAfterTimestamp(ContractId.fromString(contractId), order, timestamp);
}

default Page<ContractLog> findLogsByContractAfterTimestamp(@NonNull String contractId, @NonNull AbiEvent abiEvent,
ZonedDateTime timestamp) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContractAfterTimestamp(ContractId.fromString(contractId), abiEvent, timestamp);
}

default Page<ContractLog> findLogsByContractAfterTimestamp(@NonNull String contractId, @NonNull AbiEvent abiEvent,
@NonNull Order order, ZonedDateTime timestamp) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContractAfterTimestamp(ContractId.fromString(contractId), abiEvent, order, timestamp);
}

default Page<ContractLog> findLogsByContractAfterTimestamp(@NonNull String contractId, int pageLimit,
ZonedDateTime timestamp) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContractAfterTimestamp(ContractId.fromString(contractId), pageLimit, timestamp);
}

default Page<ContractLog> findLogsByContractAfterTimestamp(@NonNull String contractId, @NonNull Order order,
int pageLimit, ZonedDateTime timestamp) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContractAfterTimestamp(ContractId.fromString(contractId), order, pageLimit, timestamp);
}

default Page<ContractLog> findLogsByContractAfterTimestamp(@NonNull String contractId, @NonNull AbiEvent abiEvent,
int pageLimit, ZonedDateTime timestamp) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContractAfterTimestamp(ContractId.fromString(contractId), abiEvent, pageLimit, timestamp);
}

default Page<ContractLog> findLogsByContractAfterTimestamp(@NonNull String contractId, @NonNull AbiEvent abiEvent,
@NonNull Order order, int pageLimit, ZonedDateTime timestamp) {
Objects.requireNonNull(contractId, "contractId must be provided");
return findLogsByContractAfterTimestamp(ContractId.fromString(contractId), abiEvent, order, pageLimit,
timestamp);
}

default Page<ContractLog> findLogsByContractAfterTimestamp(@NonNull ContractId contractId,
ZonedDateTime timestamp) {
return findLogsByContractAfterTimestamp(contractId, Order.DESC, timestamp);
}

default Page<ContractLog> findLogsByContractAfterTimestamp(@NonNull ContractId contractId,
@NonNull AbiEvent abiEvent, ZonedDateTime timestamp) {
return findLogsByContractAfterTimestamp(contractId, abiEvent, Order.DESC, timestamp);
}

default Page<ContractLog> findLogsByContractAfterTimestamp(@NonNull ContractId contractId, int pageLimit,
ZonedDateTime timestamp) {
return findLogsByContractAfterTimestamp(contractId, Order.DESC, pageLimit, timestamp);
}

default Page<ContractLog> findLogsByContractAfterTimestamp(@NonNull ContractId contractId,
@NonNull AbiEvent abiEvent,
int pageLimit, ZonedDateTime timestamp) {
return findLogsByContractAfterTimestamp(contractId, abiEvent, Order.DESC, pageLimit, timestamp);
}

Page<ContractLog> findLogsByContractAfterTimestamp(@NonNull ContractId contractId, @NonNull Order order,
ZonedDateTime timestamp);

Page<ContractLog> findLogsByContractAfterTimestamp(@NonNull ContractId contractId, @NonNull AbiEvent abiEvent,
@NonNull Order order, ZonedDateTime timestamp);

Page<ContractLog> findLogsByContractAfterTimestamp(@NonNull ContractId contractId, @NonNull Order order,
int pageLimit, ZonedDateTime timestamp);

Page<ContractLog> findLogsByContractAfterTimestamp(@NonNull ContractId contractId, @NonNull AbiEvent abiEvent,
@NonNull Order order, int pageLimit, ZonedDateTime timestamp);
}
Loading
Loading