2023-01-13 19:11:13 +00:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
2023-02-03 03:10:30 +00:00
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
cbg "github.com/whyrusleeping/cbor-gen"
|
|
|
|
|
2023-01-13 19:11:13 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
)
|
|
|
|
|
2023-02-03 03:10:30 +00:00
|
|
|
// EventEntry flags defined in fvm_shared
|
|
|
|
const (
|
|
|
|
EventFlagIndexedKey = 0b00000001
|
|
|
|
EventFlagIndexedValue = 0b00000010
|
|
|
|
)
|
|
|
|
|
2023-01-13 19:11:13 +00:00
|
|
|
type Event struct {
|
|
|
|
// The ID of the actor that emitted this event.
|
|
|
|
Emitter abi.ActorID
|
|
|
|
|
|
|
|
// Key values making up this event.
|
|
|
|
Entries []EventEntry
|
|
|
|
}
|
|
|
|
|
|
|
|
type EventEntry struct {
|
|
|
|
// A bitmap conveying metadata or hints about this entry.
|
|
|
|
Flags uint8
|
|
|
|
|
|
|
|
// The key of this event entry
|
|
|
|
Key string
|
|
|
|
|
|
|
|
// Any DAG-CBOR encodeable type.
|
|
|
|
Value []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
type FilterID [32]byte // compatible with EthHash
|
|
|
|
|
2023-02-03 03:10:30 +00:00
|
|
|
// DecodeEvents decodes a CBOR list of CBOR-encoded events.
|
|
|
|
func DecodeEvents(input []byte) ([]Event, error) {
|
|
|
|
r := bytes.NewReader(input)
|
|
|
|
typ, len, err := cbg.NewCborReader(r).ReadHeader()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to read events: %w", err)
|
|
|
|
}
|
|
|
|
if typ != cbg.MajArray {
|
|
|
|
return nil, fmt.Errorf("expected a CBOR list, was major type %d", typ)
|
|
|
|
}
|
|
|
|
events := make([]Event, 0, len)
|
|
|
|
for i := 0; i < int(len); i++ {
|
|
|
|
var evt Event
|
|
|
|
if err := evt.UnmarshalCBOR(r); err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to parse event: %w", err)
|
|
|
|
}
|
|
|
|
events = append(events, evt)
|
|
|
|
}
|
|
|
|
return events, nil
|
|
|
|
}
|