-
Notifications
You must be signed in to change notification settings - Fork 33
Sparrow dom/tranaction hash #546
Changes from 6 commits
3fd5f58
95e164b
f3610b2
6e1cdc4
0bfcb1c
5f14c3a
2cfc55c
697ac79
9340710
fa7b66f
5f3e6f3
59e7f26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,7 +192,7 @@ class ContractService { | |
return withLibraryAddresses | ||
} | ||
|
||
async deploy(contract, args, options) { | ||
async deploy(contract, args, options, { confirmationCallback, transactionHashCallback } = {} ) { | ||
const bytecode = await this.getBytecode(contract) | ||
const deployed = await this.deployed(contract) | ||
const txReceipt = await new Promise((resolve, reject) => { | ||
|
@@ -205,16 +205,53 @@ class ContractService { | |
.on('receipt', receipt => { | ||
resolve(receipt) | ||
}) | ||
//.on('confirmation', confirmationCallback) | ||
//.on('transactionHash', transactionHashCallback) | ||
// Workaround for "confirmationCallback" not being triggered with web3 version:1.0.0-beta.34 | ||
.on('transactionHash', (hash) => { | ||
if (transactionHashCallback) | ||
transactionHashCallback(hash) | ||
if (confirmationCallback) | ||
this.checkForDeploymentCompletion(hash, confirmationCallback) | ||
}) | ||
.on('error', err => reject(err)) | ||
}) | ||
return txReceipt | ||
} | ||
|
||
/* confirmation callback does not get triggered in current version of web3 version:1.0.0-beta.34 | ||
* so this function perpetually (until 5 confirmations) checks for presence of deployed contract. | ||
* | ||
* This could also be a problem in Ethereum node: https://github.com/ethereum/web3.js/issues/1255 | ||
*/ | ||
async checkForDeploymentCompletion(hash, confirmationCallback) { | ||
const transactionInfo = await this.web3.eth.getTransaction(hash) | ||
|
||
// transaction not mined | ||
if (transactionInfo.blockNumber === null){ | ||
setTimeout(() => { | ||
this.checkForDeploymentCompletion(hash, confirmationCallback) | ||
}, 1500) | ||
} else { | ||
const currentBlockNumber = await this.web3.eth.getBlockNumber() | ||
const confirmations = currentBlockNumber - transactionInfo.blockNumber | ||
confirmationCallback(confirmations, { | ||
transactionHash: transactionInfo.hash | ||
}) | ||
// do checks untill 5 block confirmations | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo: "until" |
||
if (confirmations < 5) { | ||
setTimeout(() => { | ||
this.checkForDeploymentCompletion(hash, confirmationCallback) | ||
}, 1500) | ||
} | ||
} | ||
} | ||
|
||
async call( | ||
contractName, | ||
functionName, | ||
args = [], | ||
{ contractAddress, from, gas, value, confirmationCallback, additionalGas = 0 } = {} | ||
{ contractAddress, from, gas, value, confirmationCallback, transactionHashCallback, additionalGas = 0 } = {} | ||
) { | ||
const contractDefinition = this.contracts[contractName] | ||
if (typeof contractDefinition === 'undefined') { | ||
|
@@ -239,6 +276,7 @@ class ContractService { | |
.send(opts) | ||
.on('receipt', resolve) | ||
.on('confirmation', confirmationCallback) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't we have same issue here mentioned in the deploy method that confirmationCallback does not get triggered ? Are we relying on this callback anywhere in our DApp or origin-js codebase ? If yes let's fix it (ok to do in separate PR), if no could we at least add a comment to warn caller that this is currently not working ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interestingly when doing an Ethereum transaction confirmation callback is working, but when deploying a contract it is not. That is why the workaround is implemented only in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Thanks for being thorough. |
||
.on('transactionHash', transactionHashCallback) | ||
.on('error', reject) | ||
}) | ||
const block = await this.web3.eth.getBlock(transactionReceipt.blockNumber) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we document as a comment what options are available ?