+
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/address/Address.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ describe('Address', () => {
expect(address.toString({ bounceable: false, urlSafe: false })).toMatch('UQAs9VlT6S776tq3unJcP5Ogsj+ELLunLXuOb1EKcOQi41+E');
expect(address.toString({ bounceable: false, urlSafe: false, testOnly: true })).toMatch('0QAs9VlT6S776tq3unJcP5Ogsj+ELLunLXuOb1EKcOQi4+QO');
});
it('should serialize with urlSafe=false', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

These match exactly 5 out of 8 expects from should serialize to friendly form test above. First of them considers urlSafe to be true. Is this intentional?

const address = Address.parseRaw('0:2cf55953e92efbeadab7ba725c3f93a0b23f842cbba72d7b8e6f510a70e422e3');

// Bounceable
expect(address.toString({ testOnly: true })).toMatch('kQAs9VlT6S776tq3unJcP5Ogsj-ELLunLXuOb1EKcOQi47nL');
expect(address.toString({ urlSafe: false })).toMatch('EQAs9VlT6S776tq3unJcP5Ogsj+ELLunLXuOb1EKcOQi4wJB');
expect(address.toString({ urlSafe: false, testOnly: true })).toMatch('kQAs9VlT6S776tq3unJcP5Ogsj+ELLunLXuOb1EKcOQi47nL');

// Non-Bounceable
expect(address.toString({ bounceable: false, urlSafe: false })).toMatch('UQAs9VlT6S776tq3unJcP5Ogsj+ELLunLXuOb1EKcOQi41+E');
expect(address.toString({ bounceable: false, urlSafe: false, testOnly: true })).toMatch('0QAs9VlT6S776tq3unJcP5Ogsj+ELLunLXuOb1EKcOQi4+QO');
});
it('should implement equals', () => {
let address1 = Address.parseRaw('0:2cf55953e92efbeadab7ba725c3f93a0b23f842cbba72d7b8e6f510a70e422e3');
let address2 = Address.parseRaw('0:2cf55953e92efbeadab7ba725c3f93a0b23f842cbba72d7b8e6f510a70e422e3');
Expand Down
19 changes: 12 additions & 7 deletions src/address/Address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,19 @@ export class Address {
return addressWithChecksum;
}

/**
* Returns address as a string.
*
* @param args optional arguments with the following properties:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't provide documentation for completions/hovers of fields themselves, where it'd be more expected.

I'd suggest to put it directly into the type.

{
    /**
     * If true, returns url-friendly string, otherwise just base64
     * @default true
     */
    urlSafe?: boolean;
    /**
     * If true, returns bounceable address (with 0x11 tag), otherwise — non-bounceable (with 0x51 tag)
     * @default true
     */
    bounceable?: boolean;
    /**
     * If true, returns test-only address (with 0x80 tag), otherwise — non-test-only
     * @default false
     */
    testOnly?: boolean;
}

* - urlSafe — if true (default), returns url-friendly string, otherwise just base64
* - bounceable — if true (default), returns bounceable address (with 0x11 tag),
* otherwise — non-bounceable (with 0x51 tag)
* - testOnly — if true (by default, false), returns test-only address (with 0x80 tag), otherwise - non-test-only
*/
toString = (args?: { urlSafe?: boolean, bounceable?: boolean, testOnly?: boolean }) => {
let urlSafe = (args && args.urlSafe !== undefined) ? args.urlSafe : true;
let buffer = this.toStringBuffer(args);
if (urlSafe) {
return buffer.toString('base64').replace(/\+/g, '-').replace(/\//g, '_');
} else {
return buffer.toString('base64');
}
const urlSafe = (args && args.urlSafe !== undefined) ? args.urlSafe : true;
const buffer = this.toStringBuffer(args);
return urlSafe ? buffer.toString('base64url') : buffer.toString('base64');
}

[inspectSymbol] = () => this.toString()
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载