ClientMsg constructor

ClientMsg(
  1. String type, {
  2. String? id,
  3. Nip01Event? event,
  4. List<Filter>? filters,
})

Implementation

ClientMsg(
  this.type, {
  this.id,
  this.event,
  this.filters,
}) {
  // verify based on type
  if (type == ClientMsgType.EVENT) {
    if (event == null) {
      throw Exception("event is required for type EVENT");
    }
  }

  if (type == ClientMsgType.REQ) {
    if (filters == null) {
      throw Exception("filters are required for type REQ");
    }

    if (filters!.isEmpty) {
      throw Exception("filters are required for type REQ");
    }
    if (id == null) {
      throw Exception("id is required for type REQ");
    }
  }

  if (type == ClientMsgType.CLOSE) {
    if (id == null) {
      throw Exception("id is required for type CLOSE");
    }
  }
  if (type == ClientMsgType.COUNT) {
    throw Exception("COUNT is not implemented yet");
  }
}