Skip to content

Commit 0d64d9e

Browse files
authored
refactor: move replaceBigInts + toJson into ensnode-sdk (#1978)
1 parent 44b4385 commit 0d64d9e

22 files changed

Lines changed: 267 additions & 70 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@ensnode/ensnode-sdk": minor
3+
"ensapi": patch
4+
"ensindexer": patch
5+
---
6+
7+
Added `replaceBigInts` (sourced from `@ponder/utils`) and `toJson` helpers to `@ensnode/ensnode-sdk`. `toJson` now takes an options object (`{ pretty?: boolean }`) with `pretty` defaulting to `false` — pass `{ pretty: true }` for indented output. Migrated all in-repo call sites and dropped the `@ponder/utils` dependency from `ensapi`.

apps/ensadmin/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"@graphiql/toolkit": "0.11.3",
3333
"@icons-pack/react-simple-icons": "^13.7.0",
3434
"@namehash/namehash-ui": "workspace:*",
35-
"@ponder/utils": "catalog:",
3635
"@radix-ui/react-avatar": "^1.1.3",
3736
"@radix-ui/react-checkbox": "^1.3.3",
3837
"@radix-ui/react-collapsible": "^1.1.3",

apps/ensapi/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"@opentelemetry/sdk-trace-node": "^2.0.1",
4242
"@opentelemetry/semantic-conventions": "^1.34.0",
4343
"@ponder/client": "catalog:",
44-
"@ponder/utils": "catalog:",
4544
"@pothos/core": "^4.10.0",
4645
"@pothos/plugin-dataloader": "^4.4.3",
4746
"@pothos/plugin-relay": "^4.6.2",

apps/ensapi/src/handlers/api/resolution/resolution-api.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { replaceBigInts } from "@ponder/utils";
21
import type { Duration } from "enssdk";
32

4-
import type {
5-
ResolvePrimaryNameResponse,
6-
ResolvePrimaryNamesResponse,
7-
ResolveRecordsResponse,
3+
import {
4+
type ResolvePrimaryNameResponse,
5+
type ResolvePrimaryNamesResponse,
6+
type ResolveRecordsResponse,
7+
replaceBigInts,
88
} from "@ensnode/ensnode-sdk";
99

1010
import { createApp } from "@/lib/hono-factory";

apps/ensapi/src/lib/resolution/forward-resolution.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import config from "@/config";
22

33
import { trace } from "@opentelemetry/api";
4-
import { replaceBigInts } from "@ponder/utils";
54
import {
65
type AccountId,
76
asInterpretedName,
@@ -23,6 +22,7 @@ import {
2322
PluginName,
2423
type ResolverRecordsSelection,
2524
TraceableENSProtocol,
25+
toJson,
2626
} from "@ensnode/ensnode-sdk";
2727
import {
2828
isBridgedResolver,
@@ -119,7 +119,7 @@ async function _resolveForward<SELECTION extends ResolverRecordsSelection>(
119119
} = options;
120120

121121
// `selection` may contain bigints (e.g. `abi: ContentType`); stringify safely for tracing.
122-
const selectionString = JSON.stringify(replaceBigInts(selection, String));
122+
const selectionString = toJson(selection);
123123

124124
// trace for external consumers
125125
return withEnsProtocolStep(
@@ -164,7 +164,7 @@ async function _resolveForward<SELECTION extends ResolverRecordsSelection>(
164164

165165
// construct the set of resolve() operations indicated by node/selection
166166
let operations = makeOperations(node, selection);
167-
span.setAttribute("operations", JSON.stringify(replaceBigInts(operations, String)));
167+
span.setAttribute("operations", toJson(operations));
168168

169169
// if no operations were generated, this was an empty selection; give them what they asked for
170170
if (operations.length === 0) return makeRecordsResponse<SELECTION>(operations);
@@ -354,7 +354,7 @@ async function _resolveForward<SELECTION extends ResolverRecordsSelection>(
354354
// Invariant: all operations must be resolved
355355
if (!operations.every(isOperationResolved)) {
356356
throw new Error(
357-
`Invariant(forward-resolution): Not all operations were resolved at the end of resolution!\n${JSON.stringify(replaceBigInts(operations, String))}`,
357+
`Invariant(forward-resolution): Not all operations were resolved at the end of resolution!\n${toJson(operations, { pretty: true })}`,
358358
);
359359
}
360360

apps/ensindexer/src/lib/heal-addr-reverse-subname-label.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import config from "@/config";
33
import type { LabelHash, LiteralLabel, NormalizedAddress } from "enssdk";
44

55
import { getENSRootChainId } from "@ensnode/datasources";
6+
import { toJson } from "@ensnode/ensnode-sdk";
67

78
import type { IndexingEngineContext } from "@/lib/indexing-engines/ponder";
8-
import { toJson } from "@/lib/json-stringify-with-bigints";
99
import { maybeHealLabelByAddrReverseSubname } from "@/lib/maybe-heal-label-by-addr-reverse-subname";
1010
import type { EventWithArgs } from "@/lib/ponder-helpers";
1111
import {
@@ -101,6 +101,6 @@ export async function healAddrReverseSubnameLabel(
101101

102102
// Invariant: by this point, we should have healed all subnames of addr.reverse
103103
throw new Error(
104-
`Invariant(healAddrReverseSubnameLabel): Unable to heal the label for subname of addr.reverse with labelHash '${labelHash}'. Event:\n${toJson(event)}`,
104+
`Invariant(healAddrReverseSubnameLabel): Unable to heal the label for subname of addr.reverse with labelHash '${labelHash}'. Event:\n${toJson(event, { pretty: true })}`,
105105
);
106106
}

apps/ensindexer/src/lib/json-stringify-with-bigints.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ import {
1414
accountIdEqual,
1515
getDatasourceContract,
1616
maybeGetDatasourceContract,
17+
toJson,
1718
} from "@ensnode/ensnode-sdk";
1819

19-
import { toJson } from "@/lib/json-stringify-with-bigints";
20-
2120
/**
2221
* Many contracts within the ENSv1 Ecosystem are relative to a parent Name. For example,
2322
* the .eth BaseRegistrar (and RegistrarControllers) manage direct subnames of .eth. As such, they
@@ -162,7 +161,7 @@ export const getManagedName = (contract: AccountId): { name: InterpretedName; no
162161
}
163162

164163
throw new Error(
165-
`The following contract ${toJson(contract)} does not have a configured Managed Name. See apps/ensindexer/src/lib/managed-names.ts.`,
164+
`The following contract ${toJson(contract, { pretty: true })} does not have a configured Managed Name. See apps/ensindexer/src/lib/managed-names.ts.`,
166165
);
167166
};
168167

apps/ensindexer/src/plugins/ensv2/handlers/ensv1/BaseRegistrar.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import {
99
} from "enssdk";
1010
import { isAddressEqual, zeroAddress } from "viem";
1111

12-
import { interpretAddress, isRegistrationFullyExpired, PluginName } from "@ensnode/ensnode-sdk";
12+
import {
13+
interpretAddress,
14+
isRegistrationFullyExpired,
15+
PluginName,
16+
toJson,
17+
} from "@ensnode/ensnode-sdk";
1318

1419
import { ensureAccount } from "@/lib/ensv2/account-db-helpers";
1520
import { materializeENSv1DomainEffectiveOwner } from "@/lib/ensv2/domain-db-helpers";
@@ -25,7 +30,6 @@ import {
2530
ensIndexerSchema,
2631
type IndexingEngineContext,
2732
} from "@/lib/indexing-engines/ponder";
28-
import { toJson } from "@/lib/json-stringify-with-bigints";
2933
import { getManagedName } from "@/lib/managed-names";
3034
import { namespaceContract } from "@/lib/plugin-helpers";
3135
import type { EventWithArgs } from "@/lib/ponder-helpers";
@@ -120,7 +124,7 @@ export default function () {
120124
// Invariant: If there is an existing Registration, it must be fully expired.
121125
if (registration && !isFullyExpired) {
122126
throw new Error(
123-
`Invariant(BaseRegistrar:NameRegistered): Existing unexpired registration found in NameRegistered, expected none or expired.\n${toJson(registration)}`,
127+
`Invariant(BaseRegistrar:NameRegistered): Existing unexpired registration found in NameRegistered, expected none or expired.\n${toJson(registration, { pretty: true })}`,
124128
);
125129
}
126130

@@ -184,6 +188,7 @@ export default function () {
184188
node,
185189
domainId,
186190
},
191+
{ pretty: true },
187192
)}`,
188193
);
189194
}
@@ -193,6 +198,7 @@ export default function () {
193198
throw new Error(
194199
`Invariant(BaseRegistrar:NameRenewed): NameRenewed emitted for a non-BaseRegistrar registration:\n${toJson(
195200
{ labelHash, managedNode, node, domainId, registration },
201+
{ pretty: true },
196202
)}`,
197203
);
198204
}
@@ -202,6 +208,7 @@ export default function () {
202208
throw new Error(
203209
`Invariant(BaseRegistrar:NameRenewed): NameRenewed emitted for a BaseRegistrar registration that has a null expiry:\n${toJson(
204210
{ labelHash, managedNode, node, domainId, registration },
211+
{ pretty: true },
205212
)}`,
206213
);
207214
}
@@ -219,6 +226,7 @@ export default function () {
219226
registration,
220227
timestamp: event.block.timestamp,
221228
},
229+
{ pretty: true },
222230
)}`,
223231
);
224232
}

apps/ensindexer/src/plugins/ensv2/handlers/ensv1/NameWrapper.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
isRegistrationFullyExpired,
2222
isRegistrationInGracePeriod,
2323
PluginName,
24+
toJson,
2425
} from "@ensnode/ensnode-sdk";
2526

2627
import { ensureAccount } from "@/lib/ensv2/account-db-helpers";
@@ -38,7 +39,6 @@ import {
3839
ensIndexerSchema,
3940
type IndexingEngineContext,
4041
} from "@/lib/indexing-engines/ponder";
41-
import { toJson } from "@/lib/json-stringify-with-bigints";
4242
import { logger } from "@/lib/logger";
4343
import { getManagedName } from "@/lib/managed-names";
4444
import { namespaceContract } from "@/lib/plugin-helpers";
@@ -128,15 +128,15 @@ export default function () {
128128
// Invariant: must have Registration
129129
if (!registration) {
130130
throw new Error(
131-
`Invariant(NameWrapper:Transfer): Registration expected:\n${toJson(registration)}`,
131+
`Invariant(NameWrapper:Transfer): Registration expected:\n${toJson(registration, { pretty: true })}`,
132132
);
133133
}
134134

135135
// Invariant: Expired Registrations are non-transferrable if PCC is set
136136
const cannotTransferWhileExpired = registration.fuses && isPccFuseSet(registration.fuses);
137137
if (isExpired && cannotTransferWhileExpired) {
138138
throw new Error(
139-
`Invariant(NameWrapper:Transfer): Transfer of expired Registration with PARENT_CANNOT_CONTROL set:\n${toJson(registration)} ${JSON.stringify({ isPccFuseSet: isPccFuseSet(registration.fuses ?? 0) })}`,
139+
`Invariant(NameWrapper:Transfer): Transfer of expired Registration with PARENT_CANNOT_CONTROL set:\n${toJson(registration, { pretty: true })} ${JSON.stringify({ isPccFuseSet: isPccFuseSet(registration.fuses ?? 0) })}`,
140140
);
141141
}
142142

@@ -203,21 +203,21 @@ export default function () {
203203
// Invariant: Cannot wrap grace period names
204204
if (isRegistrationInGracePeriod(registration, event.block.timestamp)) {
205205
throw new Error(
206-
`Invariant(NameWrapper:NameWrapped): Cannot wrap direct-subname-of-registrar-managed-names in GRACE_PERIOD \n${toJson(registration)}`,
206+
`Invariant(NameWrapper:NameWrapped): Cannot wrap direct-subname-of-registrar-managed-names in GRACE_PERIOD \n${toJson(registration, { pretty: true })}`,
207207
);
208208
}
209209

210210
// Invariant: cannot re-wrap, right? NameWrapped -> NameUnwrapped -> NameWrapped
211211
if (registration.wrapped) {
212212
throw new Error(
213-
`Invariant(NameWrapper:NameWrapped): Re-wrapping already wrapped BaseRegistrar registration\n${toJson(registration)}`,
213+
`Invariant(NameWrapper:NameWrapped): Re-wrapping already wrapped BaseRegistrar registration\n${toJson(registration, { pretty: true })}`,
214214
);
215215
}
216216

217217
// Invariant: BaseRegistrar always provides expiry
218218
if (expiry === null) {
219219
throw new Error(
220-
`Invariant(NameWrapper:NameWrapped): Wrap of BaseRegistrar Registration does not include expiry!\n${toJson(registration)}`,
220+
`Invariant(NameWrapper:NameWrapped): Wrap of BaseRegistrar Registration does not include expiry!\n${toJson(registration, { pretty: true })}`,
221221
);
222222
}
223223

@@ -240,7 +240,7 @@ export default function () {
240240
// Invariant: If there's an existing Registration, it should be expired
241241
if (registration && !isFullyExpired) {
242242
throw new Error(
243-
`Invariant(NameWrapper:NameWrapped): NameWrapped but there's an existing unexpired non-BaseRegistrar Registration:\n${toJson({ registration, timestamp: event.block.timestamp })}`,
243+
`Invariant(NameWrapper:NameWrapped): NameWrapped but there's an existing unexpired non-BaseRegistrar Registration:\n${toJson({ registration, timestamp: event.block.timestamp }, { pretty: true })}`,
244244
);
245245
}
246246

@@ -327,7 +327,7 @@ export default function () {
327327
// Invariant: must have a Registration
328328
if (!registration) {
329329
throw new Error(
330-
`Invariant(NameWrapper:FusesSet): Registration expected:\n${toJson(registration)}`,
330+
`Invariant(NameWrapper:FusesSet): Registration expected:\n${toJson(registration, { pretty: true })}`,
331331
);
332332
}
333333

@@ -363,7 +363,7 @@ export default function () {
363363
// Invariant: must have Registration
364364
if (!registration) {
365365
throw new Error(
366-
`Invariant(NameWrapper:ExpiryExtended): Registration expected\n${toJson(registration)}`,
366+
`Invariant(NameWrapper:ExpiryExtended): Registration expected\n${toJson(registration, { pretty: true })}`,
367367
);
368368
}
369369

0 commit comments

Comments
 (0)