hiero-ledger / hiero-ledger/hiero-enterprise-java
Issue 6 — ContractListener: Web3j event subscription + log decoding
- Dominant language
- Java
- Stars
- 6
- Forks
- 21
- Avg merge
- 10h 27m
- Merged PRs (30d)
- 37
Description
### Context
This is the core of the feature: given a resolved EVM contractAddress, eventName, and List, actually subscribe to the contract's event logs via the ledger's Web3j provider, deliver decoded events, and return a ContractSubscription (#4) the caller can use to cancel it.
```java
@Nullable
private String contractAddress;
@NonNull
private final String eventName;
@NonNull @Immutable
private final List eventParams = List.of();
```
### Scope
* Build the Solidity Event definition (name + List> unwrapped from eventParams) and derive its topic0 signature hash via Web3j's EventEncoder.
* Construct an EthFilter for the contract address + event signature and subscribe via the resolved Web3j provider (web3j.ethLogFlowable(filter) or equivalent), consistent with the class holding a Web3j per ledger from #5.
* Decode each received Log into an EventLog (#3): copy the raw log fields (address, topics, blockHash, logIndex, blockNumber, transactionHash, transactionIndex, data) across, and populate indexedValues by decoding topics[1..] against the indexed EventParams and nonIndexedValues by decoding data against the non-indexed EventParams (Web3j's FunctionReturnDecoder/Contract.staticExtractEventParameters helpers cover most of this).
* Deliver decoded events to the registered callback; define and document error handling for decode failures and subscription/connection errors (propagate vs. log-and-skip — align with the pattern chosen in #7).
* Wrap the Flowable's Disposable in a ContractSubscription (#4) and return it from the subscription call, so unsubscribe()/close() disposes it cleanly.
### Acceptance Criteria
[x] Given a deployed sample contract and a function call that emits the target event, the registered callback receives a correctly decoded EventLog.
[x] Indexed and non-indexed parameters are both decoded correctly for the types supported by EventParam (#2).
[x] The returned ContractSubscription's unsubscribe()/close() stops further callback invocations and disposes the underlying Web3j subscription without leaking resources.
[x] Unit tests using a mocked/stubbed Web3j provider; integration test against a live testnet contract (can be combined with #9).
Contributor guide
Assessment
This issue has not been assessed yet.