Skip to content

Commit cb3c8d8

Browse files
Travis Paynepetermetz
Travis Payne
authored andcommitted
feat: allows for constructor args in quorum contract deploy
Closes: #962 Signed-off-by: Travis Payne <[email protected]>
1 parent 55a12b6 commit cb3c8d8

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

packages/cactus-plugin-ledger-connector-quorum/src/main/json/openapi.json

+12
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,12 @@
487487
"type": "object",
488488
"description": "For use when not using keychain, pass the contract in as this variable",
489489
"nullable": false
490+
},
491+
"constructorArgs": {
492+
"description": "The list of arguments to pass in to the constructor of the contract being deployed.",
493+
"type": "array",
494+
"default": [],
495+
"items": {}
490496
}
491497
}
492498
},
@@ -532,6 +538,12 @@
532538
"$ref": "#/components/schemas/ContractJSON",
533539
"description": "For use when not using keychain, pass the contract in as this variable",
534540
"nullable": false
541+
},
542+
"constructorArgs": {
543+
"description": "The list of arguments to pass in to the constructor of the contract being deployed.",
544+
"type": "array",
545+
"default": [],
546+
"items": {}
535547
}
536548
}
537549
},

packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/generated/openapi/typescript-axios/api.ts

+12
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ export interface DeployContractSolidityBytecodeJsonObjectV1Request {
144144
* @memberof DeployContractSolidityBytecodeJsonObjectV1Request
145145
*/
146146
contractJSON: ContractJSON;
147+
/**
148+
* The list of arguments to pass in to the constructor of the contract being deployed.
149+
* @type {Array<any>}
150+
* @memberof DeployContractSolidityBytecodeJsonObjectV1Request
151+
*/
152+
constructorArgs?: Array<any>;
147153
}
148154
/**
149155
*
@@ -193,6 +199,12 @@ export interface DeployContractSolidityBytecodeV1Request {
193199
* @memberof DeployContractSolidityBytecodeV1Request
194200
*/
195201
contractJSON?: object;
202+
/**
203+
* The list of arguments to pass in to the constructor of the contract being deployed.
204+
* @type {Array<any>}
205+
* @memberof DeployContractSolidityBytecodeV1Request
206+
*/
207+
constructorArgs?: Array<any>;
196208
}
197209
/**
198210
*

packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -503,13 +503,26 @@ export class PluginLedgerConnectorQuorum
503503
}
504504
}
505505

506+
private async generateBytecode(req: any): Promise<string> {
507+
const tmpContract = new this.web3.eth.Contract(
508+
(req.contractJSON as any).abi,
509+
);
510+
const deployment = tmpContract.deploy({
511+
data: req.contractJSON.bytecode,
512+
arguments: req.constructorArgs,
513+
});
514+
const abi = deployment.encodeABI();
515+
return abi.startsWith("0x") ? abi : `0x${abi}`;
516+
}
517+
506518
async runDeploy(req: any): Promise<DeployContractSolidityBytecodeV1Response> {
507519
const web3SigningCredential = req.web3SigningCredential as
508520
| Web3SigningCredentialGethKeychainPassword
509521
| Web3SigningCredentialPrivateKeyHex;
522+
510523
const receipt = await this.transact({
511524
transactionConfig: {
512-
data: `0x${req.contractJSON.bytecode}`,
525+
data: await this.generateBytecode(req),
513526
from: web3SigningCredential.ethAccount,
514527
gas: req.gas,
515528
gasPrice: req.gasPrice,

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

+30
Original file line numberDiff line numberDiff line change
@@ -461,5 +461,35 @@ test(testCase, async (t: Test) => {
461461
t2.end();
462462
});
463463

464+
test("deploys contract via .json file with constructorArgs", async (t2: Test) => {
465+
const deployOut = await connector.deployContract({
466+
contractName: HelloWorldContractJson.contractName,
467+
contractJSON: HelloWorldContractJson,
468+
keychainId: keychainPlugin.getKeychainId(),
469+
web3SigningCredential: {
470+
ethAccount: firstHighNetWorthAccount,
471+
secret: "",
472+
type: Web3SigningCredentialType.GethKeychainPassword,
473+
},
474+
gas: 1000000,
475+
constructorArgs: ["Test Arg"],
476+
});
477+
t2.ok(deployOut, "deployContract() output is truthy OK");
478+
t2.ok(
479+
deployOut.transactionReceipt,
480+
"deployContract() output.transactionReceipt is truthy OK",
481+
);
482+
t2.ok(
483+
deployOut.transactionReceipt.contractAddress,
484+
"deployContract() output.transactionReceipt.contractAddress is truthy OK",
485+
);
486+
487+
contractAddress = deployOut.transactionReceipt.contractAddress as string;
488+
t2.ok(
489+
typeof contractAddress === "string",
490+
"contractAddress typeof string OK",
491+
);
492+
});
493+
464494
t.end();
465495
});

0 commit comments

Comments
 (0)