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

Function buildWrappedFallback

lib.commonjs/contract/contract.js:129–189  ·  view source on GitHub ↗
(contract)

Source from the content-addressed store, hash-verified

127}
128exports.resolveArgs = resolveArgs;
129function buildWrappedFallback(contract) {
130 const populateTransaction = async function (overrides) {
131 // If an overrides was passed in, copy it and normalize the values
132 const tx = (await copyOverrides(overrides, ["data"]));
133 tx.to = await contract.getAddress();
134 if (tx.from) {
135 tx.from = await (0, index_js_2.resolveAddress)(tx.from, getResolver(contract.runner));
136 }
137 const iface = contract.interface;
138 const noValue = ((0, index_js_3.getBigInt)((tx.value || BN_0), "overrides.value") === BN_0);
139 const noData = ((tx.data || "0x") === "0x");
140 if (iface.fallback && !iface.fallback.payable && iface.receive && !noData && !noValue) {
141 (0, index_js_3.assertArgument)(false, "cannot send data to receive or send value to non-payable fallback", "overrides", overrides);
142 }
143 (0, index_js_3.assertArgument)(iface.fallback || noData, "cannot send data to receive-only contract", "overrides.data", tx.data);
144 // Only allow payable contracts to set non-zero value
145 const payable = iface.receive || (iface.fallback && iface.fallback.payable);
146 (0, index_js_3.assertArgument)(payable || noValue, "cannot send value to non-payable fallback", "overrides.value", tx.value);
147 // Only allow fallback contracts to set non-empty data
148 (0, index_js_3.assertArgument)(iface.fallback || noData, "cannot send data to receive-only contract", "overrides.data", tx.data);
149 return tx;
150 };
151 const staticCall = async function (overrides) {
152 const runner = getRunner(contract.runner, "call");
153 (0, index_js_3.assert)(canCall(runner), "contract runner does not support calling", "UNSUPPORTED_OPERATION", { operation: "call" });
154 const tx = await populateTransaction(overrides);
155 try {
156 return await runner.call(tx);
157 }
158 catch (error) {
159 if ((0, index_js_3.isCallException)(error) && error.data) {
160 throw contract.interface.makeError(error.data, tx);
161 }
162 throw error;
163 }
164 };
165 const send = async function (overrides) {
166 const runner = contract.runner;
167 (0, index_js_3.assert)(canSend(runner), "contract runner does not support sending transactions", "UNSUPPORTED_OPERATION", { operation: "sendTransaction" });
168 const tx = await runner.sendTransaction(await populateTransaction(overrides));
169 const provider = getProvider(contract.runner);
170 // @TODO: the provider can be null; make a custom dummy provider that will throw a
171 // meaningful error
172 return new wrappers_js_1.ContractTransactionResponse(contract.interface, provider, tx);
173 };
174 const estimateGas = async function (overrides) {
175 const runner = getRunner(contract.runner, "estimateGas");
176 (0, index_js_3.assert)(canEstimate(runner), "contract runner does not support gas estimation", "UNSUPPORTED_OPERATION", { operation: "estimateGas" });
177 return await runner.estimateGas(await populateTransaction(overrides));
178 };
179 const method = async (overrides) => {
180 return await send(overrides);
181 };
182 (0, index_js_3.defineProperties)(method, {
183 _contract: contract,
184 estimateGas,
185 populateTransaction,
186 send, staticCall

Callers 1

constructorMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected