main.ts 972 B

1234567891011121314151617181920212223242526272829
  1. import express from 'express'
  2. import { PKMapping } from './singletons'
  3. import { ethers, getIndexedAccountPath } from 'ethers'
  4. import { CreateBridgeTaskJob } from './jobs/CreateBridgeTaskJob'
  5. import { BridgeJob } from './jobs/BridgeJob'
  6. import { ConfirmJob } from './jobs/ConfirmJob'
  7. const app = express()
  8. const port = 9900
  9. app.use(express.json())
  10. app.post('/start', (req, res) => {
  11. const { phrases, count } = req.body
  12. const generateCount = count ?? 500
  13. if (!phrases) throw new Error('phrases is required')
  14. PKMapping.instance.clear()
  15. for (let i = 0; i < generateCount; i++) {
  16. const wallet = ethers.HDNodeWallet.fromPhrase(phrases, null, getIndexedAccountPath(i))
  17. PKMapping.instance.set(wallet.address, wallet.privateKey)
  18. }
  19. res.send('OK')
  20. })
  21. app.listen(port, () => {
  22. console.log(`start listening at http://localhost:${port}`)
  23. })
  24. new CreateBridgeTaskJob().start('*/5 * * * *')
  25. new BridgeJob().start('* * * * *')
  26. new ConfirmJob().start('* * * * *')