|
1 | 1 | // SPDX-FileCopyrightText: 2024-2025 IEXEC BLOCKCHAIN TECH <[email protected]> |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
| 4 | +// Usage: CALLBACK_GAS=<value> npx hardhat run scripts/set-callback-gas.ts --network <network> |
| 5 | + |
4 | 6 | import { deployments, ethers } from 'hardhat'; |
5 | | -import { IexecAccessors__factory, IexecConfigurationFacet__factory } from '../typechain'; |
| 7 | +import { IexecInterfaceToken__factory } from '../typechain'; |
6 | 8 |
|
7 | 9 | (async () => { |
8 | 10 | const requestedCallbackGas = Number(process.env.CALLBACK_GAS); |
9 | 11 | if (!requestedCallbackGas) { |
10 | | - console.error('`CALLBACK_GAS` env variable is missing. Aborting.'); |
11 | | - process.exit(1); |
| 12 | + throw new Error('`CALLBACK_GAS` env variable is missing or invalid.'); |
12 | 13 | } |
13 | | - console.log(`Setting callback-gas to ${requestedCallbackGas.toLocaleString()} ..`); |
14 | | - const [owner] = await ethers.getSigners(); |
15 | 14 | const diamondProxyAddress = (await deployments.get('Diamond')).address; |
16 | | - const viewCallbackGas = async () => |
17 | | - (await IexecAccessors__factory.connect(diamondProxyAddress, owner).callbackgas()) |
18 | | - .toNumber() |
19 | | - .toLocaleString(); |
20 | | - const callbackGasBefore = await viewCallbackGas(); |
21 | | - await IexecConfigurationFacet__factory.connect(diamondProxyAddress, owner) |
22 | | - .setCallbackGas(requestedCallbackGas) |
23 | | - .then((tx) => tx.wait()); |
24 | | - console.log(`Changed callback-gas from ${callbackGasBefore} to ${await viewCallbackGas()}`); |
| 15 | + const [owner] = await ethers.getSigners(); |
| 16 | + const iexecPoCo = IexecInterfaceToken__factory.connect(diamondProxyAddress, owner); |
| 17 | + if ((await iexecPoCo.owner()) !== owner.address) { |
| 18 | + throw new Error(`Sender account ${owner.address} is not the PoCo owner.`); |
| 19 | + } |
| 20 | + console.log(`Setting callback-gas to ${requestedCallbackGas.toLocaleString()} ..`); |
| 21 | + const callbackGasBefore = (await iexecPoCo.callbackgas()).toLocaleString(); |
| 22 | + await iexecPoCo.setCallbackGas(requestedCallbackGas).then((tx) => tx.wait()); |
| 23 | + const callbackGasAfter = (await iexecPoCo.callbackgas()).toLocaleString(); |
| 24 | + console.log(`Changed callback-gas from ${callbackGasBefore} to ${callbackGasAfter}`); |
25 | 25 | })().catch((error) => console.log(error)); |
0 commit comments