Skip to content
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

SIN should call VersionedData constructor #441

Merged
merged 2 commits into from Jul 18, 2014
Merged

SIN should call VersionedData constructor #441

merged 2 commits into from Jul 18, 2014

Conversation

ryanxcharles
Copy link
Contributor

Creating SINs was broken due to not calling the parent constructor, shich sets "converts" and "_encoding". I've fixed the problem and added tests that reveal the error. Not completely sure why this was working before, since as far as I can tell, SIN always should have been calling the parent constructor anyway

Creating SINs was broken due to not calling the parent constructor, shich sets
"converts" and "_encoding". I've fixed the problem and added tests that reveal
the error.
@ryanxcharles ryanxcharles changed the title SIN should call EncodedData constructor SIN should call VersionedData constructor Jul 18, 2014
@ryanxcharles
Copy link
Contributor Author

Ah, now I understand. The EncodedData constructor must now be run so that is sets converters and _encoding. That is required for .as to work. Although the SIN constructor does not call .as directly, it does call .encoding, which in turn runs .as. The end result is that anything that derives from EncodedData must either run the constuctor (which sets converts and _encoding), or you must set those things manually.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.51%) when pulling 098c613 on ryanxcharles:bug/sin-encodeddata into 3bed2e0 on bitpay:master.

@ryanxcharles
Copy link
Contributor Author

Here's the troublesome diff, in SIN.js:

-  this.__proto__ = this.encodings['binary'];
+  this.encoding('binary');

I changed the line that edits the prototype on the fly for a SIN. However, .converters and ._encoding now need to be set on the object itself, which can be done by calling the constructor of EncodedData.

...revert to previous change, since always calling the constructor of
VersionedData may have unintended consequences. Instead, just set .converts and
._encoding, since they are no longer in the prototype and must be set on the
object itself.
@ryanxcharles
Copy link
Contributor Author

I've updated the PR. I think I now have a complete understanding of the problem. SIN used to rely on the existence of .converters and ._encoding in the prototype. They are no longer in the prototype. Furthermore, SIN no longer sets the prototype at all in the constructor. .converters and ._encoding need to be set somehow. One way to set them is to call the VersionedData constructor. However, running that constructor with inappropriate inputs may cause uintended consequences. The simplest solution is to just set them by hand in the SIN constructor. That is what my latest commit does.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) when pulling 4523012 on ryanxcharles:bug/sin-encodeddata into 3bed2e0 on bitpay:master.

@ryanxcharles
Copy link
Contributor Author

...another way to look at it is that EncodedData and friends are really confusingly programmed and should be refactored to be easier to understand and modify.

ryanxcharles pushed a commit that referenced this pull request Jul 18, 2014
SIN should call VersionedData constructor
@ryanxcharles ryanxcharles merged commit 7866f5c into bitpay:master Jul 18, 2014
@44203
Copy link
Contributor

44203 commented Jul 18, 2014

@ryanxcharles can we bump the version and publish this to npm? this way i can go ahead and lock down bitauth to bitcore@0.1.32.

@ryanxcharles
Copy link
Contributor Author

Yep. Doing so now.

@braydonf
Copy link
Contributor

100% tests are passing here.

micahriggan pushed a commit to micahriggan/bitcore that referenced this pull request Dec 27, 2018
Fix error condition in fiat rate endpoint
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.

None yet

4 participants