Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 34x 34x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 36x 36x 36x 36x 36x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6618x 6618x 6584x 2x 2x 2x 2x 2x 2x 6618x 34x 34x 34x | import { assert, assertArgument } from "../utils/index.js"; import { getAddress } from "./address.js"; import type { Addressable, AddressLike, NameResolver } from "./index.js"; /** * Returns true if %%value%% is an object which implements the * [[Addressable]] interface. * * @example: * // Wallets and AbstractSigner sub-classes * isAddressable(Wallet.createRandom()) * //_result: * * // Contracts * contract = new Contract("dai.tokens.ethers.eth", [ ], provider) * isAddressable(contract) * //_result: */ export function isAddressable(value: any): value is Addressable { return (value && typeof(value.getAddress) === "function"); } /** * Returns true if %%value%% is a valid address. * * @example: * // Valid address * isAddress("0x8ba1f109551bD432803012645Ac136ddd64DBA72") * //_result: * * // Valid ICAP address * isAddress("XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK36") * //_result: * * // Invalid checksum * isAddress("0x8Ba1f109551bD432803012645Ac136ddd64DBa72") * //_result: * * // Invalid ICAP checksum * isAddress("0x8Ba1f109551bD432803012645Ac136ddd64DBA72") * //_result: * * // Not an address (an ENS name requires a provided and an * // asynchronous API to access) * isAddress("ricmoo.eth") * //_result: */ export function isAddress(value: any): value is string { try { getAddress(value); return true; } catch (error) { } return false; } async function checkAddress(target: any, promise: Promise<null | string>): Promise<string> { const result = await promise; if (result == null || result === "0x0000000000000000000000000000000000000000") { assert(typeof(target) !== "string", "unconfigured name", "UNCONFIGURED_NAME", { value: target }); assertArgument(false, "invalid AddressLike value; did not resolve to a value address", "target", target); } return getAddress(result); } /** * Resolves to an address for the %%target%%, which may be any * supported address type, an [[Addressable]] or a Promise which * resolves to an address. * * If an ENS name is provided, but that name has not been correctly * configured a [[UnconfiguredNameError]] is thrown. * * @example: * addr = "0x6B175474E89094C44Da98b954EedeAC495271d0F" * * // Addresses are return synchronously * resolveAddress(addr, provider) * //_result: * * // Address promises are resolved asynchronously * resolveAddress(Promise.resolve(addr)) * //_result: * * // ENS names are resolved asynchronously * resolveAddress("dai.tokens.ethers.eth", provider) * //_result: * * // Addressable objects are resolved asynchronously * contract = new Contract(addr, [ ]) * resolveAddress(contract, provider) * //_result: * * // Unconfigured ENS names reject * resolveAddress("nothing-here.ricmoo.eth", provider) * //_error: * * // ENS names require a NameResolver object passed in * // (notice the provider was omitted) * resolveAddress("nothing-here.ricmoo.eth") * //_error: */ export function resolveAddress(target: AddressLike, resolver?: null | NameResolver): string | Promise<string> { if (typeof(target) === "string") { if (target.match(/^0x[0-9a-f]{40}$/i)) { return getAddress(target); } assert(resolver != null, "ENS resolution requires a provider", "UNSUPPORTED_OPERATION", { operation: "resolveName" }); return checkAddress(target, resolver.resolveName(target)); } else if (isAddressable(target)) { return checkAddress(target, target.getAddress()); } else if (target && typeof(target.then) === "function") { return checkAddress(target, target); } assertArgument(false, "unsupported addressable value", "target", target); } |