Fixed resolving ENS addresses used as from parameters (#3961).
This commit is contained in:
parent
cd5f0fe03f
commit
2616f4c30c
@ -15,7 +15,7 @@ import {
|
||||
} from "./wrappers.js";
|
||||
|
||||
import type { EventFragment, FunctionFragment, InterfaceAbi, ParamType, Result } from "../abi/index.js";
|
||||
import type { Addressable } from "../address/index.js";
|
||||
import type { Addressable, NameResolver } from "../address/index.js";
|
||||
import type { EventEmitterable, Listener } from "../utils/index.js";
|
||||
import type {
|
||||
BlockTag, ContractRunner, Provider, TransactionRequest, TopicFilter
|
||||
@ -68,6 +68,14 @@ function canSend(value: any): value is ContractRunnerSender {
|
||||
return (value && typeof(value.sendTransaction) === "function");
|
||||
}
|
||||
|
||||
function getResolver(value: any): undefined | NameResolver {
|
||||
if (value != null) {
|
||||
if (canResolve(value)) { return value; }
|
||||
if (value.provider) { return value.provider; }
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
class PreparedTopicFilter implements DeferredTopicFilter {
|
||||
#filter: Promise<TopicFilter>;
|
||||
readonly fragment!: EventFragment;
|
||||
@ -146,9 +154,7 @@ export async function copyOverrides<O extends string = "data" | "to">(arg: any,
|
||||
"cannot override data", "overrides.data", overrides.data);
|
||||
|
||||
// Resolve any from
|
||||
if (overrides.from) {
|
||||
overrides.from = await resolveAddress(overrides.from);
|
||||
}
|
||||
if (overrides.from) { overrides.from = overrides.from; }
|
||||
|
||||
return <Omit<ContractTransaction, O>>overrides;
|
||||
}
|
||||
@ -177,6 +183,10 @@ function buildWrappedFallback(contract: BaseContract): WrappedFallback {
|
||||
const tx: ContractTransaction = <any>(await copyOverrides<"data">(overrides, [ "data" ]));
|
||||
tx.to = await contract.getAddress();
|
||||
|
||||
if (tx.from) {
|
||||
tx.from = await resolveAddress(tx.from, getResolver(contract.runner));
|
||||
}
|
||||
|
||||
const iface = contract.interface;
|
||||
|
||||
const noValue = (getBigInt((tx.value || BN_0), "overrides.value") === BN_0);
|
||||
@ -271,6 +281,10 @@ function buildWrappedMethod<A extends Array<any> = Array<any>, R = any, D extend
|
||||
let overrides: Omit<ContractTransaction, "data" | "to"> = { };
|
||||
if (fragment.inputs.length + 1 === args.length) {
|
||||
overrides = await copyOverrides(args.pop());
|
||||
|
||||
if (overrides.from) {
|
||||
overrides.from = await resolveAddress(overrides.from, getResolver(contract.runner));
|
||||
}
|
||||
}
|
||||
|
||||
if (fragment.inputs.length !== args.length) {
|
||||
|
@ -817,7 +817,7 @@ export class AbstractProvider implements Provider {
|
||||
[ "to", "from" ].forEach((key) => {
|
||||
if ((<any>request)[key] == null) { return; }
|
||||
|
||||
const addr = resolveAddress((<any>request)[key]);
|
||||
const addr = resolveAddress((<any>request)[key], this);
|
||||
if (isPromise(addr)) {
|
||||
promises.push((async function() { (<any>request)[key] = await addr; })());
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user