diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/main/json/openapi.json b/packages/cactus-plugin-ledger-connector-quorum/src/main/json/openapi.json index 145edc618d..1b2fcd29e3 100644 --- a/packages/cactus-plugin-ledger-connector-quorum/src/main/json/openapi.json +++ b/packages/cactus-plugin-ledger-connector-quorum/src/main/json/openapi.json @@ -487,6 +487,12 @@ "type": "object", "description": "For use when not using keychain, pass the contract in as this variable", "nullable": false + }, + "constructorArgs": { + "description": "The list of arguments to pass in to the constructor of the contract being deployed.", + "type": "array", + "default": [], + "items": {} } } }, @@ -532,6 +538,12 @@ "$ref": "#/components/schemas/ContractJSON", "description": "For use when not using keychain, pass the contract in as this variable", "nullable": false + }, + "constructorArgs": { + "description": "The list of arguments to pass in to the constructor of the contract being deployed.", + "type": "array", + "default": [], + "items": {} } } }, diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/generated/openapi/typescript-axios/api.ts b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/generated/openapi/typescript-axios/api.ts index 922c605af1..08ce366503 100644 --- a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/generated/openapi/typescript-axios/api.ts +++ b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/generated/openapi/typescript-axios/api.ts @@ -144,6 +144,12 @@ export interface DeployContractSolidityBytecodeJsonObjectV1Request { * @memberof DeployContractSolidityBytecodeJsonObjectV1Request */ contractJSON: ContractJSON; + /** + * The list of arguments to pass in to the constructor of the contract being deployed. + * @type {Array} + * @memberof DeployContractSolidityBytecodeJsonObjectV1Request + */ + constructorArgs?: Array; } /** * @@ -193,6 +199,12 @@ export interface DeployContractSolidityBytecodeV1Request { * @memberof DeployContractSolidityBytecodeV1Request */ contractJSON?: object; + /** + * The list of arguments to pass in to the constructor of the contract being deployed. + * @type {Array} + * @memberof DeployContractSolidityBytecodeV1Request + */ + constructorArgs?: Array; } /** * diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts index a1eac4d494..3c80035f68 100644 --- a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts +++ b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts @@ -503,13 +503,26 @@ export class PluginLedgerConnectorQuorum } } + private async generateBytecode(req: any): Promise { + const tmpContract = new this.web3.eth.Contract( + (req.contractJSON as any).abi, + ); + const deployment = tmpContract.deploy({ + data: req.contractJSON.bytecode, + arguments: req.constructorArgs, + }); + const abi = deployment.encodeABI(); + return abi.startsWith("0x") ? abi : `0x${abi}`; + } + async runDeploy(req: any): Promise { const web3SigningCredential = req.web3SigningCredential as | Web3SigningCredentialGethKeychainPassword | Web3SigningCredentialPrivateKeyHex; + const receipt = await this.transact({ transactionConfig: { - data: `0x${req.contractJSON.bytecode}`, + data: await this.generateBytecode(req), from: web3SigningCredential.ethAccount, gas: req.gas, gasPrice: req.gasPrice, diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/v2.3.0-deploy-contract-from-json.test.ts b/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/v2.3.0-deploy-contract-from-json.test.ts index 39e23e55fc..4fdbfb7b52 100644 --- a/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/v2.3.0-deploy-contract-from-json.test.ts +++ b/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/v2.3.0-deploy-contract-from-json.test.ts @@ -461,5 +461,35 @@ test(testCase, async (t: Test) => { t2.end(); }); + test("deploys contract via .json file with constructorArgs", async (t2: Test) => { + const deployOut = await connector.deployContract({ + contractName: HelloWorldContractJson.contractName, + contractJSON: HelloWorldContractJson, + keychainId: keychainPlugin.getKeychainId(), + web3SigningCredential: { + ethAccount: firstHighNetWorthAccount, + secret: "", + type: Web3SigningCredentialType.GethKeychainPassword, + }, + gas: 1000000, + constructorArgs: ["Test Arg"], + }); + t2.ok(deployOut, "deployContract() output is truthy OK"); + t2.ok( + deployOut.transactionReceipt, + "deployContract() output.transactionReceipt is truthy OK", + ); + t2.ok( + deployOut.transactionReceipt.contractAddress, + "deployContract() output.transactionReceipt.contractAddress is truthy OK", + ); + + contractAddress = deployOut.transactionReceipt.contractAddress as string; + t2.ok( + typeof contractAddress === "string", + "contractAddress typeof string OK", + ); + }); + t.end(); });