go-ethereum/accounts/abi/abigen/testdata/v2
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
..
callbackparam.go.txt accounts/abi: generate TryPack* methods for abigen v2 bindings (#31692) 2025-07-02 15:16:54 +09:00
crowdsale.go.txt cmd/abigen/v2: add package-level errors (#34076) 2026-04-13 14:42:34 +02:00
dao.go.txt cmd/abigen/v2: add package-level errors (#34076) 2026-04-13 14:42:34 +02:00
deeplynestedarray.go.txt accounts/abi: generate TryPack* methods for abigen v2 bindings (#31692) 2025-07-02 15:16:54 +09:00
empty.go.txt cmd/abigen, accounts/abi/bind: implement abigen version 2 (#31379) 2025-03-17 15:56:55 +01:00
eventchecker.go.txt cmd/abigen/v2: add package-level errors (#34076) 2026-04-13 14:42:34 +02:00
getter.go.txt accounts/abi: generate TryPack* methods for abigen v2 bindings (#31692) 2025-07-02 15:16:54 +09:00
identifiercollision.go.txt accounts/abi: generate TryPack* methods for abigen v2 bindings (#31692) 2025-07-02 15:16:54 +09:00
inputchecker.go.txt accounts/abi: generate TryPack* methods for abigen v2 bindings (#31692) 2025-07-02 15:16:54 +09:00
interactor.go.txt accounts/abi: generate TryPack* methods for abigen v2 bindings (#31692) 2025-07-02 15:16:54 +09:00
nameconflict.go.txt cmd/abigen/v2: add package-level errors (#34076) 2026-04-13 14:42:34 +02:00
numericmethodname.go.txt cmd/abigen/v2: add package-level errors (#34076) 2026-04-13 14:42:34 +02:00
outputchecker.go.txt accounts/abi: generate TryPack* methods for abigen v2 bindings (#31692) 2025-07-02 15:16:54 +09:00
overload.go.txt cmd/abigen/v2: add package-level errors (#34076) 2026-04-13 14:42:34 +02:00
rangekeyword.go.txt accounts/abi: generate TryPack* methods for abigen v2 bindings (#31692) 2025-07-02 15:16:54 +09:00
slicer.go.txt accounts/abi: generate TryPack* methods for abigen v2 bindings (#31692) 2025-07-02 15:16:54 +09:00
structs.go.txt accounts/abi: generate TryPack* methods for abigen v2 bindings (#31692) 2025-07-02 15:16:54 +09:00
token.go.txt cmd/abigen/v2: add package-level errors (#34076) 2026-04-13 14:42:34 +02:00
tuple.go.txt cmd/abigen/v2: add package-level errors (#34076) 2026-04-13 14:42:34 +02:00
tupler.go.txt accounts/abi: generate TryPack* methods for abigen v2 bindings (#31692) 2025-07-02 15:16:54 +09:00
underscorer.go.txt accounts/abi: generate TryPack* methods for abigen v2 bindings (#31692) 2025-07-02 15:16:54 +09:00