-
Notifications
You must be signed in to change notification settings - Fork 339
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
UInt extends BN #396
UInt extends BN #396
Conversation
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.
Looks mostly good, some questions, rather than comments. We may just want to check the UInt
vs BN
construction for Moment
though. (It is great being able to pass any number in there)
} | ||
|
||
get bitLength (): UIntBitLength { | ||
bitLength (): UIntBitLength { |
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.
Q: Do we actually use/rely on bitLength
anywhere? (Or is is just there as a "could be useful"). The reason for asking, is that I for the life of me cannot remember why we have it.
@@ -27,8 +27,6 @@ export default class Moment extends Base<Date> { | |||
return value.raw; | |||
} else if (value instanceof Date) { | |||
return new Date(Math.ceil(value.getTime() / 1000) * 1000); | |||
} else if (value instanceof UInt) { |
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.
In removing this, we don't seem to cater for BN
construction anymore? Should we not have a isBn
path 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.
The return at the bottom of the function handles the BN case.
@@ -147,6 +147,6 @@ export default class Compact extends Base<UInt | Moment> { | |||
} | |||
|
|||
toU8a (isBare?: boolean): Uint8Array { | |||
return Compact.encodeU8a(this.raw.toBn(), this.bitLength); | |||
return Compact.encodeU8a(this.raw.toBn(), this.bitLength()); |
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.
Ahh... ok, to my question above, here it is used. (I should have probably left a note in there somewhere as to why we have bitLength
)
@@ -40,7 +38,7 @@ export default class Moment extends Base<Date> { | |||
); | |||
} | |||
|
|||
get bitLength (): UIntBitLength { | |||
bitLength (): UIntBitLength { |
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 there a reason why these are now not getters? Additionally, I believe in U8aFixed
we still have it as a getter?
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 would love to have bitLength everywhere as getter too, but on BN, bitLength is a method, so on Moment it needs to be a method too.
I'll change bitLenght on U8aFixed to method too, for consistency.
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.
Alternatively, @ts-ignore in Uint, but we stray away from BN
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.
No, rather keep it as a method, it is cleaner.
} | ||
|
||
toBn (): BN { | ||
return this.raw; |
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.
Yay! Lotsa stuff gone. :D
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
related #161.