2023-11-27 18:33:27 +01:00
|
|
|
{.used.}
|
|
|
|
|
2024-02-06 17:37:42 +01:00
|
|
|
import std/options, stew/results, chronos, libp2p/crypto/crypto
|
2023-11-27 18:33:27 +01:00
|
|
|
|
|
|
|
import
|
2024-07-06 03:33:38 +05:30
|
|
|
waku/[
|
2023-11-27 18:33:27 +01:00
|
|
|
node/peer_manager,
|
|
|
|
waku_core,
|
|
|
|
waku_archive,
|
|
|
|
waku_archive/common,
|
|
|
|
waku_archive/driver/sqlite_driver,
|
2024-03-16 00:08:47 +01:00
|
|
|
common/databases/db_sqlite,
|
2023-11-27 18:33:27 +01:00
|
|
|
],
|
2024-02-06 17:37:42 +01:00
|
|
|
../testlib/[wakucore]
|
2023-11-27 18:33:27 +01:00
|
|
|
|
2024-05-13 17:25:44 +02:00
|
|
|
proc newSqliteDatabase*(path: Option[string] = string.none()): SqliteDatabase =
|
|
|
|
SqliteDatabase.new(path.get(":memory:")).tryGet()
|
2023-11-27 18:33:27 +01:00
|
|
|
|
|
|
|
proc newSqliteArchiveDriver*(): ArchiveDriver =
|
|
|
|
let database = newSqliteDatabase()
|
|
|
|
SqliteDriver.new(database).tryGet()
|
|
|
|
|
|
|
|
proc newWakuArchive*(driver: ArchiveDriver): WakuArchive =
|
|
|
|
WakuArchive.new(driver).get()
|
|
|
|
|
2024-02-06 17:37:42 +01:00
|
|
|
proc put*(
|
|
|
|
driver: ArchiveDriver, pubsubTopic: PubSubTopic, msgList: seq[WakuMessage]
|
|
|
|
): ArchiveDriver =
|
2023-11-27 18:33:27 +01:00
|
|
|
for msg in msgList:
|
2024-07-12 12:19:12 -04:00
|
|
|
let _ = waitFor driver.put(computeMessageHash(pubsubTopic, msg), pubsubTopic, msg)
|
2023-12-19 15:38:43 +01:00
|
|
|
return driver
|
2023-11-27 18:33:27 +01:00
|
|
|
|
2024-02-06 17:37:42 +01:00
|
|
|
proc newArchiveDriverWithMessages*(
|
|
|
|
pubsubTopic: PubSubTopic, msgList: seq[WakuMessage]
|
|
|
|
): ArchiveDriver =
|
2023-12-19 15:38:43 +01:00
|
|
|
var driver = newSqliteArchiveDriver()
|
|
|
|
driver = driver.put(pubsubTopic, msgList)
|
2023-11-27 18:33:27 +01:00
|
|
|
return driver
|