From 7934d415cde61407f40b542c25ed9a258776a33a Mon Sep 17 00:00:00 2001 From: benbierens Date: Fri, 1 Mar 2024 14:59:24 +0100 Subject: [PATCH] Wires up downloading and unzipping --- .gitmodules | 3 +++ codex/slots/proofs/backendfactory.nim | 36 ++++++++++++++++++++++----- vendor/zip | 1 + 3 files changed, 34 insertions(+), 6 deletions(-) create mode 160000 vendor/zip diff --git a/.gitmodules b/.gitmodules index ad4e4792..b4a9c9f6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/codex/slots/proofs/backendfactory.nim b/codex/slots/proofs/backendfactory.nim index dd048e85..e9f55093 100644 --- a/codex/slots/proofs/backendfactory.nim +++ b/codex/slots/proofs/backendfactory.nim @@ -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, diff --git a/vendor/zip b/vendor/zip new file mode 160000 index 00000000..06f5b0a0 --- /dev/null +++ b/vendor/zip @@ -0,0 +1 @@ +Subproject commit 06f5b0a0767b14c7595ed168611782be69e61543