Better error message for unconfigured ENS names (#504).

This commit is contained in:
Richard Moore 2019-05-23 19:10:15 -04:00
parent c05768afab
commit 3cbc4b4622
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295

@ -452,7 +452,7 @@ export class BaseProvider extends Provider {
getBalance(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<BigNumber> { getBalance(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<BigNumber> {
return this._runPerform("getBalance", { return this._runPerform("getBalance", {
address: () => this.resolveName(addressOrName), address: () => this._getAddress(addressOrName),
blockTag: () => this._getBlockTag(blockTag) blockTag: () => this._getBlockTag(blockTag)
}).then((result) => { }).then((result) => {
return BigNumber.from(result); return BigNumber.from(result);
@ -461,7 +461,7 @@ export class BaseProvider extends Provider {
getTransactionCount(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<number> { getTransactionCount(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<number> {
return this._runPerform("getTransactionCount", { return this._runPerform("getTransactionCount", {
address: () => this.resolveName(addressOrName), address: () => this._getAddress(addressOrName),
blockTag: () => this._getBlockTag(blockTag) blockTag: () => this._getBlockTag(blockTag)
}).then((result) => { }).then((result) => {
return BigNumber.from(result).toNumber(); return BigNumber.from(result).toNumber();
@ -470,7 +470,7 @@ export class BaseProvider extends Provider {
getCode(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<string> { getCode(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<string> {
return this._runPerform("getCode", { return this._runPerform("getCode", {
address: () => this.resolveName(addressOrName), address: () => this._getAddress(addressOrName),
blockTag: () => this._getBlockTag(blockTag) blockTag: () => this._getBlockTag(blockTag)
}).then((result) => { }).then((result) => {
return hexlify(result); return hexlify(result);
@ -479,7 +479,7 @@ export class BaseProvider extends Provider {
getStorageAt(addressOrName: string | Promise<string>, position: BigNumberish | Promise<BigNumberish>, blockTag?: BlockTag | Promise<BlockTag>): Promise<string> { getStorageAt(addressOrName: string | Promise<string>, position: BigNumberish | Promise<BigNumberish>, blockTag?: BlockTag | Promise<BlockTag>): Promise<string> {
return this._runPerform("getStorageAt", { return this._runPerform("getStorageAt", {
address: () => this.resolveName(addressOrName), address: () => this._getAddress(addressOrName),
blockTag: () => this._getBlockTag(blockTag), blockTag: () => this._getBlockTag(blockTag),
position: () => Promise.resolve(position).then((p) => hexValue(p)) position: () => Promise.resolve(position).then((p) => hexValue(p))
}).then((result) => { }).then((result) => {
@ -546,7 +546,7 @@ export class BaseProvider extends Provider {
let tx: any = { }; let tx: any = { };
["from", "to"].forEach((key) => { ["from", "to"].forEach((key) => {
if (t[key] == null) { return; } 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) => { ["data", "gasLimit", "gasPrice", "value"].forEach((key) => {
if (t[key] == null) { return; } if (t[key] == null) { return; }
@ -561,7 +561,7 @@ export class BaseProvider extends Provider {
let filter: any = { }; let filter: any = { };
if (f.address != null) { if (f.address != null) {
filter.address = this.resolveName(f.address); filter.address = this._getAddress(f.address);
} }
if (f.topics) { if (f.topics) {
@ -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> { _getBlock(blockHashOrBlockTag: BlockTag | string | Promise<BlockTag | string>, includeTransactions?: boolean): Promise<Block | BlockWithTransactions> {
return this.ready.then(() => { return this.ready.then(() => {
return this._getBlockTag(blockHashOrBlockTag).then((blockHashOrBlockTag) => { return this._getBlockTag(blockHashOrBlockTag).then((blockHashOrBlockTag) => {