Skip to content

Conversation

@dcousens
Copy link
Contributor

This pull request cleans up HDWallet and Wallet just a little bit.
It first fixes a bug in createTx which allowed the creation of transactions even when no UTXOs existed. Tests have been amended to ensure this does not regress.

I've then removed all the Wallet async interfaces (which weren't actually async anyway), with the proposed alternative for users to use something like https://github.com/caolan/async#nextTick.

hashLittleEndian is a small convenience option for people using blockchain.info's inconsistent endianness in their API; and therefore has no business being in our interface, and has thus been removed. This further reduces parameter complexity for the Wallet interface.

I have also enforced consistent use of network throughout the project by avoiding stringly typed parameters wherever possible, and instead just using the network objects as they were intended.
Also, in accordance with the standards we chose a while back, constructors should always use operator new where possible.

Finally I added some exception messages and tests for HDWallet.fromBase58.

dcousens added 7 commits May 30, 2014 18:17
Unknowingly this also revealed a subtle bug in the previous
implementation which allowed the creation of transactions even
when no UTXOs existed.
The definition of a dust amount is pretty clear, and I feel it is less
readable when represented as isDust(amount) or !isDust(amount), by
comparison to    amount <= dustThreshold   or   amount > dustThreshold.

Also means I don't have to stray my eyes to understand the
implemention by looking up isDust does.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed network here as it is implied by the closure it resides in. If a user was to specify otherwise, it would produce a HDWallet node with a different network type to the master wallet. This seems erroneous and just plain confusing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed. Good call

@coveralls
Copy link

Coverage Status

Coverage increased (+3.29%) when pulling 80da2ed on dcousens:walletclean into 13f95d4 on bitcoinjs:master.

@dcousens
Copy link
Contributor Author

Integration tests are failing, seems to be a problem with helloblock. @sidazhang @locksley?

For what its worth, the error messages the helloblock node package gives are impossible to debug.

src/wallet.js Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. why not be consistent and use assert here as well?
  2. the original checkDust checks for null and undefined as well. Is there a particular reason why you dropped it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Agreed, I'll add on a commit.
  2. Any invalid values will be caught by Transaction.toBuffer. Even though its not explicit. The same mechanism is being used for to address validation (aka, address.toScriptPubKey() is undefined). If we want to be stricter about parameter validation, probably better to push it down the tree (maybe in Transaction.addOutput).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, as mentioned on IRC, undefined compared to any number is false, so it would always have thrown anyway.

@weilu
Copy link
Contributor

weilu commented May 31, 2014

Sure they are not truly async and I don't mind having only synchronous methods. But I do think the callback interface is nicer for error handling and more familiar to node devs. At some point I'd like to see us migrating to callback interfaces from throwing errors.

@weilu
Copy link
Contributor

weilu commented May 31, 2014

Kicked off the build again. All passed this time. @sidazhang @locksley FYI, the failing build: https://travis-ci.org/bitcoinjs/bitcoinjs-lib/builds/26368607

@kyledrake
Copy link
Contributor

+1 when you're ready

@coveralls
Copy link

Coverage Status

Coverage increased (+4.52%) when pulling bb96ab7 on dcousens:walletclean into 13f95d4 on bitcoinjs:master.

@kyledrake
Copy link
Contributor

If the coverage message is annoying, just let me know and I'll try to turn it off.

@sidazhang
Copy link
Contributor

+1

Haha :)
On May 30, 2014 9:20 PM, "Kyle Drake" notifications@github.com wrote:

If the coverage message is annoying, just let me know and I'll try to turn
it off.


Reply to this email directly or view it on GitHub
#200 (comment)
.

dcousens added 3 commits May 31, 2014 14:24
Taken from browserify-buffer.

Also adds a few more tests to assert this is working correctly from both
read and write perspectives.
The assertion in for writePushDataInt in the 32 bit case was
unnecessary as that is handled by buffer.writeUInt32LE anyway.
@dcousens
Copy link
Contributor Author

Rebased last 3 commits and fixed the wallet error messages as per the discussion.

@kyledrake it's my fault, it posts whenever I rebase a commit. Perhaps I'll need to iterate with @weilu and others before I post it here, so we can clean up smaller issues and then only commit on top of the PRs.
Re-basing is a bad security practice to have given it technically should mean any reviewers would have to restart their review; which often doesn't happen.

@kyledrake
Copy link
Contributor

No worries, I'm totally cool with you doing that.

@coveralls
Copy link

Coverage Status

Coverage increased (+4.52%) when pulling 3bce535 on dcousens:walletclean into 13f95d4 on bitcoinjs:master.

weilu added a commit that referenced this pull request May 31, 2014
@weilu weilu merged commit 1bce662 into bitcoinjs:master May 31, 2014
@coveralls
Copy link

Coverage Status

Coverage increased (+4.52%) when pulling 749943c on dcousens:walletclean into 13f95d4 on bitcoinjs:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants