mirror of
https://github.com/tornadocash/trusted-setup-server.git
synced 2024-11-22 09:56:53 +01:00
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
const db = require('./db.js')
|
|
const crypto = require('crypto')
|
|
|
|
let sql
|
|
const Contributions = { }
|
|
|
|
Contributions.currentContributionIndex = async function() {
|
|
const [rows,] = await sql.query('select max(id) as max from contributions')
|
|
return (rows[0].max || 0) + 1
|
|
}
|
|
|
|
Contributions.insertContributionInfo = async function(name, company) {
|
|
const token = crypto.randomBytes(32).toString('hex')
|
|
await sql.execute(
|
|
'insert into contributions(token, name, company) values(?, ?, ?)',
|
|
[token, name, company]
|
|
)
|
|
}
|
|
|
|
Contributions.updateContributionInfo = async function(token, name, company) {
|
|
await sql.execute(
|
|
'insert into contributions(token, name, company) values(?, ?, ?)',
|
|
[token, name, company]
|
|
)
|
|
}
|
|
|
|
Contributions.getContributions = async function() {
|
|
const [rows,] = await db.execute('select id, name, company from contributions')
|
|
return rows
|
|
}
|
|
|
|
|
|
async function main () {
|
|
({ sql } = await db())
|
|
const contribitionIndex = await Contributions.currentContributionIndex()
|
|
console.log('Next contribution index is', contribitionIndex)
|
|
}
|
|
main()
|
|
|
|
module.exports = Contributions |