Commit 56e48169 authored by Mark Tyneway's avatar Mark Tyneway

lint: fix

parent 7746080f
...@@ -128,44 +128,43 @@ export const asAdvancedContract = (opts: { ...@@ -128,44 +128,43 @@ export const asAdvancedContract = (opts: {
// Now reset Object.defineProperty // Now reset Object.defineProperty
Object.defineProperty = def Object.defineProperty = def
// Override each function call to also `.wait()` so as to simplify the deploy scripts' syntax.
for (const fnName of Object.keys(contract.functions)) { for (const fnName of Object.keys(contract.functions)) {
const fn = contract[fnName].bind(contract) const fn = contract[fnName].bind(contract)
; (contract as any)[fnName] = async (...args: any) => { ;(contract as any)[fnName] = async (...args: any) => {
// We want to use the configured gas price but we need to set the gas price to zero if we're // We want to use the configured gas price but we need to set the gas price to zero if we're
// triggering a static function. // triggering a static function.
let gasPrice = opts.gasPrice let gasPrice = opts.gasPrice
if (contract.interface.getFunction(fnName).constant) { if (contract.interface.getFunction(fnName).constant) {
gasPrice = 0 gasPrice = 0
} }
// Now actually trigger the transaction (or call). // Now actually trigger the transaction (or call).
const tx = await fn(...args, { const tx = await fn(...args, {
gasPrice, gasPrice,
}) })
// Meant for static calls, we don't need to wait for anything, we get the result right away. // Meant for static calls, we don't need to wait for anything, we get the result right away.
if (typeof tx !== 'object' || typeof tx.wait !== 'function') { if (typeof tx !== 'object' || typeof tx.wait !== 'function') {
return tx return tx
} }
// Wait for the transaction to be included in a block and wait for the specified number of // Wait for the transaction to be included in a block and wait for the specified number of
// deployment confirmations. // deployment confirmations.
const maxTimeout = 120 const maxTimeout = 120
let timeout = 0 let timeout = 0
while (true) { while (true) {
await sleep(1000) await sleep(1000)
const receipt = await contract.provider.getTransactionReceipt(tx.hash) const receipt = await contract.provider.getTransactionReceipt(tx.hash)
if (receipt === null) { if (receipt === null) {
timeout++ timeout++
if (timeout > maxTimeout) { if (timeout > maxTimeout) {
throw new Error('timeout exceeded waiting for txn to be mined') throw new Error('timeout exceeded waiting for txn to be mined')
}
} else if (receipt.confirmations >= (opts.confirmations || 0)) {
return tx
} }
} else if (receipt.confirmations >= (opts.confirmations || 0)) {
return tx
} }
} }
}
} }
return contract return contract
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment