Better errors when non-string address or ENS name is passed into Contracts or provider methods (#1051).
This commit is contained in:
parent
8947fd405e
commit
a5c6a468f4
@ -116,6 +116,10 @@ const allowedTransactionKeys: { [ key: string ]: boolean } = {
|
|||||||
async function resolveName(resolver: Signer | Provider, nameOrPromise: string | Promise<string>): Promise<string> {
|
async function resolveName(resolver: Signer | Provider, nameOrPromise: string | Promise<string>): Promise<string> {
|
||||||
const name = await nameOrPromise;
|
const name = await nameOrPromise;
|
||||||
|
|
||||||
|
if (typeof(name) !== "string") {
|
||||||
|
logger.throwArgumentError("invalid address or ENS name", "name", name);
|
||||||
|
}
|
||||||
|
|
||||||
// If it is already an address, just use it (after adding checksum)
|
// If it is already an address, just use it (after adding checksum)
|
||||||
try {
|
try {
|
||||||
return getAddress(name);
|
return getAddress(name);
|
||||||
|
@ -1313,6 +1313,11 @@ export class BaseProvider extends Provider implements EnsProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _getAddress(addressOrName: string | Promise<string>): Promise<string> {
|
async _getAddress(addressOrName: string | Promise<string>): Promise<string> {
|
||||||
|
addressOrName = await addressOrName;
|
||||||
|
if (typeof(addressOrName) !== "string") {
|
||||||
|
logger.throwArgumentError("invalid address or ENS name", "name", addressOrName);
|
||||||
|
}
|
||||||
|
|
||||||
const address = await this.resolveName(addressOrName);
|
const address = await this.resolveName(addressOrName);
|
||||||
if (address == null) {
|
if (address == null) {
|
||||||
logger.throwError("ENS name not configured", Logger.errors.UNSUPPORTED_OPERATION, {
|
logger.throwError("ENS name not configured", Logger.errors.UNSUPPORTED_OPERATION, {
|
||||||
|
Loading…
Reference in New Issue
Block a user