-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lib] Batch ENS queries using ReverseRecords smart contract
Summary: This resolves [ENG-2593](https://linear.app/comm/issue/ENG-2593/use-reverserecords-smart-contract-for-bulk-ens-name-lookups). For more info about this smart contract, see [official ENS docs](https://docs.ens.domains/dapp-developer-guide/resolving-names#reverse-resolution) and [GitHub repo](https://github.com/ensdomains/reverse-records). When I start my iOS app, it needs to resolve 142 ENS names to build the in-memory search indices for @-mentioning and inbox search. Before this diff, this meant 142 individual network requests to Alchemy. After this diff, it requires only 1. Depends on D9524 Test Plan: 1. Included updated unit tests. 2. I ran the iOS app and confirmed that the regression described [here](https://linear.app/comm/issue/ENG-5274/ens-resolution-for-chat-mentioning-causes-too-many-react-rerenders#comment-a7405e2f) was resolved. 3. I added a log statement to the code that issues a "single fetch" to confirm that it wasn't getting triggered anymore on iOS app start. (One "single fetch" was actually triggered, but it was for an ENS name that appeared immediately in my inbox... I think this is actually what we want, since we need that result more urgently.) 4. I confirmed that ENS resolution still worked on the iOS app. 5. I confirmed that ENS resolution still worked on the web app. 6. I confirmed that the keyserver is still able to resolve ENS names in notifs. Reviewers: rohan, atul, tomek Reviewed By: tomek Subscribers: tomek, wyilio Differential Revision: https://phab.comm.dev/D9525
- Loading branch information
Showing
5 changed files
with
292 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// @flow | ||
|
||
type ABIParam = { | ||
+internalType: string, | ||
+name: string, | ||
+type: string, | ||
}; | ||
type EthereumSmartContractABI = $ReadOnlyArray<{ | ||
+inputs: $ReadOnlyArray<ABIParam>, | ||
+stateMutability: string, | ||
+type: string, | ||
+name?: ?string, | ||
+outputs?: ?$ReadOnlyArray<ABIParam>, | ||
}>; | ||
|
||
const resolverABI: EthereumSmartContractABI = [ | ||
{ | ||
inputs: [{ internalType: 'contract ENS', name: '_ens', type: 'address' }], | ||
stateMutability: 'nonpayable', | ||
type: 'constructor', | ||
}, | ||
{ | ||
inputs: [ | ||
{ internalType: 'address[]', name: 'addresses', type: 'address[]' }, | ||
], | ||
name: 'getNames', | ||
outputs: [{ internalType: 'string[]', name: 'r', type: 'string[]' }], | ||
stateMutability: 'view', | ||
type: 'function', | ||
}, | ||
]; | ||
|
||
const mainnetChainID = 1; | ||
const goerliChainID = 5; | ||
const resolverAddresses: { +[chainID: number]: string } = { | ||
[mainnetChainID]: '0x3671aE578E63FdF66ad4F3E12CC0c0d71Ac7510C', | ||
[goerliChainID]: '0x333Fc8f550043f239a2CF79aEd5e9cF4A20Eb41e', | ||
}; | ||
|
||
export type ReverseRecordsEthersSmartContract = { | ||
+'getNames(address[])': ($ReadOnlyArray<string>) => Promise<string[]>, | ||
... | ||
}; | ||
|
||
export { resolverABI, resolverAddresses }; |