FISCO-BCOS / FISCO-BCOS/java-sdk

ContractCodec.decodeIndexedEvent fails for non-dynamic indexed event params (address/uintN indexed)

Aperta
#950 0 commenti 1 reazione 2 assegnatari Rivendicata da @kyonRay Vedi su GitHub
bug
Lingua principale
Java
Stelle
58
Fork
62
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### Description
`org.fisco.bcos.sdk.v3.codec.ContractCodec.decodeIndexedEvent(log, abiDefinition)` does not correctly handle **non-dynamic** indexed event parameters (the common case, e.g. `event Transfer(address indexed from, address indexed to, uint256 value)`): the non-dynamic indexed topics throw / are dropped when decoding by interface.

### Cause
For a non-dynamic indexed object, it routes a single value-type `ABIObject` through the JSON struct decoder:

```java
} else {
List objects =
contractCodecJsonWrapper.decode(
indexedObject, Hex.decode(log.getTopics().get(i)), isWasm);
if (!objects.isEmpty()) {
topics.add(objects.get(0));
}
}
```

`ContractCodecJsonWrapper.decode` on a single bare VALUE-type object treats it as a struct (its `getStructFields()` is null), which throws `NullPointerException` / produces no value, so non-dynamic indexed params cannot be decoded via the by-interface path. (Dynamic indexed params take the `if (indexedObject.isDynamic())` branch and are fine.)

### Impact
`decodeEventByInterface` / `decodeIndexedEvent` fail for events whose indexed parameters are value types (`address indexed`, `uintN indexed`, `bytesN indexed`, …) — a very common ABI shape.

### Suggested fix
For non-dynamic indexed params, decode the 32-byte topic with the ABI `TypeDecoder` directly (as the static-bytes/value path elsewhere does) instead of `ContractCodecJsonWrapper.decode`.

### Found via
Event encode→decode-by-interface tests during #947.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.