-
Notifications
You must be signed in to change notification settings - Fork 98
Userlib: CanisterIds are little endian #317
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,18 @@ class CanisterIdEncoder implements CborEncoder<CanisterId> { | |
| } | ||
|
|
||
| public encode(v: CanisterId): cbor.CborValue { | ||
| return cbor.value.u64(v.toHex(), 16); | ||
| return cbor.value.u64(this.changeEndianness(v.toHex()), 16); | ||
| } | ||
|
|
||
| // Drop once we use https://github.com/dfinity-lab/dfinity/pull/2286 | ||
| private changeEndianness(str: string): string { | ||
| const result = []; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did this instead: I also modified the test in cbor.test.ts to check for endianess, but it doesn't make sense I think, since we should soon remove this. This might have issues when we receive the canister id, but I don't think this is used in the LinkedUp demo (as this is not inverse of toHex().
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @stanleygjones
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct; Canister ids are only recevied upon canister registration, this is not something the user lib does, so we are good on that front. Agree that your code is a bit more elegant, I just copied the nible-reversing code from @chenyan-dfinity. But it’ll be removed in a few days anyways, so let’s not worry. |
||
| let len = str.length - 2; | ||
| while (len >= 0) { | ||
| result.push(str.substr(len, 2)); | ||
| len -= 2; | ||
| } | ||
| return result.join(''); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,8 @@ | ||
| declare module "borc" { | ||
| import { Buffer } from "buffer/"; | ||
| declare module 'borc' { | ||
| import { Buffer } from 'buffer/'; | ||
|
|
||
| class Decoder { | ||
| constructor(opts: { | ||
| size: Number, | ||
| tags: Record<number, (val: any) => any>, | ||
| }); | ||
| constructor(opts: { size: Number; tags: Record<number, (val: any) => any> }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does the style checker pass?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the result of running the style checker here… IC checks the style checker, so I guess the answer is yes? |
||
|
|
||
| decodeFirst(input: ArrayBuffer): any; | ||
| } | ||
|
|
||
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.
Can we changeEndianness inside
toHexfunction?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! The
toHexis the correctCanisterIDtoblobconversion that we will want to use once we updatedfinity. We should keep the work-around close the CBOR encoding, where we shoehorn a blob into au64.