schedule上链该用新方法,降低gas费用

This commit is contained in:
CounterFire2023 2023-07-27 17:08:35 +08:00
parent 303fca75e8
commit a3e543fe23
4 changed files with 6548 additions and 6256 deletions

View File

@ -2,7 +2,7 @@
{
"id": 421613,
"key": "0xd9ed33809372932059c1ba7b336a33f406b4c55e7430daef8297134c67429d60",
"wallet": "0xE68F149daF2F314d9960c08496D8701BC7671850",
"wallet": "0x2419c58F3542E69c3f10dfe6C1Bb1fBd4D54Db5A",
"mail": "zhl010101@gmail.com"
},
{

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
import { Contract } from 'web3-eth-contract'
import Web3 from 'web3'
import { Account } from 'web3-core'
import { ZERO_BYTES32 } from 'common/Constants'
import { GAS_BOOST, ZERO_BYTES32 } from 'common/Constants'
import { generateRandomBytes32 } from 'utils/wallet.util'
import { ChainCache } from 'cache/ChainCache'
const abi = require('abis/BEMultiSigWallet.json').abi
@ -39,26 +39,35 @@ export class WalletReactor {
*/
async beginSchedule(operation: IOperationData, seconds: number) {
// let operation: any = this.genOperation(contractAddress, 0, data, ZERO_BYTES32, salt)
if (!operation.scheduleId) {
operation.scheduleId = this.genOperation(operation).scheduleId
}
let gas = await this.contract.methods
.schedule(operation.targets, operation.values, operation.datas, operation.predecessor, operation.salt, seconds)
.simpleSchedule(operation.scheduleId, seconds)
.estimateGas({ from: this.account.address })
// let gas = await this.contract.methods
// .schedule(operation.targets, operation.values, operation.datas, operation.predecessor, operation.salt, seconds)
// .estimateGas({ from: this.account.address })
// let nonce = await this.web3.eth.getTransactionCount(this.account.address)
let gasPrice = await this.web3.eth.getGasPrice()
let res = await this.contract.methods
.schedule(operation.targets, operation.values, operation.datas, operation.predecessor, operation.salt, seconds)
.send({ gas: (gas * 1.51) | 0, gasPrice })
.simpleSchedule(operation.scheduleId, seconds)
.send({ gas: (gas * GAS_BOOST) | 0, gasPrice })
// let res = await this.contract.methods
// .schedule(operation.targets, operation.values, operation.datas, operation.predecessor, operation.salt, seconds)
// .send({ gas: (gas * 1.51) | 0, gasPrice })
operation.transactionHash = res.transactionHash
return operation
}
/**
* , proposer角色
* @param {bytes32} id beginSchedule返回的id
* @param {bytes32} scheduleId beginSchedule返回的id
* @returns
*/
async cancelSchedule(id) {
let gas = await this.contract.methods.cancel(id).estimateGas({ from: this.account.address })
let res = await this.contract.methods.cancel(id).send({ gas: gas | 0 })
async cancelSchedule(scheduleId: string) {
let gas = await this.contract.methods.cancel(scheduleId).estimateGas({ from: this.account.address })
let res = await this.contract.methods.cancel(scheduleId).send({ gas: (gas * GAS_BOOST) | 0 })
return res
}
/**
@ -94,7 +103,7 @@ export class WalletReactor {
let gasPrice = await this.web3.eth.getGasPrice()
let res = await this.contract.methods
.execute(operation.targets, operation.values, operation.datas, operation.predecessor, operation.salt)
.send({ gas: (gas * 1.5) | 0, gasPrice })
.send({ gas: (gas * GAS_BOOST) | 0, gasPrice })
return res
}

View File

@ -9,6 +9,7 @@ import { ChainTask } from 'models/ChainTask'
import { isObjectId } from 'utils/string.util'
import { WechatWorkService } from 'service/wechatwork.service'
import { ChainCache } from 'cache/ChainCache'
import { ChainQueue } from 'queue/chain.queue'
class WorkFlowController extends BaseController {
@role(ROLE_ANON)
@ -116,12 +117,29 @@ class WorkFlowController extends BaseController {
@role(ROLE_ANON)
@router('get /workflow/test')
async test(req, res) {
// let file_path = '/Users/zhl/Documents/workspace/tools/excel2json/test.xlsx'
let file_path = '/Users/zhl/Desktop/arbitrum_airdrop_0726_test.xlsx'
let { data, chain } = new WechatWorkService().parseOneExcel(file_path)
let taskData = {
taskId: 'test012',
name: 'test01',
desc: 'test01',
data,
starter: 'test01',
starterName: 'test01',
chain,
}
let subTasks = await ChainTask.parseWxApprovalInfo(taskData)
for (let subTask of subTasks) {
let { scheduleId } = new ChainCache().getWallet(taskData.chain).genOperation(subTask)
subTask.scheduleId = scheduleId
await subTask.save()
new ChainQueue().addTaskToQueue(subTask)
}
// let fileId = 'WWME_g-oYEAAACj738mha3is3XxxDavhb5w'
// await new WechatWorkService().fetchFile(fileId, true)
// console.log('11')
let spNo = '202307120024'
new TaskQueue().addTaskToQueue(spNo)
// let spNo = '202307120024'
// new TaskQueue().addTaskToQueue(spNo)
// let task = await ChainTask.findById('642fe42611845ce0e1def316')
// for (let tid of task.tasks) {
// let subTask = await RequestTask.findById(tid)