2021-09-08 20:55:37 +00:00
|
|
|
import json, json_serialization, strutils
|
2021-10-04 21:21:07 +00:00
|
|
|
import signals/[base, chronicles_logs, community, discovery_summary, envelope, expired, mailserver, messages, peerstats, signal_type, stats, wallet, whisper_filter, keycard]
|
2021-09-08 20:55:37 +00:00
|
|
|
|
2021-09-30 18:56:22 +00:00
|
|
|
export base, chronicles_logs, community, discovery_summary, envelope, expired, mailserver, messages, peerstats, signal_type, stats, wallet, whisper_filter
|
2021-09-08 20:55:37 +00:00
|
|
|
|
|
|
|
proc decode*(jsonSignal: JsonNode): Signal =
|
|
|
|
let signalString = jsonSignal{"type"}.getStr
|
|
|
|
var signalType: SignalType
|
|
|
|
try:
|
|
|
|
signalType = parseEnum[SignalType](signalString)
|
|
|
|
except:
|
|
|
|
raise newException(ValueError, "Unknown signal received: " & signalString)
|
|
|
|
|
|
|
|
result = case signalType:
|
|
|
|
of SignalType.Message: MessageSignal.fromEvent(jsonSignal)
|
|
|
|
of SignalType.EnvelopeSent: EnvelopeSentSignal.fromEvent(jsonSignal)
|
|
|
|
of SignalType.EnvelopeExpired: EnvelopeExpiredSignal.fromEvent(jsonSignal)
|
|
|
|
of SignalType.WhisperFilterAdded: WhisperFilterSignal.fromEvent(jsonSignal)
|
|
|
|
of SignalType.Wallet: WalletSignal.fromEvent(jsonSignal)
|
|
|
|
of SignalType.NodeLogin: Json.decode($jsonSignal, NodeSignal)
|
2021-09-30 18:56:22 +00:00
|
|
|
of SignalType.PeerStats: PeerStatsSignal.fromEvent(jsonSignal)
|
2021-09-08 20:55:37 +00:00
|
|
|
of SignalType.DiscoverySummary: DiscoverySummarySignal.fromEvent(jsonSignal)
|
|
|
|
of SignalType.MailserverRequestCompleted: MailserverRequestCompletedSignal.fromEvent(jsonSignal)
|
|
|
|
of SignalType.MailserverRequestExpired: MailserverRequestExpiredSignal.fromEvent(jsonSignal)
|
|
|
|
of SignalType.CommunityFound: CommunitySignal.fromEvent(jsonSignal)
|
|
|
|
of SignalType.Stats: StatsSignal.fromEvent(jsonSignal)
|
2021-09-15 19:45:17 +00:00
|
|
|
of SignalType.ChroniclesLogs: ChroniclesLogsSignal.fromEvent(jsonSignal)
|
2021-09-28 18:41:40 +00:00
|
|
|
of SignalType.HistoryRequestCompleted: HistoryRequestCompletedSignal.fromEvent(jsonSignal)
|
|
|
|
of SignalType.HistoryRequestStarted: HistoryRequestStartedSignal.fromEvent(jsonSignal)
|
|
|
|
of SignalType.HistoryRequestFailed: HistoryRequestFailedSignal.fromEvent(jsonSignal)
|
2021-10-04 21:21:07 +00:00
|
|
|
of SignalType.KeycardConnected: KeycardConnectedSignal.fromEvent(jsonSignal)
|
2021-09-08 20:55:37 +00:00
|
|
|
else: Signal()
|
2021-10-04 21:21:07 +00:00
|
|
|
|
2021-09-17 16:55:17 +00:00
|
|
|
result.signalType = signalType
|