Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

feat: impl rns.resolver(name) - getter function #122

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ export default class extends Composer implements RNS {
return this._resolutions.setContenthash(domain, content, options);
}

/**
* Get decoded contenthash of a given domain.
*
* @throws DOMAIN_NOT_EXISTS if the given domain does not exists - KB012
* @throws NO_RESOLVER when the domain doesn't have resolver - KB003
*
* @param domain - Domain to be resolved
*
* @returns Address of the resolver associated with the given domain
*/
resolver(domain: string): Promise<string> {
return this._resolutions.resolver(domain);
}

/**
* Set resolver of a given domain.
*
Expand Down
19 changes: 19 additions & 0 deletions src/resolutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,25 @@ export default class extends Composer implements Resolutions {
return this.estimateGasAndSendTransaction(contractMethod, options);
}

async resolver(domain: string): Promise<string> {
await this.compose();
const node: string = namehash(domain);

const domainOwner = await
this._contracts.registry.methods.owner(node).call();
if (domainOwner === ZERO_ADDRESS) {
this._throw(DOMAIN_NOT_EXISTS);
}

const resolverAddress: string = await
this._contracts.registry.methods.resolver(node).call();
if (resolverAddress === ZERO_ADDRESS) {
this._throw(NO_RESOLVER);
}

return resolverAddress;
}

async setResolver(
domain: string, resolver: string, options?: TransactionOptions,
): Promise<string> {
Expand Down
7 changes: 7 additions & 0 deletions src/types/resolutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ export interface Resolutions {
*/
setContenthash(domain: string, content: string, options?: TransactionOptions): any;

/**
* Get resolver of a given domain.
*
* @param domain - Domain to be resolved
*/
resolver(domain: string): Promise<string>;

/**
* Set resolver of a given domain.
*
Expand Down