Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6992 getText update and getName fix #7047

Merged
merged 8 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/web3-eth-ens/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,13 @@ Documentation:

- `defaultReturnFormat` was added to all methods that have `ReturnType` param. (#6947)

## [Unreleased]
## [Unreleased]

### Added

- `getText` now supports first param Address
- `getName` has optional second param checkInterfaceSupport

### Fixed

- `getName` reverse resolution
11 changes: 7 additions & 4 deletions packages/web3-eth-ens/src/ens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
TransactionReceipt,
Web3NetAPI,
} from 'web3-types';
import { isAddress } from 'web3-validator';
import { PublicResolverAbi } from './abi/ens/PublicResolver.js';
import { networkIds, registryAddresses } from './config.js';
import { Registry } from './registry.js';
Expand Down Expand Up @@ -174,17 +175,19 @@ export class ENS extends Web3Context<EthExecutionAPI & Web3NetAPI> {
* @param key - The key to resolve https://github.com/ethereum/ercs/blob/master/ERCS/erc-634.md#global-keys
* @returns - The value content stored in the resolver for the specified key
*/
public async getText(ENSName: string, key: string): Promise<string> {
return this._resolver.getText(ENSName, key);
public async getText(ENSNameOrAddr: string | Address, key: string): Promise<string> {
if(isAddress(ENSNameOrAddr))
return this._resolver.getText(await(this._resolver.getName(ENSNameOrAddr,false)), key);
return this._resolver.getText(ENSNameOrAddr, key);
}

/**
* Resolves the name of an ENS node.
* @param ENSName - The node to resolve
* @returns - The name
*/
public async getName(ENSName: string): Promise<string> {
return this._resolver.getName(ENSName);
public async getName(ENSName: string, checkInterfaceSupport = true): Promise<string> {
return this._resolver.getName(ENSName, checkInterfaceSupport);
}

/**
Expand Down
13 changes: 9 additions & 4 deletions packages/web3-eth-ens/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,17 @@ export class Resolver {
}

public async getName(
address: string
address: string,
checkInterfaceSupport = true
) {
const resolverContract = await this.getResolverContractAdapter(address);
await this.checkInterfaceSupport(resolverContract, methodsInInterface.name);
const reverseName = `${address.toLowerCase().substring(2)}.addr.reverse`;

const resolverContract = await this.getResolverContractAdapter(reverseName);

if(checkInterfaceSupport)
await this.checkInterfaceSupport(resolverContract, methodsInInterface.name);

return resolverContract.methods
.name(namehash(address)).call()
.name(namehash(reverseName)).call()
}
}
Loading