Skip to content

Commit 8abcec4

Browse files
committed
fix: handle tuples in events 1 level deep for now
1 parent 42885c9 commit 8abcec4

File tree

6 files changed

+7380
-115
lines changed

6 files changed

+7380
-115
lines changed

abi-types-generator/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ethereum-abi-types-generator",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"description": "Generate types from an ethereum ABI json file.",
55
"main": "dist/index.js",
66
"scripts": {

abi-types-generator/src/converters/typescript/abi-generator.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,20 @@ export default class AbiGenerator {
318318
for (let e = 0; e < eventInputs.length; e++) {
319319
const eventTsType = TypeScriptHelpers.getSolidityInputTsType(
320320
eventInputs[e],
321-
this._context.provider
321+
this._context.provider,
322+
'EventEmittedResponse'
322323
);
323324

324325
eventTypeProperties += `${eventInputs[e].name}: ${eventTsType};`;
326+
327+
if (eventInputs[e].type === SolidityType.tuple) {
328+
this.buildTupleParametersInterface(
329+
// remove due to prefix of components
330+
eventTsType.replace('EventEmittedResponse', ''),
331+
eventInputs[e],
332+
'EventEmittedResponse'
333+
);
334+
}
325335
}
326336

327337
this.addReturnTypeInterface(
@@ -367,7 +377,7 @@ export default class AbiGenerator {
367377
*/
368378
private getAbiFileLocationRawName(): string {
369379
const basename = path.basename(this._context.abiFileLocation);
370-
return basename.substr(0, basename.lastIndexOf('.'));
380+
return basename.substr(0, basename.lastIndexOf('.'));
371381
}
372382

373383
/**
@@ -516,9 +526,10 @@ export default class AbiGenerator {
516526
*/
517527
private buildTupleParametersInterface(
518528
name: string,
519-
abiInput: AbiInput
529+
abiInput: AbiInput,
530+
prefix: 'Request' | 'Response' | 'EventEmittedResponse' = 'Request'
520531
): string {
521-
const interfaceName = `${Helpers.capitalize(name)}Request`;
532+
const interfaceName = `${Helpers.capitalize(name)}${prefix}`;
522533

523534
let properties = '';
524535

@@ -534,7 +545,7 @@ export default class AbiGenerator {
534545
if (abiInput.components![i].components) {
535546
const deepInterfaceName = TypeScriptHelpers.buildInterfaceName(
536547
abiInput.components![i],
537-
'Request'
548+
prefix
538549
);
539550
let deepProperties = '';
540551
for (

abi-types-generator/src/converters/typescript/common/helpers.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export default class TypeScriptHelpers {
1919
*/
2020
public static getSolidityInputTsType(
2121
abiInput: AbiInput,
22-
provider: Provider
22+
provider: Provider,
23+
prefix: 'Request' | 'EventEmittedResponse' = 'Request'
2324
): string {
2425
switch (provider) {
2526
case Provider.ethers:
@@ -128,7 +129,7 @@ export default class TypeScriptHelpers {
128129
}
129130

130131
if (abiInput.type.includes(SolidityType.tuple)) {
131-
const interfaceName = this.buildInterfaceName(abiInput, 'Request');
132+
const interfaceName = this.buildInterfaceName(abiInput, prefix);
132133
if (abiInput.type.includes('[')) {
133134
return `${interfaceName}[]`;
134135
}
@@ -233,7 +234,10 @@ export default class TypeScriptHelpers {
233234
*/
234235
public static buildInterfaceName(
235236
inputOrOutput: AbiOutput | AbiInput,
236-
requestInterfaceType: 'Request' | 'Response' = 'Response'
237+
requestInterfaceType:
238+
| 'Request'
239+
| 'Response'
240+
| 'EventEmittedResponse' = 'Response'
237241
): string {
238242
if (inputOrOutput.name.length > 0) {
239243
return `${Helpers.capitalize(inputOrOutput.name)}${requestInterfaceType}`;
-94.4 KB
Binary file not shown.
20.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)