Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Suggested promisifying of a contract factory. #83

Merged
merged 2 commits into from
Mar 27, 2017

Conversation

xavierlepretre
Copy link
Contributor

Notice how it resolves to an array with both returned contracts.
Only contracts[1] has the address, presumably.

@Arachnid
Copy link
Member

The constructor callback is called twice, once when the transaction is accepted into the node's transaction pool, and once when it's mined. For these purposes, it'd be sufficient to ignore the first callback and only fulfill the promise on the second.

It might be more convenient to just take the ABI, too, and do the web3.eth.contract call in the function.

@xavierlepretre
Copy link
Contributor Author

I can change to only return on the second time.
But you are saying we should go with a synchronous .new? Wouldn't that be a problem with a future Web3, or a NodeJs that forbids synchronous calls?

@Arachnid
Copy link
Member

No, not at all - definitely use the asynchronous new. But there's no need to return an array in the promise - just return the value passed to the callback once contract.address is populated.

TestRPC: TestRPC,
promisifyContractFactory: function(contractFactory) {
contractFactory.newAsync = function() {
var args = arguments;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is left over from the earlier version? No need to store args now.

Copy link
Contributor Author

@xavierlepretre xavierlepretre Mar 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is necessary, otherwise, inside function(resolve, reject), arguments are set to { '0': [Function resolve], '1': [Function reject] }.

@Arachnid Arachnid merged commit 9d0ffbf into ensdomains:master Mar 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants