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

ABI generation #301

Merged
merged 15 commits into from
Dec 4, 2022
Merged
Prev Previous commit
Next Next commit
fix linting
itegulov committed Nov 22, 2022

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 34429d070f0d1ee6e096ac1a4f76fbf08ad4b8d4
8 changes: 7 additions & 1 deletion lib/cli/abi.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions src/cli/abi.ts
Original file line number Diff line number Diff line change
@@ -71,8 +71,8 @@ export function runAbiCompilerPlugin(
if (diagnostics.length > 0) {
diagnostics.forEach((diagnostic) => {
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
if (diagnostic.file) {
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start!);
if (diagnostic.file && diagnostic.start) {
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
console.error(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
} else {
console.error(message);
@@ -81,7 +81,10 @@ export function runAbiCompilerPlugin(
throw Error("Failed to compile the contract");
}

const generator = TJS.buildGenerator(program)!;
const generator = TJS.buildGenerator(program);
if (!generator) {
throw Error("Failed to generate ABI due to an unexpected typescript-json-schema error. Please report this.");
}

const abiFunctions: abi.AbiFunction[] = [];

@@ -108,6 +111,7 @@ export function runAbiCompilerPlugin(
if (arg.kind !== ts.SyntaxKind.ObjectLiteralExpression) return;
const objLiteral = arg as ts.ObjectLiteralExpression;
objLiteral.properties.forEach((prop) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const propName = (prop.name as any).text;
if (propName === "privateFunction") {
if (prop.kind !== ts.SyntaxKind.PropertyAssignment) return;
@@ -166,6 +170,7 @@ export function runAbiCompilerPlugin(
const nodeType = tc.getTypeAtLocation(parameter);
const schema = generator.getTypeDefinition(nodeType, true);
const abiParameter: abi.AbiJsonParameter = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
name: (parameter.name as any).text,
type_schema: schema as JSONSchema7
};
@@ -184,6 +189,7 @@ export function runAbiCompilerPlugin(
};
}
const abiFunction: abi.AbiFunction = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
name: (methodDeclaration.name as any).text,
kind: isView ? abi.AbiFunctionKind.View : abi.AbiFunctionKind.Call,
modifiers: abiModifiers,