#35726·go-ethereum

abigen v2: 生成的事件拆解器会跳过对空有效负载的解码,返回包含 nil 错误的 nil 字段

作者: jeanbmar创建于 2026年9月17日更新于 2026年9月17日

Use the existing test contract in the repo, basic1(uint256 indexed id, uint256 data). Save as accounts/abi/bind/v2/internal/contracts/events/repro_test.go:

package events

import (
	"math/big"
	"testing"

	"GitHub.com/ethereum/go-ethereum/common"
	"GitHub.com/ethereum/go-ethereum/core/types"
)

func TestReproEmptyPayload(t *testing.T) {
	c := NewC()
	log := &types.Log{Topics: []common.Hash{
		c.abi.Events["basic1"].ID,
		common.BigToHash(big.NewInt(7)),
	}}
	out, err := c.UnpackBasic1Event(log)
	t.Logf("empty payload: err=%v Id=%v Data=%v", err, out.Id, out.Data)

	short := &types.Log{Topics: log.Topics, Data: make([]byte, 8)}
	_, err = c.UnpackBasic1Event(short)
	t.Logf("8-byte payload: err=%v", err)

	_ = out.Data.Int64() // what a consumer does with a nil-error result
}

内容来源: ethereum/go-ethereum