Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3390302
D11487.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D11487.diff
View Options
diff --git a/lib/utils/ens-cache.js b/lib/utils/ens-cache.js
--- a/lib/utils/ens-cache.js
+++ b/lib/utils/ens-cache.js
@@ -58,7 +58,7 @@
class ENSCache {
provider: EthersProvider;
batchReverseResolverSmartContract: ?ReverseRecordsEthersSmartContract;
- batchReverseResolverSmartContractPromise: Promise<ReverseRecordsEthersSmartContract>;
+ batchReverseResolverSmartContractPromise: Promise<?ReverseRecordsEthersSmartContract>;
// Maps from normalized ETH address to a cache entry for its name
nameQueryCache: Map<string, ENSNameQueryCacheEntry> = new Map();
@@ -72,15 +72,15 @@
this.batchReverseResolverSmartContractPromise = (async () => {
const { chainId } = await provider.getNetwork();
const reverseRecordsAddress = resolverAddresses[chainId];
- invariant(
- reverseRecordsAddress,
- `no ReverseRecords smart contract address for chaind ID ${chainId}!`,
- );
- this.batchReverseResolverSmartContract = new Contract(
- reverseRecordsAddress,
- resolverABI,
- provider,
- );
+ if (reverseRecordsAddress) {
+ this.batchReverseResolverSmartContract = new Contract(
+ reverseRecordsAddress,
+ resolverABI,
+ provider,
+ );
+ } else {
+ this.batchReverseResolverSmartContract = null;
+ }
return this.batchReverseResolverSmartContract;
})();
}
@@ -182,25 +182,31 @@
let smartContract;
if (batchReverseResolverSmartContract) {
smartContract = batchReverseResolverSmartContract;
- } else {
+ } else if (batchReverseResolverSmartContract !== null) {
smartContract = await batchReverseResolverSmartContractPromise;
}
// ReverseRecords smart contract handles checking forward resolution
let ensNames: $ReadOnlyArray<?string>;
- try {
- const raceResult = await Promise.race([
- smartContract['getNames(address[])'](needFetch),
- throwOnTimeout(`names for ${JSON.stringify(needFetch)}`),
- ]);
- invariant(
- Array.isArray(raceResult),
- 'ReverseRecords smart contract should return array',
+ if (smartContract) {
+ try {
+ const raceResult = await Promise.race([
+ smartContract['getNames(address[])'](needFetch),
+ throwOnTimeout(`names for ${JSON.stringify(needFetch)}`),
+ ]);
+ invariant(
+ Array.isArray(raceResult),
+ 'ReverseRecords smart contract should return array',
+ );
+ ensNames = raceResult;
+ } catch (e) {
+ console.log(e);
+ ensNames = new Array<?string>(needFetch.length).fill(null);
+ }
+ } else {
+ ensNames = await Promise.all(
+ needFetch.map(ethAddress => this.getNameForAddress(ethAddress)),
);
- ensNames = raceResult;
- } catch (e) {
- console.log(e);
- ensNames = new Array<?string>(needFetch.length).fill(null);
}
const resultMap = new Map<string, ?string>();
diff --git a/lib/utils/ens-cache.test.js b/lib/utils/ens-cache.test.js
--- a/lib/utils/ens-cache.test.js
+++ b/lib/utils/ens-cache.test.js
@@ -183,7 +183,14 @@
const timesLookupAddressCalledAfter = timesLookupAddressCalled;
const timesLookupAddressCalledDuringTest =
timesLookupAddressCalledAfter - timesLookupAddressCalledBefore;
- expect(timesLookupAddressCalledDuringTest).toBe(0);
+
+ // These tests are run on the Sepolia testnet, where the ReverseRecords
+ // smart contract is not deployed. As a result, we end up needing to call
+ // the lookupAddress method (single lookup) once for each address. On
+ // mainnet (outside of these tests) this is 0, since the ReverseRecords
+ // smart contract lets us batch up our requests, and avoid calling
+ // lookupAddress entirely.
+ expect(timesLookupAddressCalledDuringTest).toBe(3);
expect(ashoatEthResult1).toBe(ashoatDotEth);
expect(commalphaEthResult1).toBe(commalphaDotEth);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 30, 11:13 PM (19 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2602727
Default Alt Text
D11487.diff (3 KB)
Attached To
Mode
D11487: [lib] Allow getNamesForAddresses to be called without ReverseRecords smart contract
Attached
Detach File
Event Timeline
Log In to Comment