mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-02-16 20:13:26 +00:00
Update library to work with Libchat
This commit is contained in:
parent
3fab891d47
commit
bcfd98eb2a
@ -71,9 +71,9 @@ proc DefaultConfig*(): WakuConfig =
|
||||
shardId: @[shardId], pubsubTopic: &"/waku/2/rs/{clusterId}/{shardId}",
|
||||
staticPeers: @[])
|
||||
|
||||
proc sendPayload*(client: WakuClient, contentTopic: string,
|
||||
env: WapEnvelopeV1) {.async.} =
|
||||
let bytes = encode(env)
|
||||
|
||||
proc sendBytes*(client: WakuClient, contentTopic: string,
|
||||
bytes: seq[byte]) {.async.} =
|
||||
|
||||
let msg = WakuMessage(contentTopic: contentTopic, payload: bytes)
|
||||
let res = await client.node.publish(some(PubsubTopic(client.cfg.pubsubTopic)), msg)
|
||||
|
||||
@ -9,6 +9,7 @@ type
|
||||
errTypeError
|
||||
errWrapped
|
||||
errTopic
|
||||
errLibChat
|
||||
|
||||
proc `$`*(x: ChatError): string =
|
||||
fmt"ChatError(code={$x.code}, context: {x.context})"
|
||||
|
||||
@ -32,6 +32,13 @@ proc getPubkey*(self: Identity): PublicKey =
|
||||
proc getAddr*(self: Identity): string =
|
||||
result = get_addr(self.getPubKey())
|
||||
|
||||
|
||||
proc getName*(self: Identity): string =
|
||||
result = self.name
|
||||
|
||||
proc toHex(key: PublicKey): string =
|
||||
bytesToHex(key.bytes())
|
||||
|
||||
proc `$`*(key: PublicKey): string =
|
||||
let byteStr = toHex(key)
|
||||
fmt"{byteStr[0..3]}..{byteStr[^4 .. ^1]}"
|
||||
|
||||
|
||||
@ -6,7 +6,6 @@ import strutils
|
||||
proc getCurrentTimestamp*(): Timestamp =
|
||||
result = waku_core.getNanosecondTime(getTime().toUnix())
|
||||
|
||||
|
||||
proc hash_func*(s: string | seq[byte]): string =
|
||||
# This should be Blake2s but it does not exist so substituting with Blake2b
|
||||
result = getBlake2b(s, 4, "")
|
||||
@ -17,17 +16,3 @@ proc bytesToHex*[T](bytes: openarray[T], lowercase: bool = false): string =
|
||||
for b in bytes:
|
||||
let hex = b.toHex(2)
|
||||
result.add(if lowercase: hex.toLower() else: hex)
|
||||
|
||||
proc toBytes*(s: string): seq[byte] =
|
||||
result = cast[seq[byte]](s)
|
||||
|
||||
proc toUtfString*(b: seq[byte]): string =
|
||||
result = cast[string](b)
|
||||
|
||||
macro panic*(reason: string): untyped =
|
||||
result = quote do:
|
||||
let pos = instantiationInfo()
|
||||
echo `reason` & " ($1:$2)" % [
|
||||
pos.filename, $pos.line]
|
||||
echo "traceback:\n", getStackTrace()
|
||||
quit(1)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user