Skip to content

Commit

Permalink
chore: simplify the EnumCoder::isNativeEnum check
Browse files Browse the repository at this point in the history
  • Loading branch information
petertonysmith94 committed Jul 16, 2024
1 parent b326369 commit c0e5d7b
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions packages/abi-coder/src/encoding/coders/EnumCoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { hasNestedOption } from '../../utils/utilities';
import type { TypesOfCoder } from './AbstractCoder';
import { Coder } from './AbstractCoder';
import { BigNumberCoder } from './BigNumberCoder';
import type { TupleCoder } from './TupleCoder';

export type InputValueOf<TCoders extends Record<string, Coder>> = RequireExactlyOne<{
[P in keyof TCoders]: TypesOfCoder<TCoders[P]>['Input'];
Expand Down Expand Up @@ -42,14 +41,9 @@ export class EnumCoder<TCoders extends Record<string, Coder>> extends Coder<
this.#shouldValidateLength = !(this.type === OPTION_CODER_TYPE || hasNestedOption(coders));
}

// We parse a native enum as an empty tuple, so we are looking for a tuple with no child coders.
// The '()' is enough but the child coders is a stricter check.
// Checks that we're handling a native enum that is of type void.
#isNativeEnum(coder: Coder): boolean {
if (this.type !== OPTION_CODER_TYPE && coder.type === VOID_TYPE) {
const tupleCoder = coder as TupleCoder<[]>;
return tupleCoder.coders.length === 0;
}
return false;
return this.type !== OPTION_CODER_TYPE && coder.type === VOID_TYPE;
}

#encodeNativeEnum(value: string): Uint8Array {
Expand Down

0 comments on commit c0e5d7b

Please sign in to comment.