Skip to content

Commit 7bf56d3

Browse files
committed
fix: tidy up after self-review
1 parent 70069b1 commit 7bf56d3

8 files changed

Lines changed: 35 additions & 38 deletions

File tree

apps/ensapi/src/omnigraph-api/schema/resolver.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import config from "@/config";
33
import { type ResolveCursorConnectionArgs, resolveCursorConnection } from "@pothos/plugin-relay";
44
import { and, eq } from "drizzle-orm";
55
import {
6-
asInterpretedName,
76
makePermissionsId,
87
makeResolverRecordsId,
98
namehashInterpretedName,
@@ -114,7 +113,7 @@ ResolverRef.implement({
114113
args: { for: t.arg({ type: NameOrNodeInput, required: true }) },
115114
nullable: true,
116115
resolve: async ({ chainId, address }, args) => {
117-
const node = args.for.node ?? namehashInterpretedName(asInterpretedName(args.for.name));
116+
const node = args.for.node ?? namehashInterpretedName(args.for.name);
118117
return makeResolverRecordsId({ chainId, address }, node);
119118
},
120119
}),

apps/ensindexer/src/lib/managed-names.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type AccountId, asInterpretedName, namehashInterpretedName } from "enssdk";
1+
import { type AccountId, ETH_NODE } from "enssdk";
22
import { zeroAddress } from "viem";
33
import { beforeEach, describe, expect, it, vi } from "vitest";
44

@@ -37,8 +37,6 @@ const controller = getDatasourceContract(
3737
"LegacyEthRegistrarController",
3838
);
3939

40-
const ETH_NODE = namehashInterpretedName(asInterpretedName("eth"));
41-
4240
describe("managed-names", () => {
4341
beforeEach(() => {
4442
vi.resetAllMocks();

apps/ensindexer/src/lib/managed-names.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ export const getManagedName = (contract: AccountId): { name: InterpretedName; no
152152
const namespaceSpecific = MANAGED_NAME_BY_NAMESPACE[config.namespace]?.[managedName];
153153

154154
// use the namespace-specific Managed Name if specified, otherwise use the default from CONTRACTS_BY_MANAGED_NAME
155-
const name = asInterpretedName(namespaceSpecific ?? managedName);
155+
// NOTE: we cast to InterpretedName directly to avoid the overhead of asInterpretedName and
156+
// both namespaceSpecific and managedName are guaranteed to be InterpretedName (see above)
157+
const name = (namespaceSpecific ?? managedName) as InterpretedName;
156158
const node = cachedNamehash(name);
157159

158160
return { name, node };

apps/ensindexer/src/plugins/subgraph/shared-handlers/ThreeDNSToken.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function decodeFQDN(fqdn: DNSEncodedLiteralName): {
8080
}
8181

8282
// due the invariant above, we know that all of the labels are normalized (and therefore Interpreted Labels)
83-
const interpretedLabels = literalLabels.map((l) => asInterpretedLabel(l));
83+
const interpretedLabels = literalLabels.map(asInterpretedLabel);
8484

8585
return {
8686
// biome-ignore lint/style/noNonNullAssertion: ok due to length invariant above

packages/ensnode-sdk/src/ensapi/client.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,9 @@ export class EnsApiClient {
410410
* registrarActionsFilter,
411411
* EnsApiClient,
412412
* } from "@ensnode/ensnode-sdk";
413-
* import { namehashInterpretedName } from "enssdk";
413+
* import { ETH_NODE, namehashInterpretedName, asInterpretedName } from "enssdk";
414+
*
415+
* const BASE_NODE = namehashInterpretedName(asInterpretedName("base.eth"));
414416
*
415417
* const client: EnsApiClient;
416418
*
@@ -432,7 +434,7 @@ export class EnsApiClient {
432434
* // get latest registrar action records associated with
433435
* // subregistry managing `eth` name
434436
* await client.registrarActions({
435-
* filters: [registrarActionsFilter.byParentNode(namehash('eth'))],
437+
* filters: [registrarActionsFilter.byParentNode(ETH_NODE)],
436438
* });
437439
*
438440
* // get latest registrar action records which include referral info
@@ -448,7 +450,7 @@ export class EnsApiClient {
448450
* // get latest 10 registrar action records associated with
449451
* // subregistry managing `base.eth` name
450452
* await client.registrarActions({
451-
* filters: [registrarActionsFilter.byParentNode(namehash('base.eth'))],
453+
* filters: [registrarActionsFilter.byParentNode(BASE_NODE)],
452454
* recordsPerPage: 10
453455
* });
454456
*
@@ -622,17 +624,20 @@ export class EnsApiClient {
622624
* import {
623625
* EnsApiClient,
624626
* } from "@ensnode/ensnode-sdk";
625-
* import { namehashInterpretedName } from "enssdk";
627+
* import { namehashInterpretedName, asInterpretedName } from "enssdk";
628+
*
629+
* const VITALIK_NAME = asInterpretedName("vitalik.eth");
630+
* const VITALIK_DOMAIN_ID = namehashInterpretedName(vitalik);
626631
*
627632
* const client: EnsApiClient;
628633
*
629634
* // get latest name token records from the indexed subregistry based on the requested name
630635
* const response = await client.nameTokens({
631-
* name: "vitalik.eth"
636+
* name: VITALIK_NAME,
632637
* });
633638
*
634639
* const response = await client.nameTokens({
635-
* domainId: "0xee6c4522aab0003e8d14cd40a6af439055fd2577951148c14b6cea9a53475835" // namehash('vitalik.eth')
640+
* domainId: VITALIK_DOMAIN_ID,
636641
* })
637642
* ```
638643
*/

packages/enssdk/src/lib/dns-encoded-name.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import { asLiteralLabel } from "./interpreted-names-and-labels";
77
import { encodeLabelHash, labelhashLiteralLabel } from "./labelhash";
88
import type { DNSEncodedName } from "./types";
99

10-
const MULTI_BYTE_UNICODE_NAMES = [
11-
"\u{1F469}\u{1F3FC}\u200D\u2764\u200D\u{1F48B}\u200D\u{1F468}\u{1F3FC}.eth",
12-
];
10+
const MULTI_BYTE_UNICODE_NAMES = ["👩🏼‍❤‍💋‍👨🏼.eth"];
1311

1412
describe("decodeDNSEncodedName", () => {
1513
it("handles root node", () => {

packages/enssdk/src/lib/interpreted-names-and-labels.test.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
parsePartialInterpretedName,
1111
} from "./interpreted-names-and-labels";
1212
import { encodeLabelHash, labelhashLiteralLabel } from "./labelhash";
13-
import type { InterpretedLabel, InterpretedName, Name } from "./types";
13+
import type { InterpretedLabel, InterpretedName, LiteralLabel, Name } from "./types";
1414

1515
const ENCODED_LABELHASH_LABEL = /^\[[\da-f]{64}\]$/;
1616

@@ -20,9 +20,9 @@ const NORMALIZED_LABELS = [
2020
"test",
2121
"eth",
2222
"base",
23-
"\u{1F525}",
24-
"test\u{1F382}",
25-
"caf\u00E9",
23+
"🔥",
24+
"test🎂",
25+
"café",
2626
"sub",
2727
"a".repeat(512), // Long normalized
2828
].map(asLiteralLabel);
@@ -91,15 +91,13 @@ describe("interpretation", () => {
9191
});
9292

9393
it("correctly interprets an empty array of labels", () => {
94-
expect(literalLabelsToInterpretedName(([] as string[]).map(asLiteralLabel))).toEqual("");
94+
expect(literalLabelsToInterpretedName([] as LiteralLabel[])).toEqual("");
9595
});
9696
});
9797

9898
describe("interpretedLabelsToInterpretedName", () => {
9999
it("correctly interprets an empty array of labels", () => {
100-
expect(interpretedLabelsToInterpretedName(([] as string[]).map(asInterpretedLabel))).toEqual(
101-
"",
102-
);
100+
expect(interpretedLabelsToInterpretedName([] as InterpretedLabel[])).toEqual("");
103101
});
104102

105103
it("correctly interprets a single label", () => {
@@ -111,12 +109,9 @@ describe("interpretation", () => {
111109
const interpretedLabelThatLooksLikeALabelHash = literalLabelToInterpretedLabel(literalLabel);
112110

113111
expect(
114-
interpretedLabelsToInterpretedName([
115-
asInterpretedLabel("a"),
116-
asInterpretedLabel("b"),
117-
asInterpretedLabel("c"),
118-
interpretedLabelThatLooksLikeALabelHash,
119-
]),
112+
interpretedLabelsToInterpretedName(
113+
["a", "b", "c", interpretedLabelThatLooksLikeALabelHash].map(asInterpretedLabel),
114+
),
120115
).toEqual(`a.b.c.${interpretedLabelThatLooksLikeALabelHash}`);
121116
});
122117
});
@@ -129,7 +124,7 @@ describe("interpretation", () => {
129124
["t", [], "t"],
130125
["test", [], "test"],
131126
["exam", [], "exam"],
132-
["\u{1F525}", [], "\u{1F525}"],
127+
["🔥", [], "🔥"],
133128
// concrete TLD with empty partial
134129
["eth.", ["eth"], ""],
135130
["base.", ["base"], ""],
@@ -198,8 +193,8 @@ describe("interpretation", () => {
198193
// with encoded labelhash in parent
199194
["sub", `${EXAMPLE_ENCODED_LABEL_HASH}.eth`, `sub.${EXAMPLE_ENCODED_LABEL_HASH}.eth`],
200195
// emoji labels
201-
["\u{1F525}", "eth", "\u{1F525}.eth"],
202-
["wallet", "\u{1F525}.eth", "wallet.\u{1F525}.eth"],
196+
["🔥", "eth", "🔥.eth"],
197+
["wallet", "🔥.eth", "wallet.🔥.eth"],
203198
] as [InterpretedLabel, InterpretedName | undefined, InterpretedName][])(
204199
"constructSubInterpretedName(%j, %j) → %j",
205200
(label, parent, expected) => {

packages/enssdk/src/lib/normalization.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const NORMALIZED_LABELS = [
88
"test",
99
"eth",
1010
"base",
11-
"\u{1F525}",
12-
"test\u{1F382}",
13-
"caf\u00E9",
11+
"🔥",
12+
"test🎂",
13+
"café",
1414
"sub",
1515
"a".repeat(512), // Long normalized
1616
];
@@ -19,8 +19,8 @@ const UNNORMALIZED_LABELS = [
1919
"VITALIK", // normalizable but not normalized
2020
"", // empty string
2121
"abc.123", // contains full-stop
22-
"\u0435thchina", // \u0435thchina
23-
"\u0435thgold", // same situation
22+
"еthchina", // \u0435thchina
23+
"еthgold", // same situation
2424
"Vitalik", // Uppercase
2525
"Example", // Uppercase
2626
"TEST", // Uppercase

0 commit comments

Comments
 (0)