Skip to content

Commit bedc30d

Browse files
committed
Remove hardcoded values from namespace examples
1 parent 82ff179 commit bedc30d

File tree

7 files changed

+187
-158
lines changed

7 files changed

+187
-158
lines changed

source/guides/namespace/link-a-namespace-to-a-mosaic.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Method #02: Using the SDK
7878
:start-after: /* start block 02 */
7979
:end-before: /* end block 02 */
8080
81-
.. note:: If you want to unlink the alias, change alias action type to ``AliasActionType.Unlink``.
81+
.. note:: If you want to unlink the alias, change alias action type to ``AliasAction.Unlink``.
8282

8383
.. _sending-a-transfer-transaction-with-an-aliased-mosaic:
8484

source/resources/examples/typescript/namespace/GettingNamespaceInformation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import { NamespaceId, RepositoryFactoryHttp } from 'symbol-sdk';
2020

2121
/* start block 01 */
22-
// replace with namespace name
22+
// Replace with namespace name
2323
const namespaceId = new NamespaceId('foo');
24-
// replace with node endpoint
24+
// Replace with node endpoint
2525
const nodeUrl = 'http://api-01.us-east-1.testnet.symboldev.network:3000';
2626
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
2727
const namespaceHttp = repositoryFactory.createNamespaceRepository();

source/resources/examples/typescript/namespace/GettingNamespaceRentalFee.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import { RepositoryFactoryHttp } from 'symbol-sdk';
2020

2121
/* start block 01 */
22+
// Replace with node endpoint
2223
const nodeUrl = 'http://api-01.us-east-1.testnet.symboldev.network:3000';
2324
const repositoryHttp = new RepositoryFactoryHttp(nodeUrl);
2425

source/resources/examples/typescript/namespace/LinkingANamespaceToAMosaic.ts

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,52 +23,59 @@ import {
2323
Deadline,
2424
MosaicId,
2525
NamespaceId,
26-
NetworkType,
2726
RepositoryFactoryHttp,
2827
UInt64,
2928
} from 'symbol-sdk';
3029

31-
// Retrieve from node's /network/properties or RepositoryFactory
32-
const epochAdjustment = 123456789;
30+
const example = async (): Promise<void> => {
31+
try {
32+
// Network information
33+
const nodeUrl = 'http://api-01.us-east-1.testnet.symboldev.network:3000';
34+
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
35+
const epochAdjustment = await repositoryFactory
36+
.getEpochAdjustment()
37+
.toPromise();
38+
const networkType = await repositoryFactory.getNetworkType().toPromise();
39+
const networkGenerationHash = await repositoryFactory
40+
.getGenerationHash()
41+
.toPromise();
3342

34-
/* start block 01 */
35-
// replace with namespace name
36-
const namespaceId = new NamespaceId('foo');
37-
// replace with mosaic id
38-
const mosaicId = new MosaicId('7cdf3b117a3c40cc');
39-
/* end block 01 */
43+
/* start block 01 */
44+
// Replace with namespace name
45+
const namespaceId = new NamespaceId('foo');
46+
// Replace with mosaic id
47+
const mosaicId = new MosaicId('7cdf3b117a3c40cc');
48+
/* end block 01 */
4049

41-
/* start block 02 */
42-
// replace with networkType
43-
const networkType = NetworkType.TEST_NET;
50+
/* start block 02 */
51+
const mosaicAliasTransaction = AliasTransaction.createForMosaic(
52+
Deadline.create(epochAdjustment),
53+
AliasAction.Link,
54+
namespaceId,
55+
mosaicId,
56+
networkType,
57+
UInt64.fromUint(2000000),
58+
);
4459

45-
const mosaicAliasTransaction = AliasTransaction.createForMosaic(
46-
Deadline.create(epochAdjustment),
47-
AliasAction.Link,
48-
namespaceId,
49-
mosaicId,
50-
networkType,
51-
UInt64.fromUint(2000000),
52-
);
60+
// Replace with private key
61+
const privateKey =
62+
'1111111111111111111111111111111111111111111111111111111111111111';
63+
const account = Account.createFromPrivateKey(privateKey, networkType);
5364

54-
// replace with private key
55-
const privateKey =
56-
'1111111111111111111111111111111111111111111111111111111111111111';
57-
const account = Account.createFromPrivateKey(privateKey, networkType);
58-
// replace with meta.networkGenerationHash (nodeUrl + '/node/info')
59-
const networkGenerationHash =
60-
'1DFB2FAA9E7F054168B0C5FCB84F4DEB62CC2B4D317D861F3168D161F54EA78B';
61-
const signedTransaction = account.sign(
62-
mosaicAliasTransaction,
63-
networkGenerationHash,
64-
);
65-
// replace with node endpoint
66-
const nodeUrl = 'http://api-01.us-east-1.testnet.symboldev.network:3000';
67-
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
68-
const transactionHttp = repositoryFactory.createTransactionRepository();
65+
const signedTransaction = account.sign(
66+
mosaicAliasTransaction,
67+
networkGenerationHash,
68+
);
69+
console.log('Signed transaction hash: ' + signedTransaction.hash);
6970

70-
transactionHttp.announce(signedTransaction).subscribe(
71-
(x) => console.log(x),
72-
(err) => console.error(err),
73-
);
74-
/* end block 02 */
71+
const transactionHttp = repositoryFactory.createTransactionRepository();
72+
transactionHttp.announce(signedTransaction).subscribe(
73+
(x) => console.log(x),
74+
(err) => console.error(err),
75+
);
76+
/* end block 02 */
77+
} catch (e) {
78+
console.log(e);
79+
}
80+
};
81+
example().then();

source/resources/examples/typescript/namespace/LinkingANamespaceToAnAddress.ts

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,53 +23,60 @@ import {
2323
AliasTransaction,
2424
Deadline,
2525
NamespaceId,
26-
NetworkType,
2726
RepositoryFactoryHttp,
2827
UInt64,
2928
} from 'symbol-sdk';
3029

31-
// Retrieve from node's /network/properties or RepositoryFactory
32-
const epochAdjustment = 123456789;
30+
const example = async (): Promise<void> => {
31+
try {
32+
// Network information
33+
const nodeUrl = 'http://api-01.us-east-1.testnet.symboldev.network:3000';
34+
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
35+
const epochAdjustment = await repositoryFactory
36+
.getEpochAdjustment()
37+
.toPromise();
38+
const networkType = await repositoryFactory.getNetworkType().toPromise();
39+
const networkGenerationHash = await repositoryFactory
40+
.getGenerationHash()
41+
.toPromise();
3342

34-
/* start block 01 */
35-
// replace with namespace name
36-
const namespaceId = new NamespaceId('foo');
37-
// replace with address
38-
const rawAddress = 'TCHBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I';
39-
const address = Address.createFromRawAddress(rawAddress);
40-
/* end block 01 */
43+
/* start block 01 */
44+
// Replace with namespace name
45+
const namespaceId = new NamespaceId('foo');
46+
// Replace with address
47+
const rawAddress = 'TCHBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I';
48+
const address = Address.createFromRawAddress(rawAddress);
49+
/* end block 01 */
4150

42-
/* start block 02 */
43-
// replace with network type
44-
const networkType = NetworkType.TEST_NET;
51+
/* start block 02 */
52+
const addressAliasTransaction = AliasTransaction.createForAddress(
53+
Deadline.create(epochAdjustment),
54+
AliasAction.Link,
55+
namespaceId,
56+
address,
57+
networkType,
58+
UInt64.fromUint(2000000),
59+
);
4560

46-
const addressAliasTransaction = AliasTransaction.createForAddress(
47-
Deadline.create(epochAdjustment),
48-
AliasAction.Link,
49-
namespaceId,
50-
address,
51-
networkType,
52-
UInt64.fromUint(2000000),
53-
);
61+
// Replace with private key
62+
const privateKey =
63+
'1111111111111111111111111111111111111111111111111111111111111111';
64+
const account = Account.createFromPrivateKey(privateKey, networkType);
5465

55-
// replace with private key
56-
const privateKey =
57-
'1111111111111111111111111111111111111111111111111111111111111111';
58-
const account = Account.createFromPrivateKey(privateKey, networkType);
59-
// replace with meta.networkGenerationHash (nodeUrl + '/node/info')
60-
const networkGenerationHash =
61-
'1DFB2FAA9E7F054168B0C5FCB84F4DEB62CC2B4D317D861F3168D161F54EA78B';
62-
const signedTransaction = account.sign(
63-
addressAliasTransaction,
64-
networkGenerationHash,
65-
);
66-
// replace with node endpoint
67-
const nodeUrl = 'http://api-01.us-east-1.testnet.symboldev.network:3000';
68-
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
69-
const transactionHttp = repositoryFactory.createTransactionRepository();
66+
const signedTransaction = account.sign(
67+
addressAliasTransaction,
68+
networkGenerationHash,
69+
);
70+
console.log('Signed transaction hash: ' + signedTransaction.hash);
7071

71-
transactionHttp.announce(signedTransaction).subscribe(
72-
(x) => console.log(x),
73-
(err) => console.error(err),
74-
);
75-
/* end block 02 */
72+
const transactionHttp = repositoryFactory.createTransactionRepository();
73+
transactionHttp.announce(signedTransaction).subscribe(
74+
(x) => console.log(x),
75+
(err) => console.error(err),
76+
);
77+
/* end block 02 */
78+
} catch (e) {
79+
console.log(e);
80+
}
81+
};
82+
example().then();

source/resources/examples/typescript/namespace/RegisteringANamespace.ts

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,55 @@ import {
2020
Account,
2121
Deadline,
2222
NamespaceRegistrationTransaction,
23-
NetworkType,
2423
RepositoryFactoryHttp,
2524
UInt64,
2625
} from 'symbol-sdk';
2726

28-
// Retrieve from node's /network/properties or RepositoryFactory
29-
const epochAdjustment = 123456789;
27+
const example = async (): Promise<void> => {
28+
try {
29+
// Network information
30+
const nodeUrl = 'http://api-01.us-east-1.testnet.symboldev.network:3000';
31+
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
32+
const epochAdjustment = await repositoryFactory
33+
.getEpochAdjustment()
34+
.toPromise();
35+
const networkType = await repositoryFactory.getNetworkType().toPromise();
36+
const networkGenerationHash = await repositoryFactory
37+
.getGenerationHash()
38+
.toPromise();
3039

31-
/* start block 01 */
32-
// replace with namespace name
33-
const namespaceName = 'foo';
34-
// replace with duration (in blocks)
35-
const duration = UInt64.fromUint(172800);
36-
// replace with network type
37-
const networkType = NetworkType.TEST_NET;
40+
/* start block 01 */
41+
// Replace with namespace name
42+
const namespaceName = 'foo';
43+
// Replace with duration (in blocks)
44+
const duration = UInt64.fromUint(172800);
3845

39-
const namespaceRegistrationTransaction = NamespaceRegistrationTransaction.createRootNamespace(
40-
Deadline.create(epochAdjustment),
41-
namespaceName,
42-
duration,
43-
networkType,
44-
UInt64.fromUint(2000000),
45-
);
46+
const namespaceRegistrationTransaction = NamespaceRegistrationTransaction.createRootNamespace(
47+
Deadline.create(epochAdjustment),
48+
namespaceName,
49+
duration,
50+
networkType,
51+
UInt64.fromUint(2000000),
52+
);
4653

47-
// replace with private key
48-
const privateKey =
49-
'1111111111111111111111111111111111111111111111111111111111111111';
50-
const account = Account.createFromPrivateKey(privateKey, networkType);
51-
// replace with meta.networkGenerationHash (nodeUrl + '/node/info')
52-
const networkGenerationHash =
53-
'1DFB2FAA9E7F054168B0C5FCB84F4DEB62CC2B4D317D861F3168D161F54EA78B';
54-
const signedTransaction = account.sign(
55-
namespaceRegistrationTransaction,
56-
networkGenerationHash,
57-
);
58-
// replace with node endpoint
59-
const nodeUrl = 'http://api-01.us-east-1.testnet.symboldev.network:3000';
60-
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
61-
const transactionHttp = repositoryFactory.createTransactionRepository();
54+
// Replace with private key
55+
const privateKey =
56+
'1111111111111111111111111111111111111111111111111111111111111111';
57+
const account = Account.createFromPrivateKey(privateKey, networkType);
58+
const signedTransaction = account.sign(
59+
namespaceRegistrationTransaction,
60+
networkGenerationHash,
61+
);
62+
console.log('Signed transaction hash: ' + signedTransaction.hash);
6263

63-
transactionHttp.announce(signedTransaction).subscribe(
64-
(x) => console.log(x),
65-
(err) => console.error(err),
66-
);
67-
/* end block 01 */
64+
const transactionHttp = repositoryFactory.createTransactionRepository();
65+
transactionHttp.announce(signedTransaction).subscribe(
66+
(x) => console.log(x),
67+
(err) => console.error(err),
68+
);
69+
/* end block 01 */
70+
} catch (e) {
71+
console.log(e);
72+
}
73+
};
74+
example().then();

0 commit comments

Comments
 (0)