rename seckey to prikey

This commit is contained in:
Luk Lu
2022-08-14 15:52:12 +08:00
parent 3dee1c63dd
commit 173805f7b7
3 changed files with 172 additions and 151 deletions

View File

@@ -1,42 +1,45 @@
'use strict';
'use strict'
// 该脚本只用于系统账户对用户进行提现转账
const { ERC20 } = require('../utils/erc20');
const { inject } = require('./Provider');
const { ERC20 } = require('../utils/erc20')
const { inject } = require('./Provider')
// const { USDTAddr } = require('./constant');
const crypto = require('../utils/crypto');
const crypto = require('../utils/crypto')
const ROOTSECWORD = inject(function (SysConfig) {
const { ROOTSECWORD } = SysConfig;
return ROOTSECWORD;
});
const { ROOTSECWORD } = SysConfig
return ROOTSECWORD
})
const VICCONTRACTADDR = inject(function (SysConfig) {
const { VICCONTRACTADDR } = SysConfig;
return VICCONTRACTADDR;
});
const { VICCONTRACTADDR } = SysConfig
return VICCONTRACTADDR
})
const VICSECWORD = inject(function (SysConfig) {
const { VICSECWORD } = SysConfig;
return VICSECWORD;
});
const { VICSECWORD } = SysConfig
return VICSECWORD
})
module.exports = {
async sendUSDT2User (toAddress, amount, option = {}) {
const { path } = option;
const kp = crypto.secword2keypair(ROOTSECWORD, { path });
const account = new ERC20(kp.seckey);
return await account.transfer(toAddress, amount, option);
},
async sendVIC2User (toAddress, amount, option = {}) {
const account = ERC20.fromMnemonic(VICSECWORD, VICCONTRACTADDR);
return await account.transfer(toAddress, amount, Object.assign(option, { decimals: 18 })).then(res => {
return {
success: true,
res
};
}).catch(err => {
return {
error: err,
res: null
};
});
}
};
async sendUSDT2User (toAddress, amount, option = {}) {
const { path } = option
const kp = crypto.secword2keypair(ROOTSECWORD, { path })
const account = new ERC20(kp.prikey)
return await account.transfer(toAddress, amount, option)
},
async sendVIC2User (toAddress, amount, option = {}) {
const account = ERC20.fromMnemonic(VICSECWORD, VICCONTRACTADDR)
return await account
.transfer(toAddress, amount, Object.assign(option, { decimals: 18 }))
.then(res => {
return {
success: true,
res
}
})
.catch(err => {
return {
error: err,
res: null
}
})
}
}