Fix indexed event decoding for non-dynamic topic values#955
Conversation
* Initial plan * Remove fisco-bcos.org URL, replace with GitHub repo URL in build.gradle Co-authored-by: kyonRay <32325790+kyonRay@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: kyonRay <32325790+kyonRay@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This pull request fixes decoding of non-dynamic indexed event parameters (e.g., address indexed, uint256 indexed) in ContractCodec.decodeIndexedEvent(...), ensuring the by-interface event decode APIs correctly return indexed values instead of dropping/failing on them.
Changes:
- Decode non-dynamic indexed
VALUEparameters directly from the 32-byte topic payload using the ABI decode path. - Add a regression test covering indexed
address+ indexeduint256acrossdecodeIndexedEvent(...),decodeEventByInterface(...), anddecodeEventByInterfaceToString(...).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/main/java/org/fisco/bcos/sdk/v3/codec/ContractCodec.java |
Fixes decodeIndexedEvent to properly decode non-dynamic indexed VALUE params from topic bytes. |
src/test/java/org/fisco/bcos/sdk/v3/test/codec/abi/ABIEventTest.java |
Adds a focused regression test for indexed address/uint256 event decoding across multiple decode entry points. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } else if (indexedObject.getType() == ABIObject.ObjectType.VALUE) { | ||
| ABIObject decodedIndexedObject = | ||
| ContractCodecTools.decode( | ||
| indexedObject, Hex.decode(log.getTopics().get(i)), isWasm); | ||
| topics.add(contractCodecJsonWrapper.decode(decodedIndexedObject).asText()); |
| import java.math.BigInteger; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import org.fisco.bcos.sdk.v3.codec.abi.TypeEncoder; | ||
| import org.fisco.bcos.sdk.v3.codec.abi.tools.TopicTools; |
| List<String> topics = new ArrayList<>(); | ||
| topics.add(Numeric.toHexString(abiCodec.getFunctionEncoder().buildMethodId(eventSignature))); | ||
| TopicTools topicTools = new TopicTools(TestUtils.getCryptoSuite()); | ||
| topics.add(topicTools.addressToTopic(from)); | ||
| topics.add(topicTools.integerToTopic(id)); | ||
|
|
||
| EventLog log = new EventLog(Numeric.toHexString(TypeEncoder.encode(new Uint256(value))), topics); | ||
| ABIDefinition abiDefinition = TestUtils.getContractABIDefinition(indexedAbi).getEvents().get("Transfer").get(0); |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release-3.9.0 #955 +/- ##
================================================
Coverage 64.05% 64.06%
Complexity 4567 4567
================================================
Files 430 430
Lines 17628 17634 +6
Branches 1969 1970 +1
================================================
+ Hits 11292 11297 +5
Misses 5576 5576
- Partials 760 761 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|



ContractCodec.decodeIndexedEvent(log, abiDefinition)mishandled non-dynamic indexed event params such asaddress indexedanduint256 indexed. The by-interface event decode path could drop or fail on common event shapes because bare VALUE topics were routed through the JSON struct decoder.Decoder path correction
VALUEparams directly from the 32-byte topic payload via the existing ABI decode path.Behavioral impact
address,uintN, and other static value types.decodeEventByInterface(...)/decodeIndexedEvent(...)for standard transfer-style events.Regression coverage
addressand indexeduint256.decodeIndexedEvent(...)decodeEventByInterface(...)decodeEventByInterfaceToString(...)Example shape covered by the regression test:
Before this change, the indexed topics for
from/idcould fail in the by-interface decode path; after this change, they decode to their expected values.