Skip to content
This repository was archived by the owner on May 16, 2026. It is now read-only.

Commit 5c3ecfe

Browse files
committed
Event support for contracts basically working
Signed-off-by: Hendrik Ebbers <hendrik.ebbers@web.de>
1 parent 0ea5e5f commit 5c3ecfe

2 files changed

Lines changed: 99 additions & 0 deletions

File tree

hiero-enterprise-base/src/main/java/com/openelements/hiero/base/data/ContractLog.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.openelements.hiero.base.data;
22

33
import com.hedera.hashgraph.sdk.ContractId;
4+
import com.openelements.hiero.base.solidity.SolidityTools;
45
import com.openelements.hiero.smartcontract.abi.model.AbiEvent;
56
import java.util.List;
67
import java.util.Objects;
@@ -41,6 +42,14 @@ public record ContractLog(@NonNull String address, @Nullable String bloom, @Null
4142
@NonNull String transactionHash,
4243
@Nullable Long transactionIndex) {
4344

45+
public ContractLog {
46+
Objects.requireNonNull(address, "address must not be null");
47+
Objects.requireNonNull(topics, "topics must not be null");
48+
Objects.requireNonNull(block_hash, "block_hash must not be null");
49+
Objects.requireNonNull(timestamp, "timestamp must not be null");
50+
Objects.requireNonNull(transactionHash, "transactionHash must not be null");
51+
}
52+
4453
public boolean isEventOfType(final @NonNull AbiEvent event) {
4554
Objects.requireNonNull(event, "event");
4655
if (event.anonymous()) {
@@ -53,4 +62,11 @@ public boolean isEventOfType(final @NonNull AbiEvent event) {
5362
return topics.get(0).equals(eventHashAsHex);
5463
}
5564

65+
public ContractEventInstance asEventInstance(final @NonNull AbiEvent event) {
66+
Objects.requireNonNull(event, "event must not be null");
67+
if (!isEventOfType(event)) {
68+
throw new IllegalArgumentException("Event does not match log");
69+
}
70+
return SolidityTools.asEventInstance(this, event);
71+
}
5672
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.openelements.hiero.base.test.data;
2+
3+
import com.hedera.hashgraph.sdk.ContractId;
4+
import com.openelements.hiero.base.data.ContractEventInstance;
5+
import com.openelements.hiero.base.data.ContractLog;
6+
import com.openelements.hiero.smartcontract.abi.model.AbiEvent;
7+
import com.openelements.hiero.smartcontract.abi.model.AbiParameter;
8+
import com.openelements.hiero.smartcontract.abi.model.AbiParameterType;
9+
import java.util.List;
10+
import org.junit.jupiter.api.Assertions;
11+
import org.junit.jupiter.api.Test;
12+
13+
public class ContractLogTest {
14+
15+
@Test
16+
void test() {
17+
//given
18+
// from https://testnet.mirrornode.hedera.com/api/v1/contracts/0.0.5615061/results/logs?limit=10&order=asc
19+
final String address = "0x000000000000000000000000000000000055add5";
20+
final String bloom = "0x00000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000";
21+
final ContractId contractId = ContractId.fromString("0.0.5615061");
22+
final String data = "0x0000000000000000000000000000000000000000000000000000000000000001";
23+
final long index = 1;
24+
final List<String> topics = List.of("0x271219bdbb9b91472a5df68ef7a9d3f8de02f3c27b93a35306f888acf081ea60");
25+
final String block_hash = "0x3c33e36ebaa60192ff6c714ec15adb3829e8dd24e0f28b607fa88f6052600fb07ab29aeeb828e3faffd85b90960cc679";
26+
final long blockNumber = 16076698;
27+
final ContractId rootContractId = ContractId.fromString("0.0.5615061");
28+
final String timestamp = "1740183080.776076000";
29+
final String transactionHash = "0x254fa8781dc4babe1df5925bc2e3e8aa50d1b57d019189116f93fbdbb5497812";
30+
final Long transactionIndex = 6L;
31+
final ContractLog contractLog = new ContractLog(address, bloom, contractId, data, index, topics, block_hash,
32+
blockNumber, rootContractId, timestamp, transactionHash, transactionIndex);
33+
final List<AbiParameter> inputs = List.of(
34+
new AbiParameter("count", AbiParameterType.UINT, List.of(), false)
35+
);
36+
final AbiEvent event = new AbiEvent("MissingVerificationCountUpdated", inputs, false);
37+
38+
//then
39+
Assertions.assertTrue(contractLog.isEventOfType(event));
40+
}
41+
42+
@Test
43+
void test2() {
44+
//given
45+
// from https://testnet.mirrornode.hedera.com/api/v1/contracts/0.0.5615061/results/logs?limit=10&order=asc
46+
final String address = "0x000000000000000000000000000000000055add5";
47+
final String bloom = "0x00000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000";
48+
final ContractId contractId = ContractId.fromString("0.0.5615061");
49+
final String data = "0x0000000000000000000000000000000000000000000000000000000000000001";
50+
final long index = 1;
51+
final List<String> topics = List.of("0x271219bdbb9b91472a5df68ef7a9d3f8de02f3c27b93a35306f888acf081ea60");
52+
final String block_hash = "0x3c33e36ebaa60192ff6c714ec15adb3829e8dd24e0f28b607fa88f6052600fb07ab29aeeb828e3faffd85b90960cc679";
53+
final long blockNumber = 16076698;
54+
final ContractId rootContractId = ContractId.fromString("0.0.5615061");
55+
final String timestamp = "1740183080.776076000";
56+
final String transactionHash = "0x254fa8781dc4babe1df5925bc2e3e8aa50d1b57d019189116f93fbdbb5497812";
57+
final Long transactionIndex = 6L;
58+
final ContractLog contractLog = new ContractLog(address, bloom, contractId, data, index, topics, block_hash,
59+
blockNumber, rootContractId, timestamp, transactionHash, transactionIndex);
60+
final List<AbiParameter> inputs = List.of(
61+
new AbiParameter("count", AbiParameterType.UINT, List.of(), false)
62+
);
63+
final AbiEvent event = new AbiEvent("MissingVerificationCountUpdated", inputs, false);
64+
65+
//when
66+
final ContractEventInstance eventInstance = contractLog.asEventInstance(event);
67+
68+
//then
69+
Assertions.assertNotNull(eventInstance);
70+
Assertions.assertEquals(contractId, eventInstance.contractId());
71+
Assertions.assertEquals("MissingVerificationCountUpdated", eventInstance.eventName());
72+
Assertions.assertEquals(1, eventInstance.parameters().size());
73+
Assertions.assertEquals("count", eventInstance.parameters().get(0).name());
74+
Assertions.assertEquals(AbiParameterType.UINT, eventInstance.parameters().get(0).type());
75+
Assertions.assertArrayEquals(
76+
new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
77+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
78+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
79+
0x00, 0x01},
80+
eventInstance.parameters().get(0).value());
81+
}
82+
83+
}

0 commit comments

Comments
 (0)