|
@@ -21,18 +21,20 @@ app.post('/start', (req, res) => {
|
|
|
res.status(200).send('OK')
|
|
|
})
|
|
|
|
|
|
-app.post('/add', async (req, res) => {
|
|
|
+app.post('/add', express.json(), async (req, res) => {
|
|
|
const { pks } = req.body
|
|
|
- for (const pk of pks) {
|
|
|
- const wallet = new ethers.Wallet(pk)
|
|
|
- PKMapping.instance.set(wallet.address, wallet.privateKey)
|
|
|
- const account = await DBClient.instance.account.findFirst({ where: { address: wallet.address } })
|
|
|
- if (!account) {
|
|
|
- await DBClient.instance.account.create({
|
|
|
- data: { address: wallet.address, bridgeCount: 0, currentChainId: ChainId.LINEA, lastUpdate: new Date() },
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
+ const wallets = pks.map(pk => new ethers.Wallet(pk))
|
|
|
+ const accountExisted = await DBClient.instance.account.findMany({
|
|
|
+ where: { address: { in: wallets.map(w => w.address) } },
|
|
|
+ })
|
|
|
+ const needCreate = wallets.filter(w => !accountExisted.find(a => a.address === w.address))
|
|
|
+ const createData = needCreate.map(w => ({
|
|
|
+ address: w.address,
|
|
|
+ bridgeCount: 0,
|
|
|
+ currentChainId: ChainId.LINEA,
|
|
|
+ lastUpdate: new Date(),
|
|
|
+ }))
|
|
|
+ await DBClient.instance.account.createMany({ data: createData })
|
|
|
res.status(200).send(JSON.stringify({ processed: pks.length }))
|
|
|
})
|
|
|
|