-
Notifications
You must be signed in to change notification settings - Fork 16
Refactor/enssdk refactor continued #1908
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
base: main
Are you sure you want to change the base?
Changes from all commits
0cc7c75
9559c91
f5ac2dc
fe4c7db
4b5fa3d
b49bcdf
5d4e6c9
6fb27e3
ec5cac1
ad94a8c
6b7fc4f
aae29f4
597fa4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,7 @@ import { | |
| asInterpretedName, | ||
| type DomainId, | ||
| getNameHierarchy, | ||
| type Name, | ||
| type Node, | ||
| type NormalizedName, | ||
| type InterpretedName, | ||
| namehashInterpretedName, | ||
| } from "enssdk"; | ||
| import { isAddressEqual, type PublicClient, toHex, zeroAddress } from "viem"; | ||
|
|
@@ -29,7 +27,7 @@ type FindResolverResult = | |
| activeResolver: null; | ||
| requiresWildcardSupport: undefined; | ||
| } | ||
| | { activeName: Name; requiresWildcardSupport: boolean; activeResolver: Address }; | ||
| | { activeName: InterpretedName; requiresWildcardSupport: boolean; activeResolver: Address }; | ||
|
|
||
| const NULL_RESULT: FindResolverResult = { | ||
| activeName: null, | ||
|
|
@@ -62,7 +60,7 @@ export async function findResolver({ | |
| publicClient, | ||
| }: { | ||
| registry: AccountId; | ||
| name: NormalizedName; | ||
| name: InterpretedName; | ||
| accelerate: boolean; | ||
| canAccelerate: boolean; | ||
| publicClient: PublicClient; | ||
|
|
@@ -94,7 +92,7 @@ export async function findResolver({ | |
| */ | ||
| async function findResolverWithUniversalResolver( | ||
| publicClient: PublicClient, | ||
| name: Name, | ||
| name: InterpretedName, | ||
| ): Promise<FindResolverResult> { | ||
| return withActiveSpanAsync( | ||
| tracer, | ||
|
|
@@ -147,7 +145,8 @@ async function findResolverWithUniversalResolver( | |
| } | ||
|
|
||
| // UniversalResolver returns the offset in bytes within the DNS Encoded Name where the activeName begins | ||
| const activeName: Name = bytesToPacket(dnsEncodedNameBytes.slice(offset)); | ||
| // Invariant: the decoded name must be an InterpretedName | ||
| const activeName = asInterpretedName(bytesToPacket(dnsEncodedNameBytes.slice(offset))); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we say that |
||
|
|
||
| return { | ||
| activeName, | ||
|
|
@@ -175,7 +174,7 @@ async function findResolverWithUniversalResolver( | |
| */ | ||
| async function findResolverWithIndex( | ||
| registry: AccountId, | ||
| name: NormalizedName, | ||
| name: InterpretedName, | ||
| ): Promise<FindResolverResult> { | ||
| return withActiveSpanAsync( | ||
| tracer, | ||
|
|
@@ -194,7 +193,7 @@ async function findResolverWithIndex( | |
|
|
||
| // 2. compute domainId of each node | ||
| // NOTE: this is currently ENSv1-specific | ||
| const nodes = names.map((name) => namehashInterpretedName(asInterpretedName(name)) as Node); | ||
| const nodes = names.map((name) => namehashInterpretedName(name)); | ||
| const domainIds = nodes as DomainId[]; | ||
|
|
||
| // 3. for each domain, find its associated resolver in the selected registry | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,9 @@ import { replaceBigInts } from "@ponder/utils"; | |
| import { | ||
| type AccountId, | ||
| asInterpretedName, | ||
| isNormalizedName, | ||
| type InterpretedName, | ||
| type Node, | ||
| namehashInterpretedName, | ||
| normalizeName, | ||
| parseReverseName, | ||
| } from "enssdk"; | ||
|
|
||
|
|
@@ -57,10 +56,6 @@ import { | |
| const logger = makeLogger("forward-resolution"); | ||
| const tracer = trace.getTracer("forward-resolution"); | ||
|
|
||
| // NOTE: normalize generic name to force the normalization lib to lazy-load itself (otherwise the | ||
| // first trace generated here would be unusually slow) | ||
| normalizeName("example.eth"); | ||
|
|
||
| /** | ||
| * Implements Forward Resolution of record values for a specified ENS Name. | ||
| * | ||
|
|
@@ -95,9 +90,12 @@ export async function resolveForward<SELECTION extends ResolverRecordsSelection> | |
| selection: ForwardResolutionArgs<SELECTION>["selection"], | ||
| options: Omit<Parameters<typeof _resolveForward>[2], "registry">, | ||
| ): Promise<ForwardResolutionResult<SELECTION>> { | ||
| // Invariant: Name must be an InterpretedName | ||
| const interpretedName = asInterpretedName(name); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a related issue open: #1032 What do you suggest we do in relation to issue 1032 within the scope of this PR (PR 1908)? Should we work to confirm that issue 1032 can be successfully closed, or maybe keep issue 1032 open and make any new relevant comments on it that might help us with working on it later?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the We could then also remove the need for creating |
||
|
|
||
| // NOTE: `resolveForward` is just `_resolveForward` with the enforcement that `registry` must | ||
| // initially be ENS Root Chain's Registry: see `_resolveForward` for additional context. | ||
| return _resolveForward(name, selection, { | ||
| // initially be ENS Root Registry: see `_resolveForward` for additional context. | ||
| return _resolveForward(interpretedName, selection, { | ||
| ...options, | ||
| registry: getENSv1Registry(config.namespace), | ||
| }); | ||
|
|
@@ -108,7 +106,7 @@ export async function resolveForward<SELECTION extends ResolverRecordsSelection> | |
| * `registry`. | ||
| */ | ||
| async function _resolveForward<SELECTION extends ResolverRecordsSelection>( | ||
| name: ForwardResolutionArgs<SELECTION>["name"], | ||
| name: InterpretedName, | ||
| selection: ForwardResolutionArgs<SELECTION>["selection"], | ||
| options: { registry: AccountId; accelerate: boolean; canAccelerate: boolean }, | ||
| ): Promise<ForwardResolutionResult<SELECTION>> { | ||
|
|
@@ -141,18 +139,11 @@ async function _resolveForward<SELECTION extends ResolverRecordsSelection>( | |
| // Validate Input | ||
| ////////////////////////////////////////////////// | ||
|
|
||
| // Invariant: Name must be normalized | ||
| if (!isNormalizedName(name)) { | ||
| throw new Error(`Invariant: Name "${name}" must be normalized.`); | ||
| } | ||
|
|
||
| const node: Node = namehashInterpretedName(asInterpretedName(name)); | ||
| const node: Node = namehashInterpretedName(name); | ||
| span.setAttribute("node", node); | ||
|
|
||
| // if selection is empty, give them what they asked for | ||
| if (isSelectionEmpty(selection)) { | ||
| return makeEmptyResolverRecordsResponse(selection); | ||
| } | ||
| if (isSelectionEmpty(selection)) return makeEmptyResolverRecordsResponse(selection); | ||
|
|
||
| // construct the set of resolve() calls indicated by selection | ||
| const calls = makeResolveCalls(node, selection); | ||
|
|
@@ -224,9 +215,7 @@ async function _resolveForward<SELECTION extends ResolverRecordsSelection>( | |
| !!activeResolver, | ||
| ); | ||
| // we're unable to find an active resolver for this name, return empty response | ||
| if (!activeResolver) { | ||
| return makeEmptyResolverRecordsResponse(selection); | ||
| } | ||
| if (!activeResolver) return makeEmptyResolverRecordsResponse(selection); | ||
|
|
||
| // set some attributes on the span for easy reference | ||
| span.setAttribute("activeResolver", activeResolver); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps remove this ignore and the
!and instead do the check here forparentNamebeing null and if so move the code here that generates the 404 error for name param not being the ENS Root.