Skip to content

Commit 5e2caa1

Browse files
committed
Change 'isTestnet' field in PlatformAddress option to 'networkId'
1 parent 12720cc commit 5e2caa1

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/key/PlatformAddress.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ export class PlatformAddress {
2222
this.value = address;
2323
}
2424

25-
static fromAccountId(accountId: H160 | string, options: { isTestnet?: boolean, version?: number } = {}) {
26-
const { isTestnet = false, version = 0 } = options;
25+
static fromAccountId(accountId: H160 | string, options: { networkId?: string, version?: number } = {}) {
26+
const { networkId = "cc", version = 0 } = options;
2727

2828
if (version !== 0) {
2929
throw `Unsupported version for platform address: ${version}`;
3030
}
3131

3232
const words = toWords(Buffer.from([version, ...Buffer.from(H160.ensure(accountId).value, "hex")]));
33-
return new PlatformAddress(H160.ensure(accountId), encode(isTestnet ? "tcc" : "ccc", words));
33+
return new PlatformAddress(H160.ensure(accountId), encode(networkId + "c", words));
3434
}
3535

3636
static fromString(address: string) {
37-
if (!address.startsWith("ccc") && !address.startsWith("tcc")) {
37+
if (address.charAt(2) !== "c") {
3838
throw `The prefix is unknown for platform address: ${address}`;
3939
}
4040

src/key/__test__/PlatformAddress.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test("PlatformAddress.fromAccountId - mainnet (default)", () => {
1010

1111
test("PlatformAddress.fromAccountId - testnet", () => {
1212
const accountId = new H160("7b5e0ee8644c6f585fc297364143280a45844502");
13-
const address = PlatformAddress.fromAccountId(accountId, { isTestnet: true });
13+
const address = PlatformAddress.fromAccountId(accountId, { networkId: "tc" });
1414
expect(address.value).toMatch(/^tcc[a-z0-9]+$/);
1515
});
1616

0 commit comments

Comments
 (0)