go-ethereum/accounts/abi
Vadim Tertilov 289826fefb
Some checks are pending
/ Linux Build (arm) (push) Waiting to run
/ Keeper Build (push) Waiting to run
/ Linux Build (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run
cmd/abigen/v2: add package-level errors (#34076)
# Summary

Replaces the inline `errors.New("event signature mismatch")` in
generated `UnpackXxxEvent` methods with per-event package-level sentinel
errors (e.g. `ErrTransferSignatureMismatch`,
`ErrApprovalSignatureMismatch`), allowing callers to reliably
distinguish a topic mismatch from a genuine decoding failure via
`errors.Is`.

Each event gets its own sentinel, generated via the abigen template:

```go
var ErrTransferSignatureMismatch = errors.New("event signature mismatch")
```

This scoping is intentional — it allows callers to be precise about
*which* event was mismatched, which is useful when routing logs across
multiple unpackers.

# Motivation
Previously, all errors returned from `UnpackXxxEvent` were
indistinguishable without string matching. This is especially
problematic when processing logs sourced from `eth_getBlockReceipts`,
where a caller receives the full set of logs for a block across all
contracts and event types. In that context, a signature mismatch is
expected and should be skipped, while any other error (malformed data,
topic parsing failure) indicates something is genuinely wrong and should
halt execution:

```go
for _, log := range blockLogs {
    event, err := contract.UnpackTransferEvent(log)
    if errors.Is(err, gen.ErrTransferSignatureMismatch) {
        continue // not our event, expected
    }
    if err != nil {
        return fmt.Errorf("unexpected decode failure: %w", err) // alert
    }
    // process event
}
```

**Changes:**
- `abigen` template: generates a `ErrXxxSignatureMismatch` sentinel per
event and returns it on topic mismatch instead of an inline error
- Existing generated bindings & testdata: regenerated to reflect the
update

Implements #34075
2026-04-13 14:42:34 +02:00
..
abigen cmd/abigen/v2: add package-level errors (#34076) 2026-04-13 14:42:34 +02:00
bind cmd/abigen/v2: add package-level errors (#34076) 2026-04-13 14:42:34 +02:00
abi.go accounts/abi: support unpacking solidity errors (#30738) 2024-12-10 14:30:24 +01:00
abi_test.go accounts/abi: support unpacking solidity errors (#30738) 2024-12-10 14:30:24 +01:00
abifuzzer_test.go accounts: run tests in parallel (#28544) 2023-12-04 14:55:06 +01:00
argument.go accounts/abi: improve unpack performance (#31387) 2025-03-14 15:27:38 +01:00
doc.go all: fix license headers one more time 2015-07-23 18:35:11 +02:00
error.go accounts/abi: context info on unpack-errors (#28529) 2023-11-21 09:16:57 +01:00
error_handling.go accounts/abi: error when packing negative values in unsigned types (#31790) 2025-06-04 14:47:01 +02:00
event.go accounts/abi/bind: fix duplicate field names in the generated go struct (#24924) 2022-06-07 08:38:54 +02:00
event_test.go build: update to golangci-lint 1.61.0 (#30587) 2024-10-14 19:25:22 +02:00
method.go accounts/abi: improve readability of method-to-string conversion (#28530) 2023-11-15 14:30:35 +01:00
method_test.go accounts: run tests in parallel (#28544) 2023-12-04 14:55:06 +01:00
pack.go accounts/abi: error when packing negative values in unsigned types (#31790) 2025-06-04 14:47:01 +02:00
pack_test.go accounts/abi: error when packing negative values in unsigned types (#31790) 2025-06-04 14:47:01 +02:00
packing_test.go accounts/abi: ABI explicit difference between Unpack and UnpackIntoInterface (#21091) 2020-09-28 14:10:26 +02:00
reflect.go accounts/abi, accounts/keystore: use reflect.TypeFor (#32323) 2025-08-11 14:24:55 +02:00
reflect_test.go accounts/abi, accounts/keystore: use reflect.TypeFor (#32323) 2025-08-11 14:24:55 +02:00
selector_parser.go accounts: replace noarg fmt.Errorf with errors.New (#27331) 2023-05-25 08:25:58 -04:00
selector_parser_test.go accounts: run tests in parallel (#28544) 2023-12-04 14:55:06 +01:00
topics.go accounts/abi: fix MakeTopics mutation of big.Int inputs (#30785) 2024-11-25 13:34:50 +01:00
topics_test.go accounts/abi: fix MakeTopics mutation of big.Int inputs (#30785) 2024-11-25 13:34:50 +01:00
type.go accounts/abi, accounts/keystore: use reflect.TypeFor (#32323) 2025-08-11 14:24:55 +02:00
type_test.go all: fix various typos (#29600) 2024-04-23 13:09:42 +03:00
unpack.go account/abi: convert if-else-if chain to tagged switch (#27869) 2023-08-23 09:53:38 -04:00
unpack_test.go accounts/abi: error when packing negative values in unsigned types (#31790) 2025-06-04 14:47:01 +02:00
utils.go build: upgrade to go 1.19 (#25726) 2022-09-10 13:25:40 +02:00