mirror of
https://github.com/tornadocash/trusted-setup-server.git
synced 2025-02-14 21:10:45 +01:00
s3
This commit is contained in:
parent
0a261626c8
commit
5a51b659b5
@ -1,6 +1,7 @@
|
|||||||
AWS_ACCESS_KEY_ID=
|
AWS_ACCESS_KEY_ID=
|
||||||
AWS_SECRET_ACCESS_KEY=
|
AWS_SECRET_ACCESS_KEY=
|
||||||
AWS_S3_BUCKET=
|
AWS_S3_BUCKET=
|
||||||
|
DISABLE_S3=false
|
||||||
|
|
||||||
MYSQL_USER=root
|
MYSQL_USER=root
|
||||||
MYSQL_PASSWORD=secret
|
MYSQL_PASSWORD=secret
|
||||||
|
@ -53,6 +53,9 @@
|
|||||||
<b-button
|
<b-button
|
||||||
v-if="isContributeBtnDisabled && status.type === 'is-success'"
|
v-if="isContributeBtnDisabled && status.type === 'is-success'"
|
||||||
type="is-primary"
|
type="is-primary"
|
||||||
|
tag="a"
|
||||||
|
href="https://twitter.com/intent/tweet?text=Hello%20world"
|
||||||
|
target="_blank"
|
||||||
outlined
|
outlined
|
||||||
>
|
>
|
||||||
Tweet about your contribution
|
Tweet about your contribution
|
||||||
|
@ -1,28 +1,30 @@
|
|||||||
// const aws = require('aws-sdk')
|
|
||||||
// const s3 = new aws.S3()
|
|
||||||
const fs = require('fs').promises
|
const fs = require('fs').promises
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const util = require('util')
|
const util = require('util')
|
||||||
const exec = util.promisify(require('child_process').exec)
|
const exec = util.promisify(require('child_process').exec)
|
||||||
|
const aws = require('aws-sdk')
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const router = express.Router()
|
|
||||||
const { Mutex } = require('async-mutex')
|
const { Mutex } = require('async-mutex')
|
||||||
const mutex = new Mutex()
|
|
||||||
const multer = require('multer')
|
const multer = require('multer')
|
||||||
|
|
||||||
|
const mutex = new Mutex()
|
||||||
|
const s3 = new aws.S3()
|
||||||
|
const router = express.Router()
|
||||||
const Contribution = require('../models/contributions.model.js')
|
const Contribution = require('../models/contributions.model.js')
|
||||||
const upload = multer({ dest: '/tmp/tornado' })
|
const upload = multer({ dest: '/tmp/tornado' })
|
||||||
|
|
||||||
// async function uploadToS3(response) {
|
async function uploadToS3({ filename }) {
|
||||||
// const currentContributionIndex = await Contribution.currentContributionIndex()
|
const currentContributionIndex = await Contribution.currentContributionIndex()
|
||||||
// return await s3
|
const fileContent = await fs.readFile(`/tmp/tornado/${filename}`)
|
||||||
// .upload({
|
return s3
|
||||||
// Bucket: process.env.AWS_S3_BUCKET,
|
.upload({
|
||||||
// Key: `response_${currentContributionIndex}`,
|
Bucket: process.env.AWS_S3_BUCKET,
|
||||||
// ACL: 'public-read',
|
Key: `response_${currentContributionIndex}`,
|
||||||
// Body: response
|
ACL: 'public-read',
|
||||||
// })
|
Body: fileContent
|
||||||
// .promise()
|
})
|
||||||
// }
|
.promise()
|
||||||
|
}
|
||||||
|
|
||||||
async function verifyResponse({ filename }) {
|
async function verifyResponse({ filename }) {
|
||||||
console.log('Running verifier')
|
console.log('Running verifier')
|
||||||
@ -56,7 +58,6 @@ router.post('/response', upload.single('response'), async (req, res) => {
|
|||||||
const currentContributionIndex = await Contribution.currentContributionIndex()
|
const currentContributionIndex = await Contribution.currentContributionIndex()
|
||||||
try {
|
try {
|
||||||
console.log(`Started processing contribution ${currentContributionIndex}`)
|
console.log(`Started processing contribution ${currentContributionIndex}`)
|
||||||
// await fs.writeFile('/tmp/new.params', req.file.response.data)
|
|
||||||
await verifyResponse({ filename: req.file.filename })
|
await verifyResponse({ filename: req.file.filename })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error', e)
|
console.error('Error', e)
|
||||||
@ -66,11 +67,9 @@ router.post('/response', upload.single('response'), async (req, res) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('Contribution is correct, uploading to storage')
|
console.log('Contribution is correct, uploading to storage')
|
||||||
// await uploadToS3(req.files.response.data)
|
if (process.env.DISABLE_S3 !== 'true') {
|
||||||
// await fs.copyFile(
|
await uploadToS3({ filename: req.file.filename })
|
||||||
// '/tmp/new.params',
|
}
|
||||||
// `./snark_files/response_${currentContributionIndex}`
|
|
||||||
// )
|
|
||||||
|
|
||||||
console.log('Committing changes')
|
console.log('Committing changes')
|
||||||
await fs.rename(`/tmp/tornado/${req.file.filename}`, './server/snark_files/current.params')
|
await fs.rename(`/tmp/tornado/${req.file.filename}`, './server/snark_files/current.params')
|
||||||
|
@ -1,40 +1,41 @@
|
|||||||
const db = require('./db.js')
|
|
||||||
const crypto = require('crypto')
|
const crypto = require('crypto')
|
||||||
|
const db = require('./db.js')
|
||||||
|
|
||||||
let sql
|
let sql
|
||||||
const Contributions = { }
|
const Contributions = {}
|
||||||
|
|
||||||
Contributions.currentContributionIndex = async function() {
|
Contributions.currentContributionIndex = async function() {
|
||||||
const [rows,] = await sql.query('select max(id) as max from contributions')
|
const [rows] = await sql.query('select max(id) as max from contributions')
|
||||||
return (rows[0].max || 0) + 1
|
return (rows[0].max || 0) + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Contributions.insertContributionInfo = async function(name, company) {
|
Contributions.insertContributionInfo = async function(name, company) {
|
||||||
const token = crypto.randomBytes(32).toString('hex')
|
const token = crypto.randomBytes(32).toString('hex')
|
||||||
await sql.execute(
|
await sql.execute('insert into contributions(token, name, company) values(?, ?, ?)', [
|
||||||
'insert into contributions(token, name, company) values(?, ?, ?)',
|
token,
|
||||||
[token, name, company]
|
name,
|
||||||
)
|
company
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
Contributions.updateContributionInfo = async function(token, name, company) {
|
Contributions.updateContributionInfo = async function(token, name, company) {
|
||||||
await sql.execute(
|
await sql.execute('insert into contributions(token, name, company) values(?, ?, ?)', [
|
||||||
'insert into contributions(token, name, company) values(?, ?, ?)',
|
token,
|
||||||
[token, name, company]
|
name,
|
||||||
)
|
company
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
Contributions.getContributions = async function() {
|
Contributions.getContributions = async function() {
|
||||||
const [rows,] = await db.execute('select id, name, company from contributions')
|
const [rows] = await db.execute('select id, name, company from contributions')
|
||||||
return rows
|
return rows
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
async function main () {
|
;({ sql } = await db())
|
||||||
({ sql } = await db())
|
|
||||||
const contribitionIndex = await Contributions.currentContributionIndex()
|
const contribitionIndex = await Contributions.currentContributionIndex()
|
||||||
console.log('Next contribution index is', contribitionIndex)
|
console.log('Next contribution index is', contribitionIndex)
|
||||||
}
|
}
|
||||||
main()
|
main()
|
||||||
|
|
||||||
module.exports = Contributions
|
module.exports = Contributions
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user