* Creates a new contract connected to %%target%% with the %%abi%% and * optionally connected to a %%runner%% to perform operations on behalf * of.
(target, abi, runner, _deployTx)
| 538 | * of. |
| 539 | */ |
| 540 | constructor(target, abi, runner, _deployTx) { |
| 541 | assertArgument(typeof (target) === "string" || isAddressable(target), "invalid value for Contract target", "target", target); |
| 542 | if (runner == null) { |
| 543 | runner = null; |
| 544 | } |
| 545 | const iface = Interface.from(abi); |
| 546 | defineProperties(this, { target, runner, interface: iface }); |
| 547 | Object.defineProperty(this, internal, { value: {} }); |
| 548 | let addrPromise; |
| 549 | let addr = null; |
| 550 | let deployTx = null; |
| 551 | if (_deployTx) { |
| 552 | const provider = getProvider(runner); |
| 553 | // @TODO: the provider can be null; make a custom dummy provider that will throw a |
| 554 | // meaningful error |
| 555 | deployTx = new ContractTransactionResponse(this.interface, provider, _deployTx); |
| 556 | } |
| 557 | let subs = new Map(); |
| 558 | // Resolve the target as the address |
| 559 | if (typeof (target) === "string") { |
| 560 | if (isHexString(target)) { |
| 561 | addr = target; |
| 562 | addrPromise = Promise.resolve(target); |
| 563 | } |
| 564 | else { |
| 565 | const resolver = getRunner(runner, "resolveName"); |
| 566 | if (!canResolve(resolver)) { |
| 567 | throw makeError("contract runner does not support name resolution", "UNSUPPORTED_OPERATION", { |
| 568 | operation: "resolveName" |
| 569 | }); |
| 570 | } |
| 571 | addrPromise = resolver.resolveName(target).then((addr) => { |
| 572 | if (addr == null) { |
| 573 | throw makeError("an ENS name used for a contract target must be correctly configured", "UNCONFIGURED_NAME", { |
| 574 | value: target |
| 575 | }); |
| 576 | } |
| 577 | getInternal(this).addr = addr; |
| 578 | return addr; |
| 579 | }); |
| 580 | } |
| 581 | } |
| 582 | else { |
| 583 | addrPromise = target.getAddress().then((addr) => { |
| 584 | if (addr == null) { |
| 585 | throw new Error("TODO"); |
| 586 | } |
| 587 | getInternal(this).addr = addr; |
| 588 | return addr; |
| 589 | }); |
| 590 | } |
| 591 | // Set our private values |
| 592 | setInternal(this, { addrPromise, addr, deployTx, subs }); |
| 593 | // Add the event filters |
| 594 | const filters = new Proxy({}, { |
| 595 | get: (target, prop, receiver) => { |
| 596 | // Pass important checks (like `then` for Promise) through |
| 597 | if (typeof (prop) === "symbol" || passProperties.indexOf(prop) >= 0) { |
nothing calls this directly
no test coverage detected