fix(script): Fix build runtime script to handle empty constructor

This commit is contained in:
Florian Pellissier
2024-07-17 10:37:16 +02:00
parent 15a567e5d2
commit 9e851534ce

View File

@@ -5,12 +5,32 @@ import "forge-std/Script.sol";
contract buildRuntime is Script {
function run() external {
bytes memory args = vm.envBytes("__PROPELLER_DEPLOY_ARGS");
string memory contractRef = vm.envString("__PROPELLER_CONTRACT");
bytes memory deployArgs = getDeployArgs();
string memory contractName = vm.envString("__PROPELLER_CONTRACT");
string memory outFilePath = vm.envString("__PROPELLER_OUT_FILE");
address deployedContract = deployCode(contractRef, args);
address deployedContract = deployContract(contractName, deployArgs);
bytes memory deployedCode = deployedContract.code;
vm.writeFileBinary(outFilePath, deployedCode);
}
function getDeployArgs() internal view returns (bytes memory) {
try vm.envBytes("__PROPELLER_DEPLOY_ARGS") returns (bytes memory args) {
return args;
} catch {
return "";
}
}
function deployContract(string memory contractName, bytes memory args)
internal
returns (address)
{
if (args.length == 0) {
return deployCode(contractName);
} else {
return deployCode(contractName, args);
}
}
}