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