b46258d0bf
- Event keys are now t1, t2, t3, t4 for topics; and d for data. - ref-fvm no longer stores events in the blockstore for us. It just returns events to the client, who is now responsible for handling them as it wishes / according to its configuration. - Add a flag to VMOpts to have the events AMT be written in the blockstore. - Add a flag to the ChainStore to advertise to the rest of the system if the ChainStore is storing events. - Enable that flag if the EthRPC is enabled (can also add an explicit configuration flag if wanted).
59 lines
1.3 KiB
Go
59 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
|
|
|
|
// Any DAG-CBOR encodeable type.
|
|
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
|
|
}
|