code.vegaprotocol.io/vega@v0.79.0/core/events/README.md (about)

     1  # Event bus
     2  
     3  ## Add a new event
     4  1. Create a protobuf message to describe your event in the `proto` folder.
     5  2. Register your event in `BusEventType` enum and `BusEvent.event` message in
     6     `proto/events.proto`.
     7  3. Generate the code with `make proto`.
     8  4. In `events/bus.go`, create a constant to identify the event and map it to the
     9     protobuf enum type `BusEventType` in variable `protoMap` and `toProto`. Give
    10     it a name in `eventStrings`.
    11  5. In the `events` folder, create a file `my_event.go` where the Golang
    12     definition of the new event will live:
    13  
    14  ```golang
    15  package events
    16  
    17  import (
    18  	eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1"
    19  )
    20  
    21  type MyEvent struct {
    22  	*Base
    23  	o eventspb.MyEvent
    24  }
    25  
    26  ```
    27  
    28  6. Implement the `StreamEvent` interface on it.
    29  7. Implement the "<NewEvent>FromStream interface on it.
    30  8. Add the support for this new event into the `Service` responsible for it.
    31  9. Update the graphql structures in the data-node in schema.graphql. In particular the `BusEventType` enum and the `Event` union