增加账号删除的功能
This commit is contained in:
parent
0141093817
commit
d1f3fed196
1
pm2_release.sh
Executable file
1
pm2_release.sh
Executable file
@ -0,0 +1 @@
|
|||||||
|
pm2 start npm --name "wallet-svr" --log-date-format "YYYY-MM-DD HH:mm:ss" -- run "prod:api"
|
@ -22,7 +22,7 @@ let errorRes = function (msg: string) {
|
|||||||
* for Alchemy call
|
* for Alchemy call
|
||||||
*/
|
*/
|
||||||
class AlchemyOutController extends BaseController {
|
class AlchemyOutController extends BaseController {
|
||||||
@role(ROLE_ANON)
|
// @role(ROLE_ANON)
|
||||||
// @router('post /pay/out/alchemy/buycb')
|
// @router('post /pay/out/alchemy/buycb')
|
||||||
async alchemyCallback(req, res) {
|
async alchemyCallback(req, res) {
|
||||||
let { orderNo, status, crypto, network, merchantOrderNo } = req.params
|
let { orderNo, status, crypto, network, merchantOrderNo } = req.params
|
||||||
|
@ -13,7 +13,7 @@ class MainController extends BaseController {
|
|||||||
|
|
||||||
@router('post /wallet/account/reset')
|
@router('post /wallet/account/reset')
|
||||||
async resetAccount(req, res) {
|
async resetAccount(req, res) {
|
||||||
const user = req.user
|
let user = req.user
|
||||||
await user.updateOne({ $inc: { accountVersion: 1 } })
|
await user.updateOne({ $inc: { accountVersion: 1 } })
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import { ZError } from 'common/ZError'
|
|||||||
import { router } from 'decorators/router'
|
import { router } from 'decorators/router'
|
||||||
|
|
||||||
import { Wallet } from 'modules/Wallet'
|
import { Wallet } from 'modules/Wallet'
|
||||||
|
import { WalletBackup } from 'modules/WalletBackup'
|
||||||
import { WalletExt } from 'modules/WalletExt'
|
import { WalletExt } from 'modules/WalletExt'
|
||||||
import { customAlphabet } from 'nanoid'
|
import { customAlphabet } from 'nanoid'
|
||||||
import { genRandomString, sha3_256, sha512 } from 'utils/security.util'
|
import { genRandomString, sha3_256, sha512 } from 'utils/security.util'
|
||||||
@ -66,8 +67,19 @@ class WalletController extends BaseController {
|
|||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@router('post /wallet/rest')
|
@router('post /wallet/reset')
|
||||||
async resetWalletInfo(req, res) {
|
async resetWalletInfo(req, res) {
|
||||||
|
let user = req.user
|
||||||
|
let record = await Wallet.findOne({ account: user.id })
|
||||||
|
if (!record) {
|
||||||
|
throw new ZError(11, 'no wallet found')
|
||||||
|
}
|
||||||
|
let data: any = record.toJson()
|
||||||
|
data.account = user.id
|
||||||
|
let recordBack = new WalletBackup(data)
|
||||||
|
await recordBack.save()
|
||||||
|
record.address = ''
|
||||||
|
await record.save()
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
40
src/modules/WalletBackup.ts
Normal file
40
src/modules/WalletBackup.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { getModelForClass, index, modelOptions, mongoose, prop, Severity } from '@typegoose/typegoose'
|
||||||
|
import { dbconn } from 'decorators/dbconn'
|
||||||
|
import { BaseModule } from './Base'
|
||||||
|
|
||||||
|
@dbconn()
|
||||||
|
@index({ account: 1 }, { unique: false })
|
||||||
|
@modelOptions({
|
||||||
|
schemaOptions: { collection: 'wallet_backup', timestamps: true },
|
||||||
|
})
|
||||||
|
class WalletBackupClass extends BaseModule {
|
||||||
|
@prop({ required: true })
|
||||||
|
public account!: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 钱包的master key
|
||||||
|
*/
|
||||||
|
@prop()
|
||||||
|
public key: string
|
||||||
|
|
||||||
|
@prop()
|
||||||
|
public address: string
|
||||||
|
/**
|
||||||
|
* 用于客户端生成密钥时的加盐
|
||||||
|
*/
|
||||||
|
@prop()
|
||||||
|
public salt: string
|
||||||
|
|
||||||
|
@prop({ required: true, default: true })
|
||||||
|
public nweRecord: boolean
|
||||||
|
|
||||||
|
public toJson() {
|
||||||
|
return {
|
||||||
|
key: this.key,
|
||||||
|
address: this.address,
|
||||||
|
salt: this.salt,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const WalletBackup = getModelForClass(WalletBackupClass, { existingConnection: WalletBackupClass.db })
|
Loading…
x
Reference in New Issue
Block a user