abi: adding the method EventByID and its test (#19359)
This function searches for an event+parameters in the ABI and returns it if found. Co-authored-by: Victor Tran <vu.tran54@gmail.com> Co-authored-by: Guillaume Ballet <gballet@gmail.com>
This commit is contained in:
committed by
Guillaume Ballet
parent
98099d6fa7
commit
e4a1488b2f
@ -21,6 +21,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// The ABI holds information about a contract's context and available
|
||||
@ -165,3 +167,14 @@ func (abi *ABI) MethodById(sigdata []byte) (*Method, error) {
|
||||
}
|
||||
return nil, fmt.Errorf("no method with id: %#x", sigdata[:4])
|
||||
}
|
||||
|
||||
// EventByID looks an event up by its topic hash in the
|
||||
// ABI and returns nil if none found.
|
||||
func (abi *ABI) EventByID(topic common.Hash) (*Event, error) {
|
||||
for _, event := range abi.Events {
|
||||
if bytes.Equal(event.Id().Bytes(), topic.Bytes()) {
|
||||
return &event, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("no event with id: %#x", topic.Hex())
|
||||
}
|
||||
|
Reference in New Issue
Block a user