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

UInt extends BN #396

Merged
merged 7 commits into from
Nov 14, 2018
Merged

UInt extends BN #396

merged 7 commits into from
Nov 14, 2018

Conversation

amaury1093
Copy link
Contributor

related #161.

@amaury1093 amaury1093 added @types WIP Work in Progress labels Nov 13, 2018
@amaury1093 amaury1093 removed the WIP Work in Progress label Nov 14, 2018
Copy link
Member

@jacogr jacogr left a 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 {
Copy link
Member

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) {
Copy link
Member

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?

Copy link
Contributor Author

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());
Copy link
Member

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 {
Copy link
Member

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?

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 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.

Copy link
Contributor Author

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

Copy link
Member

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;
Copy link
Member

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

@amaury1093 amaury1093 merged commit d097a7a into master Nov 14, 2018
@amaury1093 amaury1093 deleted the am-bn branch November 14, 2018 11:35
@polkadot-js-bot
Copy link

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.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Jun 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants