Skip to content

Commit

Permalink
feat: add new initialization param - chainId and deploy mainnet registry
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceban Mihail committed Feb 14, 2024
1 parent 324fb83 commit 7b8e55f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xype-resolver",
"version": "1.1.0",
"version": "1.2.0",
"description": "The Xype Name Resolver Library",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const XYPE_REGISTRY_ADDRESS = {
1: '0x2C1E6E5F4cd8Aa0f103e8653ea109A0b8b1aAf70',
5: '0x2C1E6E5F4cd8Aa0f103e8653ea109A0b8b1aAf70',
1: '0x5db0E9eD56EF5B3760cE7887BAf215a39dE8d61E',
5: '',
11155111: '0x2C1E6E5F4cd8Aa0f103e8653ea109A0b8b1aAf70',
} as Record<number, string>;

Expand Down
10 changes: 8 additions & 2 deletions src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,23 @@ export class XypeResolver {
* Creates the XypeResolver instance with specified Web3Connection type
*
* @param connection A string representing RPC URL or the JsonRpcProvider object
* @param chainId An optional number representing the chain id
* @returns New XypeResolver instance
*/
public static async init(connection: Web3Connection): Promise<XypeResolver> {
public static async init(
connection: Web3Connection,
chainId?: number
): Promise<XypeResolver> {
const provider =
connection instanceof ethers.providers.JsonRpcProvider
? connection
: new ethers.providers.JsonRpcProvider(connection);

// add network support check
const xypeRegistry = new Contract(
XYPE_REGISTRY_ADDRESS[Number((await provider.getNetwork()).chainId)],
XYPE_REGISTRY_ADDRESS[
chainId ? chainId : Number((await provider.getNetwork()).chainId)
],
REGISTRY_ABI,
provider
);
Expand Down
10 changes: 8 additions & 2 deletions test/resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ describe('XypeResolver', () => {

expect((xypeResolver = await XypeResolver.init(provider)));
expect((xypeResolver = await XypeResolver.init(PUBLIC_RPC_NODES[0])));
expect(
(xypeResolver = await XypeResolver.init(
provider,
Number((await provider.getNetwork()).chainId)
))
);
});
});

Expand Down Expand Up @@ -47,9 +53,9 @@ describe('XypeResolver', () => {
describe('lookupAddress', () => {
it('lookupAddress: 0xb305c1f2200a17E0502416B1746aB88C9B5C449f - success resolution', async () => {
const addr = await xypeResolver.lookupAddress(
'0xc46DA945f66EBe2E55f49EF9e401ec9eA7C3eC61'
'0xcefc9fcc056a8c888698b50fd88453cc66c6abc6'
);
expect(addr).toEqual('qwery.sxt');
expect(addr).toEqual('abc55.trustyfy');
});

it('lookupAddress: 0xf2EA5Fd6538EAb3B0466f1b1A447C742d8b30eFe - expired', async () => {
Expand Down

0 comments on commit 7b8e55f

Please sign in to comment.