change sth
This commit is contained in:
parent
fbb4471f07
commit
1fbed03c62
@ -143,13 +143,19 @@ export class ERC20Reactor {
|
||||
const contract = new w3.eth.Contract(abiFt, address, { from: account || this.account.address })
|
||||
const amountBN = Web3.utils.toBN(Web3.utils.toWei(amount + ''))
|
||||
if (encodeABI) {
|
||||
if (from === this.account.address) return contract.methods.transfer(to, amountBN).encodeABI()
|
||||
return contract.methods.transferFrom(from, to, amountBN).encodeABI()
|
||||
}
|
||||
let gasEstimate =
|
||||
from === this.account.address
|
||||
? await contract.methods.transfer(to, 0).estimateGas()
|
||||
: await contract.methods.transferFrom(from, to, 0).estimateGas()
|
||||
if (estimate) {
|
||||
return contract.methods.transferFrom(from, to, 0).estimateGas()
|
||||
return gasEstimate
|
||||
}
|
||||
if (from === this.account.address) return contract.methods.transfer(to, amountBN).send({ gas: gas || gasEstimate })
|
||||
return contract.methods.transferFrom(from, to, amountBN).send({
|
||||
gas: gas || 1000000,
|
||||
gas: gas || gasEstimate,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import { InfoSvr } from 'service/info.service'
|
||||
|
||||
import { BaseModule } from './Base'
|
||||
import { ReqTaskStatus, RequestTask } from './RequestTask'
|
||||
import { PriceSvr } from 'service/price.service'
|
||||
|
||||
export enum TaskStatus {
|
||||
NOTSTART = 0,
|
||||
@ -79,7 +80,7 @@ export class ChainTaskClass extends BaseModule {
|
||||
errCount += 1
|
||||
}
|
||||
if (subData.gasUsed) {
|
||||
record += subData.gasUsed
|
||||
record.gas += subData.gasUsed
|
||||
}
|
||||
hashList.push(subData.txHash)
|
||||
}
|
||||
@ -104,12 +105,14 @@ export class ChainTaskClass extends BaseModule {
|
||||
if (record.allEnd) {
|
||||
setImmediate(async function () {
|
||||
try {
|
||||
let gasPrice = await new PriceSvr().refreshGasPrice()
|
||||
let result = await new InfoSvr().reportTaskResult({
|
||||
id: record.taskId,
|
||||
result: record.status,
|
||||
successCount: record.successCount,
|
||||
errorCount: record.errorCount,
|
||||
gas: record.gas,
|
||||
gasPrice,
|
||||
hashList,
|
||||
cb: record.cb,
|
||||
})
|
||||
|
@ -11,10 +11,10 @@ const calcHash = function (data: any) {
|
||||
@singleton
|
||||
export class InfoSvr {
|
||||
reportTaskResult(data: any) {
|
||||
data.sign = calcHash(data)
|
||||
logger.info('report to info svr: ' + JSON.stringify(data))
|
||||
let url = data.cb
|
||||
delete data.cb
|
||||
data.sign = calcHash(data)
|
||||
logger.info('report to info svr: ' + JSON.stringify(data))
|
||||
if (!url) {
|
||||
url = `${process.env.INFO_SVR_HOST}${REPORT_TASK_URI}`
|
||||
}
|
||||
|
@ -30,11 +30,11 @@ export function sha1(str) {
|
||||
return str
|
||||
}
|
||||
|
||||
export function hmacSha256(str: string, key: any) {
|
||||
const md5sum = crypto.createHmac('sha256', key)
|
||||
md5sum.update(str)
|
||||
str = md5sum.digest('hex')
|
||||
return str
|
||||
export function hmacSha256(text: string, secret: string) {
|
||||
const mac = crypto.createHmac('sha256', secret)
|
||||
const data = mac.update(text).digest('hex').toLowerCase()
|
||||
console.log(`HmacSHA256 rawContent is [${text}], key is [${secret}], hash result is [${data}]`)
|
||||
return data
|
||||
}
|
||||
|
||||
export function md5(str) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user