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

Add log in codegen for unsupported multiple return types #359

Merged
merged 1 commit into from
Apr 12, 2023
Merged
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
2 changes: 2 additions & 0 deletions packages/codegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Steps:
# NOTE: When passed an *URL* as contract path, it is assumed that it points to an already flattened contract file.
```

* Ensure dependencies are installed in the contracts repository before generating the watcher

* Run the following command to generate a watcher from contract(s):

```bash
Expand Down
2 changes: 2 additions & 0 deletions packages/codegen/src/templates/package-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
"devDependencies": {
"@ethersproject/abi": "^5.3.0",
"@types/yargs": "^17.0.0",
"@types/debug": "^4.1.5",
"@types/json-bigint": "^1.0.1",
"@typescript-eslint/eslint-plugin": "^5.47.1",
"@typescript-eslint/parser": "^5.47.1",
"eslint": "^8.35.0",
Expand Down
55 changes: 30 additions & 25 deletions packages/codegen/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,37 @@ export class Visitor {

let errorMessage = '';

const typeName = node.returnParameters[0].typeName;
switch (typeName.type) {
case 'ElementaryTypeName': {
const returnType = typeName.name;

this._schema.addQuery(name, params, returnType);
this._resolvers.addQuery(name, params, returnType);
this._entity.addQuery(name, params, returnType);
this._database.addQuery(name, params, returnType);
this._client.addQuery(name, params, returnType);

assert(this._contract);
this._indexer.addQuery(this._contract.name, MODE_ETH_CALL, name, params, returnType);

break;
if (node.returnParameters.length > 1) {
errorMessage = `No support in codegen for multiple returned values from method ${node.name}`;
} else {
const typeName = node.returnParameters[0].typeName;
switch (typeName.type) {
case 'ElementaryTypeName': {
const returnType = typeName.name;

this._schema.addQuery(name, params, returnType);
this._resolvers.addQuery(name, params, returnType);
this._entity.addQuery(name, params, returnType);
this._database.addQuery(name, params, returnType);
this._client.addQuery(name, params, returnType);

assert(this._contract);
this._indexer.addQuery(this._contract.name, MODE_ETH_CALL, name, params, returnType);

break;
}

case 'UserDefinedTypeName':
errorMessage = `No support in codegen for user defined return type from method "${node.name}"`;
break;

case 'ArrayTypeName':
errorMessage = `No support in codegen for return type "${typeName.baseTypeName.name}[]" from method "${node.name}"`;
break;

default:
errorMessage = `No support in codegen for return type "${typeName.type}" from method "${node.name}"`;
}
case 'UserDefinedTypeName':
errorMessage = `No support in codegen for user defined return type from method "${node.name}"`;
break;

case 'ArrayTypeName':
errorMessage = `No support in codegen for return type "${typeName.baseTypeName.name}[]" from method "${node.name}"`;
break;

default:
errorMessage = `No support in codegen for return type "${typeName.type}" from method "${node.name}"`;
}

if (errorMessage !== '') {
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3756,7 +3756,7 @@
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.5.tgz#738dd390a6ecc5442f35e7f03fa1431353f7e138"
integrity sha512-FhpRzf927MNQdRZP0J5DLIdTXhjLYzeUTmLAu69mnVksLH9CJY3IuSeEgbKUki7GQZm0WqDkGzyxju2EZGD2wA==

"@types/json-bigint@^1.0.0":
"@types/json-bigint@^1.0.0", "@types/json-bigint@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@types/json-bigint/-/json-bigint-1.0.1.tgz#201062a6990119a8cc18023cfe1fed12fc2fc8a7"
integrity sha512-zpchZLNsNuzJHi6v64UBoFWAvQlPhch7XAi36FkH6tL1bbbmimIF+cS7vwkzY4u5RaSWMoflQfu+TshMPPw8uw==
Expand Down Expand Up @@ -6241,7 +6241,7 @@ commander@^2.15.1, commander@^2.20.3:

commander@^8.1.0:
version "8.3.0"
resolved "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz"
resolved "https://registry.yarnpkg.com/commander/-/commander-8.3.0.tgz#4837ea1b2da67b9c616a67afbb0fafee567bca66"
integrity sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==

compare-func@^2.0.0:
Expand Down Expand Up @@ -14685,7 +14685,7 @@ [email protected]:

[email protected]:
version "0.8.13"
resolved "https://registry.npmjs.org/solc/-/solc-0.8.13.tgz"
resolved "https://registry.yarnpkg.com/solc/-/solc-0.8.13.tgz#bafc7fcc11a627e2281e489076b80497123bb704"
integrity sha512-C0yTN+rjEOGO6uVOXI8+EKa75SFMuZpQ2tryex4QxWIg0HRWZvCHKfVPuLZ5wx06Sb6GBp6uQA5yqQyXZnXOJw==
dependencies:
command-exists "^1.2.8"
Expand Down