2020-02-27 14:32:10 +01:00
|
|
|
const axios = require('axios')
|
|
|
|
const path = require('path')
|
|
|
|
const fs = require('fs')
|
|
|
|
const files = ['withdraw.json', 'withdraw_proving_key.bin', 'Verifier.sol', 'withdraw_verification_key.json']
|
2020-08-01 04:28:14 +02:00
|
|
|
const circuitsPath = __dirname + '/../build/circuits'
|
|
|
|
const contractsPath = __dirname + '/../build/contracts'
|
2020-02-27 14:32:10 +01:00
|
|
|
|
|
|
|
async function downloadFile({ url, path }) {
|
|
|
|
const writer = fs.createWriteStream(path)
|
|
|
|
|
|
|
|
const response = await axios({
|
|
|
|
url,
|
|
|
|
method: 'GET',
|
2021-02-11 07:23:18 +01:00
|
|
|
responseType: 'stream',
|
2020-02-27 14:32:10 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
response.data.pipe(writer)
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
writer.on('finish', resolve)
|
|
|
|
writer.on('error', reject)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const release = await axios.get('https://api.github.com/repos/tornadocash/tornado-core/releases/latest')
|
|
|
|
const { assets } = release.data
|
2021-02-11 07:23:18 +01:00
|
|
|
if (!fs.existsSync(circuitsPath)) {
|
2020-02-27 14:32:10 +01:00
|
|
|
fs.mkdirSync(circuitsPath, { recursive: true })
|
|
|
|
fs.mkdirSync(contractsPath, { recursive: true })
|
|
|
|
}
|
2021-02-11 07:23:18 +01:00
|
|
|
for (let asset of assets) {
|
2020-02-27 14:32:10 +01:00
|
|
|
if (files.includes(asset.name)) {
|
|
|
|
console.log(`Downloading ${asset.name} ...`)
|
|
|
|
await downloadFile({
|
|
|
|
url: asset.browser_download_url,
|
2021-02-11 07:23:18 +01:00
|
|
|
path: path.resolve(__dirname, circuitsPath, asset.name),
|
2020-02-27 14:32:10 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|