Wires up downloading and unzipping
This commit is contained in:
parent
c67c2e7cd7
commit
7934d415cd
|
@ -209,3 +209,6 @@
|
||||||
url = https://github.com/codex-storage/codex-storage-proofs-circuits.git
|
url = https://github.com/codex-storage/codex-storage-proofs-circuits.git
|
||||||
ignore = untracked
|
ignore = untracked
|
||||||
branch = master
|
branch = master
|
||||||
|
[submodule "vendor/zip"]
|
||||||
|
path = vendor/zip
|
||||||
|
url = https://github.com/nim-lang/zip.git
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import os
|
import os
|
||||||
|
import httpclient
|
||||||
|
import zip/zipfiles
|
||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
import pkg/questionable
|
import pkg/questionable
|
||||||
import pkg/confutils/defs
|
import pkg/confutils/defs
|
||||||
|
@ -42,6 +44,9 @@ proc wasmFilePath(config: CodexConf): string =
|
||||||
proc zkeyFilePath(config: CodexConf): string =
|
proc zkeyFilePath(config: CodexConf): string =
|
||||||
config.dataDir / "circuit.zkey"
|
config.dataDir / "circuit.zkey"
|
||||||
|
|
||||||
|
proc zipFilePath(config: CodexConf): string =
|
||||||
|
config.dataDir / "circuit.zip"
|
||||||
|
|
||||||
proc initializeFromCeremonyFiles(config: CodexConf): ?!AnyBackend =
|
proc initializeFromCeremonyFiles(config: CodexConf): ?!AnyBackend =
|
||||||
if fileExists(config.r1csFilePath) and
|
if fileExists(config.r1csFilePath) and
|
||||||
fileExists(config.wasmFilePath) and
|
fileExists(config.wasmFilePath) and
|
||||||
|
@ -53,16 +58,35 @@ proc initializeFromCeremonyFiles(config: CodexConf): ?!AnyBackend =
|
||||||
|
|
||||||
failure("Ceremony files not found")
|
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(
|
proc initializeFromCeremonyUrl(
|
||||||
config: CodexConf,
|
config: CodexConf,
|
||||||
proofCeremonyUrl: ?string): Future[?!AnyBackend] {.async.} =
|
proofCeremonyUrl: ?string): Future[?!AnyBackend] {.async.} =
|
||||||
|
|
||||||
# download the ceremony url
|
if url =? proofCeremonyUrl:
|
||||||
# unzip it
|
downloadCeremonyUrl(config, url)
|
||||||
|
if err =? unzipCeremonyFile(config).errorOption:
|
||||||
without backend =? initializeFromCeremonyFiles(config), err:
|
return failure(err)
|
||||||
return failure(err)
|
without backend =? initializeFromCeremonyFiles(config), err:
|
||||||
return success(backend)
|
return failure(err)
|
||||||
|
return success(backend)
|
||||||
|
else:
|
||||||
|
return failure("Ceremony URL not found")
|
||||||
|
|
||||||
proc initializeBackend*(
|
proc initializeBackend*(
|
||||||
config: CodexConf,
|
config: CodexConf,
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 06f5b0a0767b14c7595ed168611782be69e61543
|
Loading…
Reference in New Issue