status-lib/status/signals/wallet.nim

28 lines
887 B
Nim
Raw Permalink Normal View History

2021-09-08 18:05:39 +00:00
import json
import base
2021-09-08 20:55:37 +00:00
import signal_type
2021-09-08 18:05:39 +00:00
type WalletSignal* = ref object of Signal
content*: string
eventType*: string
blockNumber*: int
accounts*: seq[string]
2021-09-10 17:27:49 +00:00
baseFeePerGas*: string
2021-09-08 18:05:39 +00:00
# newTransactions*: ???
erc20*: bool
2021-09-08 20:55:37 +00:00
proc fromEvent*(T: type WalletSignal, jsonSignal: JsonNode): WalletSignal =
result = WalletSignal()
result.signalType = SignalType.Wallet
result.content = $jsonSignal
2021-09-08 18:05:39 +00:00
if jsonSignal["event"].kind != JNull:
2021-09-08 20:55:37 +00:00
result.eventType = jsonSignal["event"]["type"].getStr
result.blockNumber = jsonSignal["event"]{"blockNumber"}.getInt
2021-09-10 17:27:49 +00:00
result.baseFeePerGas = jsonSignal["event"]{"baseFeePerGas"}.getStr
2021-09-08 20:55:37 +00:00
result.erc20 = jsonSignal["event"]{"erc20"}.getBool
result.accounts = @[]
2021-09-08 18:05:39 +00:00
if jsonSignal["event"]["accounts"].kind != JNull:
for account in jsonSignal["event"]["accounts"]:
2021-09-08 20:55:37 +00:00
result.accounts.add(account.getStr)
2021-09-08 18:05:39 +00:00