Added provider.lookupAddress.
This commit is contained in:
parent
88749835c8
commit
44f4caac4a
@ -12,7 +12,10 @@
|
|||||||
// migrate the listener to the static event. We also need to maintain a map
|
// migrate the listener to the static event. We also need to maintain a map
|
||||||
// of Signer/ENS name to address so we can sync respond to listenerCount.
|
// of Signer/ENS name to address so we can sync respond to listenerCount.
|
||||||
|
|
||||||
import { resolveAddress } from "../address/index.js";
|
import { getAddress, resolveAddress } from "../address/index.js";
|
||||||
|
import { ZeroHash } from "../constants/index.js";
|
||||||
|
import { Contract } from "../contract/index.js";
|
||||||
|
import { namehash } from "../hash/index.js";
|
||||||
import { Transaction } from "../transaction/index.js";
|
import { Transaction } from "../transaction/index.js";
|
||||||
import {
|
import {
|
||||||
concat, dataLength, dataSlice, hexlify, isHexString,
|
concat, dataLength, dataSlice, hexlify, isHexString,
|
||||||
@ -710,7 +713,7 @@ export class AbstractProvider implements Provider {
|
|||||||
// We may want to compute this more accurately in the future,
|
// We may want to compute this more accurately in the future,
|
||||||
// using the formula "check if the base fee is correct".
|
// using the formula "check if the base fee is correct".
|
||||||
// See: https://eips.ethereum.org/EIPS/eip-1559
|
// See: https://eips.ethereum.org/EIPS/eip-1559
|
||||||
maxPriorityFeePerGas = BigInt("1500000000");
|
maxPriorityFeePerGas = BigInt("1000000000");
|
||||||
|
|
||||||
// Allow a network to override their maximum priority fee per gas
|
// Allow a network to override their maximum priority fee per gas
|
||||||
//const priorityFeePlugin = (await this.getNetwork()).getPlugin<MaxPriorityFeePlugin>("org.ethers.plugins.max-priority-fee");
|
//const priorityFeePlugin = (await this.getNetwork()).getPlugin<MaxPriorityFeePlugin>("org.ethers.plugins.max-priority-fee");
|
||||||
@ -959,25 +962,41 @@ export class AbstractProvider implements Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async resolveName(name: string): Promise<null | string>{
|
async resolveName(name: string): Promise<null | string>{
|
||||||
if (isHexString(name, 20)) { return name; }
|
const resolver = await this.getResolver(name);
|
||||||
//if (typeof(name) === "string") {
|
if (resolver) { return await resolver.getAddress(); }
|
||||||
const resolver = await this.getResolver(name);
|
|
||||||
if (resolver) { return await resolver.getAddress(); }
|
|
||||||
/*
|
|
||||||
} else {
|
|
||||||
const address = await name.getAddress();
|
|
||||||
if (address == null) {
|
|
||||||
return logger.throwArgumentError("Addressable returned no address", "name", name);
|
|
||||||
}
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async lookupAddress(address: string): Promise<null | string> {
|
async lookupAddress(address: string): Promise<null | string> {
|
||||||
throw new Error();
|
address = getAddress(address);
|
||||||
//return "TODO";
|
const node = namehash(address.substring(2).toLowerCase() + ".addr.reverse");
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
const ensAddr = await EnsResolver.getEnsAddress(this);
|
||||||
|
const ensContract = new Contract(ensAddr, [
|
||||||
|
"function resolver(bytes32) view returns (address)"
|
||||||
|
], this);
|
||||||
|
|
||||||
|
const resolver = await ensContract.resolver(node);
|
||||||
|
if (resolver == null || resolver === ZeroHash) { return null; }
|
||||||
|
|
||||||
|
const resolverContract = new Contract(resolver, [
|
||||||
|
"function name(bytes32) view returns (string)"
|
||||||
|
], this);
|
||||||
|
const name = await resolverContract.name(node);
|
||||||
|
|
||||||
|
const check = await this.resolveName(name);
|
||||||
|
if (check !== address) {
|
||||||
|
console.log("FAIL", address, check);
|
||||||
|
}
|
||||||
|
|
||||||
|
return name;
|
||||||
|
} catch (error) {
|
||||||
|
console.log("TEMP", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async waitForTransaction(hash: string, _confirms?: null | number, timeout?: null | number): Promise<null | TransactionReceipt> {
|
async waitForTransaction(hash: string, _confirms?: null | number, timeout?: null | number): Promise<null | TransactionReceipt> {
|
||||||
@ -1021,8 +1040,9 @@ export class AbstractProvider implements Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async waitForBlock(blockTag?: BlockTag): Promise<Block> {
|
async waitForBlock(blockTag?: BlockTag): Promise<Block> {
|
||||||
throw new Error();
|
assert(false, "not implemented yet", "NOT_IMPLEMENTED", {
|
||||||
//return new Block(<any><unknown>{ }, this);
|
operation: "waitForBlock"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_clearTimeout(timerId: number): void {
|
_clearTimeout(timerId: number): void {
|
||||||
|
Loading…
Reference in New Issue
Block a user