2023-11-27 17:33:27 +00:00
|
|
|
{.used.}
|
|
|
|
|
2024-02-06 16:37:42 +00:00
|
|
|
import std/options, stew/results, chronos, libp2p/crypto/crypto
|
2023-11-27 17:33:27 +00:00
|
|
|
|
|
|
|
import
|
|
|
|
../../../waku/[
|
|
|
|
node/peer_manager,
|
|
|
|
waku_core,
|
|
|
|
waku_archive,
|
|
|
|
waku_archive/common,
|
|
|
|
waku_archive/driver/sqlite_driver,
|
2024-03-15 23:08:47 +00:00
|
|
|
common/databases/db_sqlite,
|
2023-11-27 17:33:27 +00:00
|
|
|
],
|
2024-02-06 16:37:42 +00:00
|
|
|
../testlib/[wakucore]
|
2023-11-27 17:33:27 +00:00
|
|
|
|
|
|
|
proc newSqliteDatabase*(): SqliteDatabase =
|
|
|
|
SqliteDatabase.new(":memory:").tryGet()
|
|
|
|
|
|
|
|
proc newSqliteArchiveDriver*(): ArchiveDriver =
|
|
|
|
let database = newSqliteDatabase()
|
|
|
|
SqliteDriver.new(database).tryGet()
|
|
|
|
|
|
|
|
proc newWakuArchive*(driver: ArchiveDriver): WakuArchive =
|
|
|
|
WakuArchive.new(driver).get()
|
|
|
|
|
2024-02-06 16:37:42 +00:00
|
|
|
proc computeArchiveCursor*(
|
|
|
|
pubsubTopic: PubsubTopic, message: WakuMessage
|
|
|
|
): ArchiveCursor =
|
2023-11-27 17:33:27 +00:00
|
|
|
ArchiveCursor(
|
|
|
|
pubsubTopic: pubsubTopic,
|
|
|
|
senderTime: message.timestamp,
|
|
|
|
storeTime: message.timestamp,
|
2024-03-12 11:51:03 +00:00
|
|
|
digest: computeDigest(message),
|
|
|
|
hash: computeMessageHash(pubsubTopic, message),
|
2023-11-27 17:33:27 +00:00
|
|
|
)
|
|
|
|
|
2024-02-06 16:37:42 +00:00
|
|
|
proc put*(
|
|
|
|
driver: ArchiveDriver, pubsubTopic: PubSubTopic, msgList: seq[WakuMessage]
|
|
|
|
): ArchiveDriver =
|
2023-11-27 17:33:27 +00:00
|
|
|
for msg in msgList:
|
2024-02-06 16:37:42 +00:00
|
|
|
let
|
2024-03-12 11:51:03 +00:00
|
|
|
msgDigest = computeDigest(msg)
|
2023-11-27 17:33:27 +00:00
|
|
|
msgHash = computeMessageHash(pubsubTopic, msg)
|
2024-02-06 16:37:42 +00:00
|
|
|
_ = waitFor driver.put(pubsubTopic, msg, msgDigest, msgHash, msg.timestamp)
|
2024-03-15 23:08:47 +00:00
|
|
|
# discard crashes
|
2023-12-19 14:38:43 +00:00
|
|
|
return driver
|
2023-11-27 17:33:27 +00:00
|
|
|
|
2024-02-06 16:37:42 +00:00
|
|
|
proc newArchiveDriverWithMessages*(
|
|
|
|
pubsubTopic: PubSubTopic, msgList: seq[WakuMessage]
|
|
|
|
): ArchiveDriver =
|
2023-12-19 14:38:43 +00:00
|
|
|
var driver = newSqliteArchiveDriver()
|
|
|
|
driver = driver.put(pubsubTopic, msgList)
|
2023-11-27 17:33:27 +00:00
|
|
|
return driver
|