Wires up downloading and unzipping

This commit is contained in:
benbierens 2024-03-01 14:59:24 +01:00
parent c67c2e7cd7
commit 7934d415cd
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
3 changed files with 34 additions and 6 deletions

3
.gitmodules vendored
View File

@ -209,3 +209,6 @@
url = https://github.com/codex-storage/codex-storage-proofs-circuits.git
ignore = untracked
branch = master
[submodule "vendor/zip"]
path = vendor/zip
url = https://github.com/nim-lang/zip.git

View File

@ -1,4 +1,6 @@
import os
import httpclient
import zip/zipfiles
import pkg/chronos
import pkg/questionable
import pkg/confutils/defs
@ -42,6 +44,9 @@ proc wasmFilePath(config: CodexConf): string =
proc zkeyFilePath(config: CodexConf): string =
config.dataDir / "circuit.zkey"
proc zipFilePath(config: CodexConf): string =
config.dataDir / "circuit.zip"
proc initializeFromCeremonyFiles(config: CodexConf): ?!AnyBackend =
if fileExists(config.r1csFilePath) and
fileExists(config.wasmFilePath) and
@ -53,16 +58,35 @@ proc initializeFromCeremonyFiles(config: CodexConf): ?!AnyBackend =
failure("Ceremony files not found")
proc downloadCeremonyUrl(
config: CodexConf,
proofCeremonyUrl: string
) =
var client = newHttpClient()
client.downloadFile(
"https://circuit.codex.storage/proving-key/" & proofCeremonyUrl, config.zipFilePath)
proc unzipCeremonyFile(
config: CodexConf): ?!void =
var z: ZipArchive
if not z.open(config.zipFilePath):
return failure("Unable to open zip file: " & config.zipFilePath)
z.extractAll($config.dataDir)
success()
proc initializeFromCeremonyUrl(
config: CodexConf,
proofCeremonyUrl: ?string): Future[?!AnyBackend] {.async.} =
# download the ceremony url
# unzip it
without backend =? initializeFromCeremonyFiles(config), err:
return failure(err)
return success(backend)
if url =? proofCeremonyUrl:
downloadCeremonyUrl(config, url)
if err =? unzipCeremonyFile(config).errorOption:
return failure(err)
without backend =? initializeFromCeremonyFiles(config), err:
return failure(err)
return success(backend)
else:
return failure("Ceremony URL not found")
proc initializeBackend*(
config: CodexConf,

1
vendor/zip vendored Submodule

@ -0,0 +1 @@
Subproject commit 06f5b0a0767b14c7595ed168611782be69e61543