mirror of
https://github.com/ACINQ/eclair.git
synced 2025-02-22 22:25:26 +01:00
Reorganize specialized formats for the websocket
This commit is contained in:
parent
cd703f2d4a
commit
10bc4ab811
1 changed files with 11 additions and 12 deletions
|
@ -51,6 +51,15 @@ trait Service extends Directives with Logging {
|
|||
import JsonSupport.marshaller
|
||||
import JsonSupport.formats
|
||||
import JsonSupport.serialization
|
||||
// used to send typed messages over the websocket
|
||||
val formatsWithTypeHint = formats.withTypeHintFieldName("type") +
|
||||
ShortTypeHints(List(
|
||||
classOf[PaymentSent],
|
||||
classOf[PaymentRelayed],
|
||||
classOf[PaymentReceived],
|
||||
classOf[PaymentSettlingOnChain],
|
||||
classOf[PaymentFailed]))
|
||||
|
||||
|
||||
def password: String
|
||||
|
||||
|
@ -85,27 +94,17 @@ trait Service extends Directives with Logging {
|
|||
// create a flow transforming a queue of string -> string
|
||||
val (flowInput, flowOutput) = Source.queue[String](10, OverflowStrategy.dropTail).toMat(BroadcastHub.sink[String])(Keep.both).run()
|
||||
|
||||
val _formats = formats
|
||||
|
||||
// register an actor that feeds the queue on payment related events
|
||||
actorSystem.actorOf(Props(new Actor {
|
||||
|
||||
implicit val formats = _formats.withTypeHintFieldName("type") +
|
||||
ShortTypeHints(List(
|
||||
classOf[PaymentSent],
|
||||
classOf[PaymentRelayed],
|
||||
classOf[PaymentReceived],
|
||||
classOf[PaymentSettlingOnChain],
|
||||
classOf[PaymentFailed]))
|
||||
|
||||
override def preStart: Unit = {
|
||||
context.system.eventStream.subscribe(self, classOf[PaymentFailed])
|
||||
context.system.eventStream.subscribe(self, classOf[PaymentEvent])
|
||||
}
|
||||
|
||||
def receive: Receive = {
|
||||
case message: PaymentFailed => flowInput.offer(Serialization write message)
|
||||
case message: PaymentEvent => flowInput.offer(Serialization write message)
|
||||
case message: PaymentFailed => flowInput.offer(Serialization.write(message)(formatsWithTypeHint))
|
||||
case message: PaymentEvent => flowInput.offer(Serialization.write(message)(formatsWithTypeHint))
|
||||
case other => logger.info(s"Unexpected ws message: $other")
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue