lotus/chain/types/event.go
Steven Allen 89499bfd40 fvm: chore: update FVM
This:

1. Updates the builtin actors bundle (for actors v10).
2. Updates the event entry type to include the codec.
3. Removes the cbor encoding and zero trimming from event data.

I've chose to:

1. _Not_ add codec handling to the event filtering system for now.
2. _Skip_ events with unexpected codecs.

We don't actually _allow_ these events in the FVM right now, and it
simplifies the implementation.

However, I _am_ recording the codecs in the database so we don't have to
migrate it later.
2023-02-07 18:15:40 -08:00

62 lines
1.3 KiB
Go

package types
import (
"bytes"
"fmt"
cbg "github.com/whyrusleeping/cbor-gen"
"github.com/filecoin-project/go-state-types/abi"
)
// EventEntry flags defined in fvm_shared
const (
EventFlagIndexedKey = 0b00000001
EventFlagIndexedValue = 0b00000010
)
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
// The event value's codec
Codec uint64
// The event value
Value []byte
}
type FilterID [32]byte // compatible with EthHash
// 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
}