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

fix: returned string of BigInt.toHexString #1389

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

fewwwww
Copy link

@fewwwww fewwwww commented Jun 23, 2023

For The Graph's graph-ts implementation, BigInt.toHex() and BigInt.toHexString() behaves the same.

toHex(): string {
  return typeConversion.bigIntToHex(this);
}

toHexString(): string {
  return typeConversion.bigIntToHex(this);
}

However, in my thoughts toHex() should return a string that looks like deadbeef while toHexString() should return a string that looks like 0xdeadbeef.

So the implementation should be updated into:

toHex(): string {
  return typeConversion.bigIntToHex(this);
}

toHexString(): string {
  return "0x" + typeConversion.bigIntToHex(this);
}

Additionally, toHexString() is not tracked by The Graph's AssemblyScript API docs.

@changeset-bot
Copy link

changeset-bot bot commented Jun 23, 2023

⚠️ No Changeset found

Latest commit: 890385b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@maoueh maoueh left a comment

Choose a reason for hiding this comment

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

Will not merge in this form, and if AssemblyScript don't accept default parameter, we might even probably close this PR.

@@ -115,7 +115,7 @@ export class BigInt extends Uint8Array {
}

toHexString(): string {
return typeConversion.bigIntToHex(this);
return "0x" + typeConversion.bigIntToHex(this);
Copy link
Contributor

Choose a reason for hiding this comment

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

This will be a major breaking change, while I kind of agree that we could have both I don't think we can merge that.

If AssemblyScript accepts default parameter, maybe we could think of toHexString(format) where default would be the same as today keeping compatibility and the format could be plain or prefixed or something along this.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the review and feedback! I've updated the change with an optional prefix that does not affect the compatibility.

@fewwwww fewwwww requested a review from maoueh June 27, 2023 20:47
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

2 participants