Skip to content

Commit

Permalink
6992 getText update and getName fix (#7047)
Browse files Browse the repository at this point in the history
* getText with address as input

* reverse resolution support

* changelog update

* fix

* lint fix

* name update

* updated getname test
  • Loading branch information
jdevcs committed May 24, 2024
1 parent 692987a commit 962b99f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
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()
}
}
7 changes: 5 additions & 2 deletions packages/web3-eth-ens/test/unit/resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ describe('resolver', () => {

describe('name', () => {
it('getName', async () => {
const address = "0x314159265dd8dbb310642f98f50c066173c1259b";

const supportsInterfaceMock = jest
.spyOn(contract.methods, 'supportsInterface')
.mockReturnValue({
Expand All @@ -255,12 +257,13 @@ describe('resolver', () => {
});
});

await resolver.getName(ENS_NAME);
await resolver.getName(address);
expect(supportsInterfaceMock).toHaveBeenCalledWith(
interfaceIds[methodsInInterface.name],
);

expect(nameMock).toHaveBeenCalledWith(namehash(ENS_NAME));
const reverseName = `${address.toLowerCase().substring(2)}.addr.reverse`;
expect(nameMock).toHaveBeenCalledWith(namehash(reverseName));
})
})

Expand Down

1 comment on commit 962b99f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 962b99f Previous: 692987a Ratio
processingTx 9347 ops/sec (±4.12%) 8880 ops/sec (±3.76%) 0.95
processingContractDeploy 39267 ops/sec (±7.45%) 38813 ops/sec (±6.13%) 0.99
processingContractMethodSend 20364 ops/sec (±6.85%) 18943 ops/sec (±7.10%) 0.93
processingContractMethodCall 41222 ops/sec (±6.07%) 38006 ops/sec (±5.78%) 0.92
abiEncode 46343 ops/sec (±6.97%) 43737 ops/sec (±6.49%) 0.94
abiDecode 30832 ops/sec (±8.28%) 29525 ops/sec (±8.05%) 0.96
sign 1603 ops/sec (±3.74%) 1523 ops/sec (±3.37%) 0.95
verify 380 ops/sec (±0.55%) 371 ops/sec (±0.54%) 0.98

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.