Skip to content

Commit fbc3740

Browse files
committed
feat(connector-besu): contract deployment with constructor arguments
Previously you couldn't deploy a contract that had constructor arguments of it's own because there was no way to pass in these. With this improvement this is now possible. Depends on hyperledger-cacti#810 Signed-off-by: Peter Somogyvari <[email protected]>
1 parent eac0942 commit fbc3740

File tree

7 files changed

+45
-30
lines changed

7 files changed

+45
-30
lines changed

examples/cactus-example-supply-chain-backend/src/main/typescript/infrastructure/supply-chain-app-dummy-infrastructure.ts

+2
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ export class SupplyChainAppDummyInfrastructure {
211211
const res = await connector.deployContract({
212212
contractName: BookshelfRepositoryJSON.contractName,
213213
bytecode: BookshelfRepositoryJSON.bytecode,
214+
contractAbi: BookshelfRepositoryJSON.abi,
215+
constructorArgs: [],
214216
gas: 1000000,
215217
web3SigningCredential: {
216218
ethAccount: this.besuAccount.address,

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

+16-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"description": "Enumerates the possible types of receipts that can be waited for by someone or something that has requested the execution of a transaction on a ledger.",
3636
"type": "string",
3737
"enum": [
38-
"NODE_TX_POOL_ACK",
38+
"NODE_TX_POOL_ACK",
3939
"LEDGER_BLOCK_ACK"
4040
]
4141
},
@@ -402,9 +402,11 @@
402402
"type": "object",
403403
"required": [
404404
"contractName",
405+
"contractAbi",
405406
"bytecode",
406407
"web3SigningCredential",
407-
"keychainId"
408+
"keychainId",
409+
"constructorArgs"
408410
],
409411
"properties": {
410412
"contractName": {
@@ -414,6 +416,17 @@
414416
"maxLength": 100,
415417
"nullable": false
416418
},
419+
"contractAbi": {
420+
"description": "The application binary interface of the solidity contract",
421+
"type": "array",
422+
"items": {},
423+
"nullable": false
424+
},
425+
"constructorArgs": {
426+
"type": "array",
427+
"items": {},
428+
"default": []
429+
},
417430
"web3SigningCredential": {
418431
"$ref": "#/components/schemas/Web3SigningCredential",
419432
"nullable": false
@@ -634,7 +647,7 @@
634647
"type": "string",
635648
"description": "The keychainId for retrieve the contracts json.",
636649
"minLength": 1,
637-
"maxLength": 100
650+
"maxLength": 100
638651
}
639652
}
640653
},

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

+12
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ export interface DeployContractSolidityBytecodeV1Request {
113113
* @memberof DeployContractSolidityBytecodeV1Request
114114
*/
115115
contractName: string;
116+
/**
117+
* The application binary interface of the solidity contract
118+
* @type {Array<any>}
119+
* @memberof DeployContractSolidityBytecodeV1Request
120+
*/
121+
contractAbi: Array<any>;
122+
/**
123+
*
124+
* @type {Array<any>}
125+
* @memberof DeployContractSolidityBytecodeV1Request
126+
*/
127+
constructorArgs: Array<any>;
116128
/**
117129
*
118130
* @type {Web3SigningCredential}

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -615,12 +615,22 @@ export class PluginLedgerConnectorBesu
615615
}
616616
const networkId = await this.web3.eth.net.getId();
617617

618+
const tmpContract = new this.web3.eth.Contract(req.contractAbi);
619+
const deployment = tmpContract.deploy({
620+
data: req.bytecode,
621+
arguments: req.constructorArgs,
622+
});
623+
624+
this.log.debug(`Deployment object of contract: %o`, deployment);
625+
const encodedAbi = deployment.encodeABI();
626+
const data = `0x${encodedAbi}`;
627+
618628
const web3SigningCredential = req.web3SigningCredential as
619629
| Web3SigningCredentialPrivateKeyHex
620630
| Web3SigningCredentialCactusKeychainRef;
621631
const receipt = await this.transact({
622632
transactionConfig: {
623-
data: `0x${req.bytecode}`,
633+
data,
624634
from: web3SigningCredential.ethAccount,
625635
gas: req.gas,
626636
gasPrice: req.gasPrice,

packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ test(testCase, async (t: Test) => {
137137
const deployOut = await connector.deployContract({
138138
keychainId: keychainPlugin.getKeychainId(),
139139
contractName: HelloWorldContractJson.contractName,
140+
contractAbi: HelloWorldContractJson.abi,
141+
constructorArgs: [],
140142
web3SigningCredential: {
141143
ethAccount: firstHighNetWorthAccount,
142144
secret: besuKeyPair.privateKey,

packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract-v2.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ test("deploys contract via .json file", async (t: Test) => {
9595
const deployOut = await connector.deployContract({
9696
keychainId: keychainPlugin.getKeychainId(),
9797
contractName: HelloWorldContractJson.contractName,
98+
contractAbi: HelloWorldContractJson.abi,
99+
constructorArgs: [],
98100
web3SigningCredential: {
99101
ethAccount: firstHighNetWorthAccount,
100102
secret: besuKeyPair.privateKey,

packages/cactus-test-plugin-ledger-connector-besu/package-lock.json

-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)