diff --git a/evm/scripts/_buildRuntime.s.sol b/evm/scripts/_buildRuntime.s.sol index e057572..c386db3 100644 --- a/evm/scripts/_buildRuntime.s.sol +++ b/evm/scripts/_buildRuntime.s.sol @@ -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); + } + } }