-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Remove assert, use typeforce typing #434
Conversation
// external dependent types | ||
function BigInt (value) { return !typeforce.Null(value) && value.constructor === bigi } | ||
function ECCurve (value) { return !typeforce.Null(value) && value.constructor === ecurve.Curve } | ||
function ECPoint (value) { return !typeforce.Null(value) && value.constructor === ecurve.Point } |
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.
@weilu this does revert our previous duck typing change.
I've never had the issue of de-duping where it wasn't symptomatic of something potentially disastrous anyway, so I'm not sure why we allowed it in the first place.
ECPair
and ecdsa
are the only interfaces that accept bigi
/ ECPoint
's, and we intend to remove their individual use entirely for 2.0.0
, so this shouldn't even be an issue.
If you feel otherwise, I'll change these back to typeforce.quacksLike
which is the identical behaviour to what was there before.
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.
I remember an important reason why we went with duck typing is to deal with having multiple versions of the same library in the same app. I still think that's relevant so my preference is still duck typing.
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.
I remember an important reason why we went with duck typing is to deal with having multiple versions of the same library in the same app.
Right.
I've never had the issue of de-duping where it wasn't symptomatic of something potentially disastrous anyway, so I'm not sure why we allowed it in the first place.
I feel like such a situation is dangerous enough that we shouldn't let it occur though?
Especially since this duck typing is only really enforced on types that, if calculated wrong, directly impact where a user might send or receive funds.
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.
This is the other breaking change, but, that has already been pointed out.
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.
This specific change was reverted in #450 as it was still an issue. quacksLike
behaviour was restored.
I'm happy to break out the |
I think for posterity, these benefits should be explicitly stated. |
I don't get why you are getting rid of asserts. IMHO in most of the places, assert is still more direct and semantically straightforward. It's not like we are throwing any custom Error types for better error handling. |
The errors thrown are mostly the same, as out lined by the tests. The only places it did change was in the use of |
@jprichardson @weilu, shall I merge or? To clarify, in the end, I'd like to use |
@dcousens Given that the types of the errors and in some cases the messages are different, I wonder if we need to bump major for this? |
@weilu I wasn't going to bother back porting this to |
@@ -780,7 +780,7 @@ | |||
}, | |||
{ | |||
"description": "Wrong key pair for multisig redeemScript", | |||
"exception": "key pair cannot sign for this input", | |||
"exception": "Key pair cannot sign for this input", |
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.
Breaking change - but it already is different to 1.5.x
: 'privateKey cannot sign for this input'
I'd say there is only a few breaking changes, outlined above. Even then:
The only error message that has therefore changed in terms of the The other errors should all be consistent as |
|
||
if (hash.length !== 20) throw new TypeError('Invalid hash length') | ||
if (version & ~0xff) throw new TypeError('Invalid version byte') | ||
typeforce(types.tuple(types.Hash160bit, types.UInt8), arguments) |
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.
This API is new, so its not a breaking change.
I'm fine with not back-porting this to 1.5.x but let's add these breaking changes into our 2.0 release note. |
Good to merge |
Remove assert, use typeforce typing
Thanks @weilu, I added the breaking change tag so we can easily build that release note by reviewing all issues under it later. |
Follow up 5d2abb5 for |
Will wait on ACK before merge.
ping @weilu, @jprichardson
Curious on your opinions about this...