publish<T extends EventBodyModel> method

Future<EventModel<EventBodyModel>> publish<T extends EventBodyModel>(
  1. T body
)

Publishes a new event to the network. Returns the event if it was successfully published, null otherwise.

Implementation

Future<EventModel> publish<T extends EventBodyModel>(T body) async {
  final deviceKey = signing.publicKey;
  final parent = await db.events.latestDeviceEvent(deviceKey).get();

  final event = await EventModel.create(
    deviceKey: deviceKey,
    sequence: (parent?.sequence ?? 0) + 1,
    prevHash: parent?.hash,
    body: body,
  );

  if (await EventIngestor.instance.ingest(event)) {
    await relay(event);
  }

  return event;
}