(contract, key)
| 188 | return method; |
| 189 | } |
| 190 | function buildWrappedMethod(contract, key) { |
| 191 | const getFragment = function (...args) { |
| 192 | const fragment = contract.interface.getFunction(key, args); |
| 193 | (0, index_js_3.assert)(fragment, "no matching fragment", "UNSUPPORTED_OPERATION", { |
| 194 | operation: "fragment", |
| 195 | info: { key, args } |
| 196 | }); |
| 197 | return fragment; |
| 198 | }; |
| 199 | const populateTransaction = async function (...args) { |
| 200 | const fragment = getFragment(...args); |
| 201 | // If an overrides was passed in, copy it and normalize the values |
| 202 | let overrides = {}; |
| 203 | if (fragment.inputs.length + 1 === args.length) { |
| 204 | overrides = await copyOverrides(args.pop()); |
| 205 | if (overrides.from) { |
| 206 | overrides.from = await (0, index_js_2.resolveAddress)(overrides.from, getResolver(contract.runner)); |
| 207 | } |
| 208 | } |
| 209 | if (fragment.inputs.length !== args.length) { |
| 210 | throw new Error("internal error: fragment inputs doesn't match arguments; should not happen"); |
| 211 | } |
| 212 | const resolvedArgs = await resolveArgs(contract.runner, fragment.inputs, args); |
| 213 | return Object.assign({}, overrides, await (0, index_js_3.resolveProperties)({ |
| 214 | to: contract.getAddress(), |
| 215 | data: contract.interface.encodeFunctionData(fragment, resolvedArgs) |
| 216 | })); |
| 217 | }; |
| 218 | const staticCall = async function (...args) { |
| 219 | const result = await staticCallResult(...args); |
| 220 | if (result.length === 1) { |
| 221 | return result[0]; |
| 222 | } |
| 223 | return result; |
| 224 | }; |
| 225 | const send = async function (...args) { |
| 226 | const runner = contract.runner; |
| 227 | (0, index_js_3.assert)(canSend(runner), "contract runner does not support sending transactions", "UNSUPPORTED_OPERATION", { operation: "sendTransaction" }); |
| 228 | const tx = await runner.sendTransaction(await populateTransaction(...args)); |
| 229 | const provider = getProvider(contract.runner); |
| 230 | // @TODO: the provider can be null; make a custom dummy provider that will throw a |
| 231 | // meaningful error |
| 232 | return new wrappers_js_1.ContractTransactionResponse(contract.interface, provider, tx); |
| 233 | }; |
| 234 | const estimateGas = async function (...args) { |
| 235 | const runner = getRunner(contract.runner, "estimateGas"); |
| 236 | (0, index_js_3.assert)(canEstimate(runner), "contract runner does not support gas estimation", "UNSUPPORTED_OPERATION", { operation: "estimateGas" }); |
| 237 | return await runner.estimateGas(await populateTransaction(...args)); |
| 238 | }; |
| 239 | const staticCallResult = async function (...args) { |
| 240 | const runner = getRunner(contract.runner, "call"); |
| 241 | (0, index_js_3.assert)(canCall(runner), "contract runner does not support calling", "UNSUPPORTED_OPERATION", { operation: "call" }); |
| 242 | const tx = await populateTransaction(...args); |
| 243 | let result = "0x"; |
| 244 | try { |
| 245 | result = await runner.call(tx); |
| 246 | } |
| 247 | catch (error) { |
no test coverage detected