diff --git a/.env.example b/.env.example index d93a5c2..ec6a347 100644 --- a/.env.example +++ b/.env.example @@ -4,10 +4,13 @@ AWS_S3_BUCKET= DISABLE_S3=false MYSQL_USER=root -MYSQL_PASSWORD=secret +MYSQL_PASSWORD=webmailpasswd MYSQL_DATABASE=phase2 TWITTER_CONSUMER_KEY= TWITTER_CONSUMER_SECRET= TWITTER_CALLBACK_URL=http://localhost:3000/api/twitter_callback SESSION_SECRET= + +NUXT_HOST=0.0.0.0 +NUXT_PORT=3000 diff --git a/Dockerfile b/Dockerfile index 81552e9..5a24121 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,15 @@ +FROM tornadocash/phase2-bn254 as bin + FROM node:11 WORKDIR /app -COPY package.json package-lock.json ./ -RUN npm install && npm cache clean --force +COPY package.json yarn.lock ./ +RUN yarn install && yarn cache clean --force COPY . . +COPY --from=bin /usr/bin/phase2_verify_contribution /app/bin/ + EXPOSE 3000 HEALTHCHECK CMD curl -f http://localhost:3000/ -CMD ["npm", "run", "start"] +RUN yarn build +CMD ["yarn", "start"] diff --git a/docker-compose.yml b/docker-compose.yml index c0aee49..21f87df 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,13 +4,13 @@ services: build: . restart: always environment: - VIRTUAL_HOST: trustedaf.poma.in - LETSENCRYPT_HOST: trustedaf.poma.in + VIRTUAL_HOST: ceremony.tornado.cash + LETSENCRYPT_HOST: ceremony.tornado.cash nginx_client_max_body_size: 50m MYSQL_HOST: mysql env_file: .env - volumes: - - /data/powers/verify_contribution:/app/verify_contribution + depends_on: + - mysql mysql: image: mysql:5.7 @@ -27,4 +27,4 @@ volumes: networks: default: external: - name: frontend_default \ No newline at end of file + name: frontend_default diff --git a/nuxt.config.js b/nuxt.config.js index 139b2e8..01a06a5 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -99,7 +99,12 @@ module.exports = { ** Axios module configuration ** See https://axios.nuxtjs.org/options */ - axios: {}, + axios: { + baseURL: + process.env.NODE_ENV === 'production' + ? 'http://ceremony.tornado.cash/' + : `http://localhost:3000/` + }, /* ** Build configuration */ diff --git a/seed.sql b/seed.sql new file mode 100644 index 0000000..d054cc5 --- /dev/null +++ b/seed.sql @@ -0,0 +1,13 @@ +create table contributions +( + id int auto_increment, + token varchar(64) not null, + name varchar(255) null, + company varchar(255) null, + hash varchar(130) null, + + constraint contributions_pk + primary key (id) +); + +create unique index contributions_token_uindex on contributions (token); diff --git a/server/bin/verify_contribution b/server/bin/phase2_verify_contribution similarity index 100% rename from server/bin/verify_contribution rename to server/bin/phase2_verify_contribution diff --git a/server/controllers/contributions.js b/server/controllers/contributions.js index 9acadb9..0c2f0c2 100644 --- a/server/controllers/contributions.js +++ b/server/controllers/contributions.js @@ -29,7 +29,7 @@ async function uploadToS3({ filename }) { async function verifyResponse({ filename }) { console.log('Running verifier') const { stdout, stderr } = await exec( - `../bin/verify_contribution circuit.json current.params /tmp/tornado/${filename}`, + `../bin/phase2_verify_contribution circuit.json current.params /tmp/tornado/${filename}`, { cwd: './server/snark_files/', env: { RUST_BACKTRACE: 1 } diff --git a/server/models/contributions.model.js b/server/models/contributions.model.js index d02fe4c..2e135b8 100644 --- a/server/models/contributions.model.js +++ b/server/models/contributions.model.js @@ -1,4 +1,5 @@ const crypto = require('crypto') +const fs = require('fs') const db = require('./db.js') let sql @@ -33,6 +34,18 @@ Contributions.getContributions = async function() { async function main() { ;({ sql } = await db()) + + const [rows] = await sql.query("show tables like 'contributions'") + if (rows.length === 0) { + console.log('Database appears to be empty, creating tables') + const sqlFile = await fs.readFileSync('seed.sql') + for (const s of sqlFile.toString().split(';')) { + if (s.trim().length > 0) { + await sql.query(s) + } + } + } + const contribitionIndex = await Contributions.currentContributionIndex() console.log('Next contribution index is', contribitionIndex) } diff --git a/server/models/db.js b/server/models/db.js index 0645e7e..ab13881 100644 --- a/server/models/db.js +++ b/server/models/db.js @@ -16,7 +16,6 @@ const mysql = require('mysql2/promise') // currentContributionIndex = (rows[0].max || 0) + 1 // console.log('Current contribution index:', currentContributionIndex) - module.exports = async function() { this.sql = await mysql.createPool({ host: process.env.MYSQL_HOST || 'localhost', @@ -28,4 +27,4 @@ module.exports = async function() { }) return this -} \ No newline at end of file +} diff --git a/server/snark_files/current.params b/server/snark_files/current.params index c8960fe..050fbc6 100644 Binary files a/server/snark_files/current.params and b/server/snark_files/current.params differ