2023-11-27 17:33:27 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
|
|
|
std/options,
|
|
|
|
chronos,
|
|
|
|
libp2p/crypto/crypto
|
|
|
|
|
|
|
|
import
|
|
|
|
../../../waku/[
|
|
|
|
node/peer_manager,
|
|
|
|
waku_core,
|
|
|
|
waku_archive,
|
|
|
|
waku_archive/common,
|
|
|
|
waku_archive/driver/sqlite_driver,
|
2023-12-19 14:38:43 +00:00
|
|
|
common/databases/db_sqlite
|
2023-11-27 17:33:27 +00:00
|
|
|
],
|
|
|
|
../testlib/[
|
|
|
|
wakucore
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
proc computeArchiveCursor*(pubsubTopic: PubsubTopic, message: WakuMessage): ArchiveCursor =
|
|
|
|
ArchiveCursor(
|
|
|
|
pubsubTopic: pubsubTopic,
|
|
|
|
senderTime: message.timestamp,
|
|
|
|
storeTime: message.timestamp,
|
|
|
|
digest: waku_archive.computeDigest(message)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-12-19 14:38:43 +00:00
|
|
|
proc put*(driver: ArchiveDriver, pubsubTopic: PubSubTopic, msgList: seq[WakuMessage]): ArchiveDriver =
|
2023-11-27 17:33:27 +00:00
|
|
|
for msg in msgList:
|
|
|
|
let
|
|
|
|
msgDigest = waku_archive.computeDigest(msg)
|
|
|
|
msgHash = computeMessageHash(pubsubTopic, msg)
|
|
|
|
discard waitFor driver.put(pubsubTopic, msg, msgDigest, msgHash, msg.timestamp)
|
2023-12-19 14:38:43 +00:00
|
|
|
return driver
|
2023-11-27 17:33:27 +00:00
|
|
|
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
proc newArchiveDriverWithMessages*(pubsubTopic: PubSubTopic, msgList: seq[WakuMessage]): ArchiveDriver =
|
|
|
|
var driver = newSqliteArchiveDriver()
|
|
|
|
driver = driver.put(pubsubTopic, msgList)
|
2023-11-27 17:33:27 +00:00
|
|
|
return driver
|