Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minor issues related to generating clients #268

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 5 additions & 22 deletions examples/ccd-js-gen/wCCD/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ const cli = meow(
Usage
$ yarn run-example <path-to-this-file> [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,
Expand All @@ -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,
},
},
}
);
Expand All @@ -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}'.`);
Expand Down
25 changes: 18 additions & 7 deletions packages/ccd-js-gen/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -542,7 +553,7 @@ Without checking the instance information on chain.
returnType: 'Promise<void>',
})
.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';
Expand Down