fix: eth: ensure that the event topics are non-nil
Even when empty. fixes #10910
This commit is contained in:
parent
5b31b79d58
commit
739d61c698
@ -1537,6 +1537,8 @@ func ethLogFromEvent(entries []types.EventEntry) (data []byte, topics []ethtypes
|
|||||||
topicsFoundCount int
|
topicsFoundCount int
|
||||||
dataFound bool
|
dataFound bool
|
||||||
)
|
)
|
||||||
|
// Topics must be non-nil, even if empty. So we might as well pre-allocate for 4 (the max).
|
||||||
|
topics = make([]ethtypes.EthHash, 0, 4)
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
// Drop events with non-raw topics to avoid mistakes.
|
// Drop events with non-raw topics to avoid mistakes.
|
||||||
if entry.Codec != cid.Raw {
|
if entry.Codec != cid.Raw {
|
||||||
|
@ -17,7 +17,8 @@ func TestEthLogFromEvent(t *testing.T) {
|
|||||||
data, topics, ok := ethLogFromEvent(nil)
|
data, topics, ok := ethLogFromEvent(nil)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.Nil(t, data)
|
require.Nil(t, data)
|
||||||
require.Nil(t, topics)
|
require.Empty(t, topics)
|
||||||
|
require.NotNil(t, topics)
|
||||||
|
|
||||||
// basic topic
|
// basic topic
|
||||||
data, topics, ok = ethLogFromEvent([]types.EventEntry{{
|
data, topics, ok = ethLogFromEvent([]types.EventEntry{{
|
||||||
|
Loading…
Reference in New Issue
Block a user