Skip to content

Commit

Permalink
fix an issue with invalid ABI
Browse files Browse the repository at this point in the history
ref #1973
  • Loading branch information
YaroShkvorets committed Feb 25, 2025
1 parent 9c69575 commit ab256bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
11 changes: 7 additions & 4 deletions packages/cli/src/protocols/ethereum/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ export default class ABI {
(entry: any) => !entry.has('type') || functionTypes.includes(entry.get('type')),
);

// @ts-expect-error: Unused variable 'arr'
const arr = functions.toArray();

// A function is a call function if it is nonpayable, payable or
// not constant
const mutabilityTypes = immutable.Set(['nonpayable', 'payable']);
Expand All @@ -118,10 +121,10 @@ export default class ABI {
return this.callFunctions()
.filter((entry: any) => entry.get('type') !== 'constructor')
.map((entry: any) => {
const name = entry.get('name', '<default>');
const inputs = entry
.get('inputs', immutable.List())
.map((input: any) => buildSignatureParameter(input));
const name = entry.get('name') || '<default>';
const inputs = (entry.get('inputs') ?? immutable.List()).map((input: any) =>
buildSignatureParameter(input),
);

return `${name}(${inputs.join(',')})`;
});
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/protocols/ethereum/codegen/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default class AbiCodeGenerator {
// Generate getters and classes for function inputs
util
.disambiguateNames({
values: fn.get('inputs', immutable.List()),
values: fn.get('inputs') ?? immutable.List(),
// @ts-expect-error improve typings of disambiguateNames to handle iterables
getName: (input, index) => input.get('name') || `value${index}`,
// @ts-expect-error improve typings of disambiguateNames to handle iterables
Expand Down Expand Up @@ -119,7 +119,7 @@ export default class AbiCodeGenerator {
// Generate getters and classes for function outputs
util
.disambiguateNames({
values: fn.get('outputs', immutable.List()),
values: fn.get('outputs') ?? immutable.List(),
// @ts-expect-error improve typings of disambiguateNames to handle iterables
getName: (output, index) => output.get('name') || `value${index}`,
// @ts-expect-error improve typings of disambiguateNames to handle iterables
Expand Down Expand Up @@ -198,7 +198,7 @@ export default class AbiCodeGenerator {

// Enumerate inputs with duplicate names
const inputs = util.disambiguateNames({
values: event.get('inputs'),
values: event.get('inputs') ?? immutable.List(),
// @ts-expect-error improve typings of disambiguateNames to handle iterables
getName: (input, index) => input.get('name') || `param${index}`,
// @ts-expect-error improve typings of disambiguateNames to handle iterables
Expand Down Expand Up @@ -461,7 +461,7 @@ export default class AbiCodeGenerator {
setName: (input, name) => input.set('name', name),
}) as any;

if ((member as any).get('outputs', immutable.List()).size > 1) {
if ((member as any).get('outputs', immutable.List())?.size > 1) {
simpleReturnType = false;

// Create a type dedicated to holding the return values
Expand Down Expand Up @@ -573,7 +573,7 @@ export default class AbiCodeGenerator {

// Disambiguate inputs with duplicate names
const inputs = util.disambiguateNames({
values: (member as any).get('inputs', immutable.List()),
values: (member as any).get('inputs') ?? immutable.List(),
// @ts-expect-error improve typings of disambiguateNames to handle iterables
getName: (input, index) => input.get('name') || `param${index}`,
// @ts-expect-error improve typings of disambiguateNames to handle iterables
Expand Down Expand Up @@ -714,7 +714,7 @@ export default class AbiCodeGenerator {
return this.abi.data.filter(
member =>
member.get('type') === 'function' &&
member.get('outputs', immutable.List()).size !== 0 &&
member.get('outputs', immutable.List())?.size > 0 &&
(allowedMutability.includes(member.get('stateMutability')) ||
(member.get('stateMutability') === undefined && !member.get('payable', false))),
);
Expand Down

0 comments on commit ab256bb

Please sign in to comment.