From 0579c5c66565ffe888d428d1751f33a651cfd9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Holm=20Gj=C3=B8rup?= Date: Mon, 18 Sep 2023 16:18:43 +0200 Subject: [PATCH] Fix minor issues related to generating clients --- examples/ccd-js-gen/wCCD/generate.ts | 27 +++++---------------------- packages/ccd-js-gen/src/lib.ts | 25 ++++++++++++++++++------- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/examples/ccd-js-gen/wCCD/generate.ts b/examples/ccd-js-gen/wCCD/generate.ts index 39951c426..10828eb9e 100644 --- a/examples/ccd-js-gen/wCCD/generate.ts +++ b/examples/ccd-js-gen/wCCD/generate.ts @@ -13,13 +13,9 @@ const cli = meow( Usage $ yarn run-example [options] - Required - --index, -i The index of the smart contract. Defaults to 2059, which is wCCD on Testnet. - Options --help, -h Displays this message --endpoint, -e Specify endpoint of a grpc2 interface of a Concordium node in the format "address:port". Defaults to 'localhost:20000' - --subindex, The subindex of the smart contract. Defaults to 0 `, { importMeta: import.meta, @@ -29,16 +25,6 @@ const cli = meow( alias: 'e', default: 'localhost:20000', }, - index: { - type: 'number', - alias: 'i', - isRequired: true, - default: 2059, - }, - subindex: { - type: 'number', - default: 0, - }, }, } ); @@ -50,18 +36,15 @@ const grpcClient = SDK.createConcordiumClient( credentials.createInsecure() ); -const contractAddress: SDK.ContractAddress = { - index: BigInt(cli.flags.index), - subindex: BigInt(cli.flags.subindex), -}; +const wCCDModuleRef = new SDK.ModuleReference( + 'cc285180b45d7695db75c29dee004d2e81a1383880c9b122399bea809196c98f' +); (async () => { - console.info(`Fetching instance information for ${contractAddress.index}.`); - const info = await grpcClient.getInstanceInfo(contractAddress); console.info( - `Fetching smart contract module source with reference '${info.sourceModule.moduleRef}'.` + `Fetching smart contract module source with reference '${wCCDModuleRef.moduleRef}'.` ); - const moduleSource = await grpcClient.getModuleSource(info.sourceModule); + const moduleSource = await grpcClient.getModuleSource(wCCDModuleRef); const filePath = Url.fileURLToPath(import.meta.url); const outDir = Path.join(Path.dirname(filePath), 'lib'); console.info(`Generating smart contract module client at '${outDir}'.`); diff --git a/packages/ccd-js-gen/src/lib.ts b/packages/ccd-js-gen/src/lib.ts index 90cdc7984..a1168bbeb 100644 --- a/packages/ccd-js-gen/src/lib.ts +++ b/packages/ccd-js-gen/src/lib.ts @@ -327,7 +327,7 @@ This function ensures the smart contract module is deployed on chain. .setBodyText( `return SDK.ModuleClient.createAndSendInitTransaction( ${moduleClientId}.${internalModuleClientId}, - '${contract.contractName}', + SDK.ContractName.fromStringUnchecked('${contract.contractName}'), ${transactionMetadataId}, ${parameterId}, ${signerId} @@ -361,15 +361,26 @@ This function ensures the smart contract module is deployed on chain. namespaceImport: 'SDK', moduleSpecifier: '@concordium/common-sdk', }); - contractSourceFile.addImportDeclaration({ - namedImports: [moduleRefId], - moduleSpecifier: `./${outModuleName}`, - }); contractSourceFile.addVariableStatement({ + docs: [ + 'The reference of the smart contract module supported by the provided client.', + ], isExported: true, declarationKind: tsm.VariableDeclarationKind.Const, + declarations: [ + { + name: moduleRefId, + type: 'SDK.ModuleReference', + initializer: `new SDK.ModuleReference('${moduleRef.moduleRef}')`, + }, + ], + }); + + contractSourceFile.addVariableStatement({ docs: ['Name of the smart contract supported by this client.'], + isExported: true, + declarationKind: tsm.VariableDeclarationKind.Const, declarations: [ { name: contractNameId, @@ -473,7 +484,7 @@ Checking the information instance on chain. }) .setBodyText( `const ${genericContractId} = new SDK.Contract(${grpcClientId}, ${contractAddressId}, SDK.ContractName.toString(${contractNameId})); -await ${genericContractId}.checkOnChain({ moduleReference: ${moduleRefId}, blockHash: ${blockHashId} === undefined ? undefined : SDK.BlockHash.toHexString(${blockHashId}) }); +await ${genericContractId}.checkOnChain({ moduleReference: ${moduleRefId}, blockHash: ${blockHashId} }); return new ${contractClientType}( ${grpcClientId}, ${contractAddressId}, @@ -542,7 +553,7 @@ Without checking the instance information on chain. returnType: 'Promise', }) .setBodyText( - `return ${contractClientId}.${genericContractId}.checkOnChain({moduleReference: ${moduleRefId}, blockHash: ${blockHashId} === undefined ? undefined : SDK.BlockHash.toHexString(${blockHashId})})` + `return ${contractClientId}.${genericContractId}.checkOnChain({moduleReference: ${moduleRefId}, blockHash: ${blockHashId} })` ); const invokerId = 'invoker';