Skip to content

Commit

Permalink
Better error message for unconfigured ENS names (#504).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed May 23, 2019
1 parent c05768a commit 3cbc4b4
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions packages/providers/src.ts/base-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ export class BaseProvider extends Provider {

getBalance(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<BigNumber> {
return this._runPerform("getBalance", {
address: () => this.resolveName(addressOrName),
address: () => this._getAddress(addressOrName),
blockTag: () => this._getBlockTag(blockTag)
}).then((result) => {
return BigNumber.from(result);
Expand All @@ -461,7 +461,7 @@ export class BaseProvider extends Provider {

getTransactionCount(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<number> {
return this._runPerform("getTransactionCount", {
address: () => this.resolveName(addressOrName),
address: () => this._getAddress(addressOrName),
blockTag: () => this._getBlockTag(blockTag)
}).then((result) => {
return BigNumber.from(result).toNumber();
Expand All @@ -470,7 +470,7 @@ export class BaseProvider extends Provider {

getCode(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<string> {
return this._runPerform("getCode", {
address: () => this.resolveName(addressOrName),
address: () => this._getAddress(addressOrName),
blockTag: () => this._getBlockTag(blockTag)
}).then((result) => {
return hexlify(result);
Expand All @@ -479,7 +479,7 @@ export class BaseProvider extends Provider {

getStorageAt(addressOrName: string | Promise<string>, position: BigNumberish | Promise<BigNumberish>, blockTag?: BlockTag | Promise<BlockTag>): Promise<string> {
return this._runPerform("getStorageAt", {
address: () => this.resolveName(addressOrName),
address: () => this._getAddress(addressOrName),
blockTag: () => this._getBlockTag(blockTag),
position: () => Promise.resolve(position).then((p) => hexValue(p))
}).then((result) => {
Expand Down Expand Up @@ -546,7 +546,7 @@ export class BaseProvider extends Provider {
let tx: any = { };
["from", "to"].forEach((key) => {
if (t[key] == null) { return; }
tx[key] = Promise.resolve(t[key]).then(a => (a ? this.resolveName(a): null))
tx[key] = Promise.resolve(t[key]).then(a => (a ? this._getAddress(a): null))
});
["data", "gasLimit", "gasPrice", "value"].forEach((key) => {
if (t[key] == null) { return; }
Expand All @@ -561,7 +561,7 @@ export class BaseProvider extends Provider {
let filter: any = { };

if (f.address != null) {
filter.address = this.resolveName(f.address);
filter.address = this._getAddress(f.address);
}

if (f.topics) {
Expand Down Expand Up @@ -599,6 +599,17 @@ export class BaseProvider extends Provider {
});
}

_getAddress(addressOrName: string | Promise<string>): Promise<string> {
return this.resolveName(addressOrName).then((address) => {
if (address == null) {
errors.throwError("ENS name not configured", errors.UNSUPPORTED_OPERATION, {
operation: `resolveName(${ JSON.stringify(addressOrName) })`
});
}
return address;
});
}

_getBlock(blockHashOrBlockTag: BlockTag | string | Promise<BlockTag | string>, includeTransactions?: boolean): Promise<Block | BlockWithTransactions> {
return this.ready.then(() => {
return this._getBlockTag(blockHashOrBlockTag).then((blockHashOrBlockTag) => {
Expand Down

0 comments on commit 3cbc4b4

Please sign in to comment.