-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes ethereum/web3.js#1188 #1191
Changes from 6 commits
3663cb1
48b76bd
1cb90cf
dea7cfc
16087a0
cfa4982
7e73f65
70869eb
61a9acf
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 |
---|---|---|
|
@@ -36,6 +36,8 @@ var Iban = require('web3-eth-iban'); | |
var Accounts = require('web3-eth-accounts'); | ||
var abi = require('web3-eth-abi'); | ||
|
||
var util = require('util'); | ||
|
||
var getNetworkType = require('./getNetworkType.js'); | ||
var formatter = helpers.formatters; | ||
|
||
|
@@ -138,8 +140,18 @@ var Eth = function Eth() { | |
this.personal = new Personal(this.currentProvider); | ||
this.personal.defaultAccount = this.defaultAccount; | ||
|
||
var ContractWrapper = function ContractWrapper() { | ||
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. The problem is that we want the "class" to be "Contract" not "ContractWrapper" when somebody logs the I also dopant fully understand this wrapper. 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. The problem the wrapper solves: Given two instances of The wrapper solves this by giving each instance of Edit: To demonstrate the necessity of the wrapper type, I reverted my changes in
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. Also, it's trivial to rename 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. Yes please change to |
||
Contract.apply(this, arguments); | ||
}; | ||
|
||
ContractWrapper.setProvider = function() { | ||
Contract.setProvider.apply(this, arguments); | ||
}; | ||
|
||
util.inherits(ContractWrapper, Contract); | ||
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. To me, I think this is the most contentious part. From the current node docs:
So, @frozeman my question here is whether we'd rather do things the ES6 way, per the quote above. Is Web3 1.0 babelified? If so, perhaps that'd be more idiomatic. 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. We are currently working on the 1.0ES6 branch. When we have that we can use it. Currently we do some Babel trans compiling, but I didn’t try if it works, as all the code is es5 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. Also did you try the standalone lnstantiation? According to the docs? 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. Would you rather I submitted a PR against that branch? Happy to do so - I think that answers the I didn't try standalone instantiation, as I figured existing tests covered that. This PR definitely won't fix shared state between standalone instances of If you want to remove that shared state, then I suggest we ditch the dynamic inheritance hacks altogether and go with the usual 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. @frozeman Just tested and this commit cherry-picks cleanly against 1.0ES6 and all tests pass - I'm happy to do that if you like and resubmit? 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. Important is that standalone still works as expected. We currently don’t have tests for that. Feel free to add some. Concerning the es6 branch, I will anyway merge this branch back into 1.0ES6 so it should be fine. 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. @frozeman Provided "as expected" means "as documented," then I'll be happy to add some tests for that. Otherwise a test like the following will not pass under this branch. Please let me know if fixing this issue is a condition for acceptance. Contract.setProvider(provider1);
let contract1 = new Contract(...);
Contract.setProvider(provider2);
let contract2 = new Contract(...);
assert.deepEqual(provider1, contract1.currentProvider);
assert.deepEqual(provider2,contract2.currentProvider); 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. Actually, forget I asked - I'll add that test, make it pass, and then I think we'll be in good shape. :-) |
||
|
||
// add contract | ||
this.Contract = Contract; | ||
this.Contract = ContractWrapper; | ||
this.Contract.defaultAccount = this.defaultAccount; | ||
this.Contract.defaultBlock = this.defaultBlock; | ||
this.Contract.setProvider(this.currentProvider, this.accounts); | ||
|
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.
Is this module available in the browser? As we compile to browser, we need to make sure its available there as well.
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.
Good question. I'm not familiar w/ how you're building for the browser yet, but since
util
is part of the node runtime, I'd expect most tools likebrowserify
andwebpack
include shims for it. I'll double check and get back to you.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.
@frozeman: Answer to your question: It appears that you're using browserify, and it appears (per browserify/browserify#1503) that browserify will pull in the entire
util
package in this case.If you'd rather not pull in the entire util module, we can do here what was suggested on that issue, use the
inherits
package instead ofutil.inherits
. In the ES6 branch you can ditch that as well, and just use theextends
keyword.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.
It would be great if we can avoid using util here and use something natively existing in ES5 already