MCPcopy Create free account
hub / github.com/PageLeay/celestial-runtime / constructor

Method constructor

lib.commonjs/contract/contract.js:545–651  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 14

getEventMethod · 0.95
getProviderFunction · 0.70
getRunnerFunction · 0.70
canResolveFunction · 0.70
getInternalFunction · 0.70
setInternalFunction · 0.70
buildWrappedFallbackFunction · 0.70
resolveNameMethod · 0.65
getAddressMethod · 0.65
fromMethod · 0.45
resolveMethod · 0.45
hasEventMethod · 0.45

Tested by

no test coverage detected