Skip to content

Commit c9e9821

Browse files
author
Greg S
committed
WIP #66: Added NetworkCurrencyMosaic and NetworkHarvestMosaic and tests
1 parent 4f4127c commit c9e9821

File tree

13 files changed

+365
-185
lines changed

13 files changed

+365
-185
lines changed

e2e/infrastructure/TransactionHttp.spec.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {NetworkType} from '../../src/model/blockchain/NetworkType';
2828
import {MosaicId} from '../../src/model/mosaic/MosaicId';
2929
import {MosaicProperties} from '../../src/model/mosaic/MosaicProperties';
3030
import {MosaicSupplyType} from '../../src/model/mosaic/MosaicSupplyType';
31-
import {XEM} from '../../src/model/mosaic/XEM';
31+
import {NetworkCurrencyMosaic} from '../../src/model/mosaic/NetworkCurrencyMosaic';
3232
import {AggregateTransaction} from '../../src/model/transaction/AggregateTransaction';
3333
import {CosignatureSignedTransaction} from '../../src/model/transaction/CosignatureSignedTransaction';
3434
import {CosignatureTransaction} from '../../src/model/transaction/CosignatureTransaction';
@@ -97,7 +97,7 @@ describe('TransactionHttp', () => {
9797
const transferTransaction = TransferTransaction.create(
9898
Deadline.create(),
9999
Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'),
100-
[XEM.createRelative(10)],
100+
[NetworkCurrencyMosaic.createRelative(10)],
101101
PlainMessage.create('test-message'),
102102
NetworkType.MIJIN_TEST,
103103
);
@@ -244,7 +244,7 @@ describe('TransactionHttp', () => {
244244
);
245245

246246
const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(),
247-
XEM.createRelative(10),
247+
NetworkCurrencyMosaic.createRelative(10),
248248
UInt64.fromUint(10000),
249249
signedTransaction,
250250
NetworkType.MIJIN_TEST);
@@ -265,7 +265,7 @@ describe('TransactionHttp', () => {
265265
const transferTransaction = TransferTransaction.create(
266266
Deadline.create(),
267267
Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'),
268-
[XEM.createRelative(1)],
268+
[NetworkCurrencyMosaic.createRelative(1)],
269269
PlainMessage.create('test-message'),
270270
NetworkType.MIJIN_TEST,
271271
);
@@ -279,7 +279,7 @@ describe('TransactionHttp', () => {
279279
);
280280

281281
const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(),
282-
XEM.createRelative(10),
282+
NetworkCurrencyMosaic.createRelative(10),
283283
UInt64.fromUint(10000),
284284
signedTransaction,
285285
NetworkType.MIJIN_TEST);
@@ -316,7 +316,7 @@ describe('TransactionHttp', () => {
316316
const signedTransaction = account.sign(aggregateTransaction);
317317

318318
const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(),
319-
XEM.createRelative(10),
319+
NetworkCurrencyMosaic.createRelative(10),
320320
UInt64.fromUint(10000),
321321
signedTransaction,
322322
NetworkType.MIJIN_TEST);
@@ -333,7 +333,7 @@ describe('TransactionHttp', () => {
333333
);
334334
const signedTransaction = account.sign(aggregateTransaction);
335335
const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(),
336-
XEM.createRelative(10),
336+
NetworkCurrencyMosaic.createRelative(10),
337337
UInt64.fromUint(10),
338338
signedTransaction,
339339
NetworkType.MIJIN_TEST);
@@ -351,7 +351,7 @@ describe('TransactionHttp', () => {
351351
it('standalone', (done) => {
352352
const secretLockTransaction = SecretLockTransaction.create(
353353
Deadline.create(),
354-
XEM.createAbsolute(10),
354+
NetworkCurrencyMosaic.createAbsolute(10),
355355
UInt64.fromUint(100),
356356
HashType.Op_Sha3_256,
357357
sha3_256.create().update(nacl_catapult.randomBytes(20)).hex(),
@@ -365,7 +365,7 @@ describe('TransactionHttp', () => {
365365
it('aggregate', (done) => {
366366
const secretLockTransaction = SecretLockTransaction.create(
367367
Deadline.create(),
368-
XEM.createAbsolute(10),
368+
NetworkCurrencyMosaic.createAbsolute(10),
369369
UInt64.fromUint(100),
370370
HashType.Op_Sha3_256,
371371
sha3_256.create().update(nacl_catapult.randomBytes(20)).hex(),
@@ -384,7 +384,7 @@ describe('TransactionHttp', () => {
384384
it('standalone', (done) => {
385385
const secretLockTransaction = SecretLockTransaction.create(
386386
Deadline.create(),
387-
XEM.createAbsolute(10),
387+
NetworkCurrencyMosaic.createAbsolute(10),
388388
UInt64.fromUint(100),
389389
HashType.Op_Keccak_256,
390390
sha3_256.create().update(nacl_catapult.randomBytes(20)).hex(),
@@ -398,7 +398,7 @@ describe('TransactionHttp', () => {
398398
it('aggregate', (done) => {
399399
const secretLockTransaction = SecretLockTransaction.create(
400400
Deadline.create(),
401-
XEM.createAbsolute(10),
401+
NetworkCurrencyMosaic.createAbsolute(10),
402402
UInt64.fromUint(100),
403403
HashType.Op_Keccak_256,
404404
sha3_256.create().update(nacl_catapult.randomBytes(20)).hex(),
@@ -417,7 +417,7 @@ describe('TransactionHttp', () => {
417417
it('standalone', (done) => {
418418
const secretLockTransaction = SecretLockTransaction.create(
419419
Deadline.create(),
420-
XEM.createAbsolute(10),
420+
NetworkCurrencyMosaic.createAbsolute(10),
421421
UInt64.fromUint(100),
422422
HashType.Op_Hash_160,
423423
sha3_256.create().update(nacl_catapult.randomBytes(20)).hex(),
@@ -431,7 +431,7 @@ describe('TransactionHttp', () => {
431431
it('aggregate', (done) => {
432432
const secretLockTransaction = SecretLockTransaction.create(
433433
Deadline.create(),
434-
XEM.createAbsolute(10),
434+
NetworkCurrencyMosaic.createAbsolute(10),
435435
UInt64.fromUint(100),
436436
HashType.Op_Hash_160,
437437
sha3_256.create().update(nacl_catapult.randomBytes(20)).hex(),
@@ -450,7 +450,7 @@ describe('TransactionHttp', () => {
450450
it('standalone', (done) => {
451451
const secretLockTransaction = SecretLockTransaction.create(
452452
Deadline.create(),
453-
XEM.createAbsolute(10),
453+
NetworkCurrencyMosaic.createAbsolute(10),
454454
UInt64.fromUint(100),
455455
HashType.Op_Hash_256,
456456
sha3_256.create().update(nacl_catapult.randomBytes(20)).hex(),
@@ -464,7 +464,7 @@ describe('TransactionHttp', () => {
464464
it('aggregate', (done) => {
465465
const secretLockTransaction = SecretLockTransaction.create(
466466
Deadline.create(),
467-
XEM.createAbsolute(10),
467+
NetworkCurrencyMosaic.createAbsolute(10),
468468
UInt64.fromUint(100),
469469
HashType.Op_Hash_256,
470470
sha3_256.create().update(nacl_catapult.randomBytes(20)).hex(),
@@ -488,7 +488,7 @@ describe('TransactionHttp', () => {
488488
const proof = convert.uint8ToHex(secretSeed);
489489
const secretLockTransaction = SecretLockTransaction.create(
490490
Deadline.create(),
491-
XEM.createAbsolute(10),
491+
NetworkCurrencyMosaic.createAbsolute(10),
492492
UInt64.fromUint(100),
493493
HashType.Op_Sha3_256,
494494
secret,
@@ -515,7 +515,7 @@ describe('TransactionHttp', () => {
515515
const proof = convert.uint8ToHex(secretSeed);
516516
const secretLockTransaction = SecretLockTransaction.create(
517517
Deadline.create(),
518-
XEM.createAbsolute(10),
518+
NetworkCurrencyMosaic.createAbsolute(10),
519519
UInt64.fromUint(100),
520520
HashType.Op_Sha3_256,
521521
secret,
@@ -548,7 +548,7 @@ describe('TransactionHttp', () => {
548548
const proof = convert.uint8ToHex(secretSeed);
549549
const secretLockTransaction = SecretLockTransaction.create(
550550
Deadline.create(),
551-
XEM.createAbsolute(10),
551+
NetworkCurrencyMosaic.createAbsolute(10),
552552
UInt64.fromUint(100),
553553
HashType.Op_Keccak_256,
554554
secret,
@@ -575,7 +575,7 @@ describe('TransactionHttp', () => {
575575
const proof = convert.uint8ToHex(secretSeed);
576576
const secretLockTransaction = SecretLockTransaction.create(
577577
Deadline.create(),
578-
XEM.createAbsolute(10),
578+
NetworkCurrencyMosaic.createAbsolute(10),
579579
UInt64.fromUint(100),
580580
HashType.Op_Keccak_256,
581581
secret,
@@ -607,7 +607,7 @@ describe('TransactionHttp', () => {
607607
const proof = convert.uint8ToHex(secretSeed);
608608
const secretLockTransaction = SecretLockTransaction.create(
609609
Deadline.create(),
610-
XEM.createAbsolute(10),
610+
NetworkCurrencyMosaic.createAbsolute(10),
611611
UInt64.fromUint(100),
612612
HashType.Op_Hash_160,
613613
secret,
@@ -634,7 +634,7 @@ describe('TransactionHttp', () => {
634634
const proof = convert.uint8ToHex(secretSeed);
635635
const secretLockTransaction = SecretLockTransaction.create(
636636
Deadline.create(),
637-
XEM.createAbsolute(10),
637+
NetworkCurrencyMosaic.createAbsolute(10),
638638
UInt64.fromUint(100),
639639
HashType.Op_Hash_160,
640640
secret,
@@ -666,7 +666,7 @@ describe('TransactionHttp', () => {
666666
const proof = convert.uint8ToHex(secretSeed);
667667
const secretLockTransaction = SecretLockTransaction.create(
668668
Deadline.create(),
669-
XEM.createAbsolute(10),
669+
NetworkCurrencyMosaic.createAbsolute(10),
670670
UInt64.fromUint(100),
671671
HashType.Op_Hash_256,
672672
secret,
@@ -693,7 +693,7 @@ describe('TransactionHttp', () => {
693693
const proof = convert.uint8ToHex(secretSeed);
694694
const secretLockTransaction = SecretLockTransaction.create(
695695
Deadline.create(),
696-
XEM.createAbsolute(10),
696+
NetworkCurrencyMosaic.createAbsolute(10),
697697
UInt64.fromUint(100),
698698
HashType.Op_Hash_256,
699699
secret,
@@ -857,7 +857,7 @@ describe('TransactionHttp', () => {
857857
const tx = TransferTransaction.create(
858858
Deadline.create(),
859859
Address.createFromRawAddress('SAGY2PTFX4T2XYKYXTJXYCTQRP3FESQH5MEQI2RQ'),
860-
[XEM.createRelative(10)],
860+
[NetworkCurrencyMosaic.createRelative(10)],
861861
EmptyMessage,
862862
NetworkType.MIJIN_TEST,
863863
);

e2e/infrastructure/TransactionUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {TransactionHttp} from '../../src/infrastructure/TransactionHttp';
1818
import {Account} from '../../src/model/account/Account';
1919
import {Address} from '../../src/model/account/Address';
2020
import {NetworkType} from '../../src/model/blockchain/NetworkType';
21-
import {XEM} from '../../src/model/mosaic/XEM';
21+
import {NetworkCurrencyMosaic} from '../../src/model/mosaic/NetworkCurrencyMosaic';
2222
import {AggregateTransaction} from '../../src/model/transaction/AggregateTransaction';
2323
import {CosignatureTransaction} from '../../src/model/transaction/CosignatureTransaction';
2424
import {Deadline} from '../../src/model/transaction/Deadline';
@@ -47,7 +47,7 @@ export class TransactionUtils {
4747
const transferTransaction = TransferTransaction.create(
4848
Deadline.create(),
4949
Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'),
50-
[XEM.createRelative(100000000000)],
50+
[NetworkCurrencyMosaic.createRelative(100000000000)],
5151
PlainMessage.create('test-message'),
5252
NetworkType.MIJIN_TEST,
5353
);
@@ -59,7 +59,7 @@ export class TransactionUtils {
5959
const transferTransaction = TransferTransaction.create(
6060
Deadline.create(),
6161
Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'),
62-
[XEM.createRelative(100000000000)],
62+
[NetworkCurrencyMosaic.createRelative(100000000000)],
6363
PlainMessage.create('test-message'),
6464
NetworkType.MIJIN_TEST,
6565
);

src/infrastructure/Listener.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,17 @@ export class Listener {
156156
});
157157
}
158158

159-
/**
159+
/**
160160
* returns a boolean that repressents the open state
161161
* @returns a boolean
162162
*/
163163
public isOpen(): boolean {
164-
if(this.webSocket){
164+
if (this.webSocket) {
165165
return this.webSocket.readyState === WebSocket.OPEN;
166166
}
167167
return false;
168168
}
169-
169+
170170
/**
171171
* Close web socket connection.
172172
* @returns void

src/model/model.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export * from './mosaic/MosaicSupplyType';
3939
export * from './mosaic/MosaicProperties';
4040
export * from '../service/MosaicView';
4141
export * from '../service/MosaicAmountView';
42-
export * from './mosaic/XEM';
42+
export * from './mosaic/NetworkCurrencyMosaic';
43+
export * from './mosaic/NetworkHarvestMosaic';
4344

4445
// Namespace
4546
export * from '../service/Namespace';
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright 2019 NEM
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {mosaicId, convert} from 'nem2-library';
18+
import {NamespaceId} from '../namespace/NamespaceId';
19+
import {UInt64} from '../UInt64';
20+
import {Mosaic} from './Mosaic';
21+
import {MosaicId} from './MosaicId';
22+
23+
/**
24+
* NetworkCurrencyMosaic mosaic
25+
*
26+
* This represents the per-network currency mosaic. This mosaicId is aliased
27+
* with namespace name `currency`.
28+
*
29+
* @since 0.10.2
30+
*/
31+
export class NetworkCurrencyMosaic extends Mosaic {
32+
/**
33+
* Per-Network default mosaic owner public key
34+
*/
35+
public static OWNER_PUBLIC_KEY = 'B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF';
36+
37+
/**
38+
* Per-Network currencyMosaicId
39+
*
40+
* @note Little-endianness on nonce field in `mosaicId(nonce, publicKey)`.
41+
* @type {Id}
42+
*/
43+
public static MOSAIC_ID = new MosaicId(mosaicId([
44+
0x0, 0x0,
45+
0x0, 0x0,
46+
], convert.hexToUint8(NetworkCurrencyMosaic.OWNER_PUBLIC_KEY)));
47+
48+
/**
49+
* Divisiblity
50+
* @type {number}
51+
*/
52+
public static DIVISIBILITY = 6;
53+
54+
/**
55+
* Initial supply
56+
* @type {number}
57+
*/
58+
public static INITIAL_SUPPLY = 8999999998;
59+
60+
/**
61+
* Is tranferable
62+
* @type {boolean}
63+
*/
64+
public static TRANSFERABLE = true;
65+
66+
/**
67+
* Is Supply mutable
68+
* @type {boolean}
69+
*/
70+
public static SUPPLY_MUTABLE = false;
71+
72+
/**
73+
* Is Levy mutable
74+
* @type {boolean}
75+
*/
76+
public static LEVY_MUTABLE = false;
77+
78+
/**
79+
* constructor
80+
* @param amount
81+
*/
82+
private constructor(amount: UInt64) {
83+
super(NetworkCurrencyMosaic.MOSAIC_ID, amount);
84+
}
85+
86+
/**
87+
* Create NetworkCurrencyMosaic with using NetworkCurrencyMosaic as unit.
88+
*
89+
* @param amount
90+
* @returns {NetworkCurrencyMosaic}
91+
*/
92+
public static createRelative(amount: UInt64 | number) {
93+
if (typeof amount === 'number') {
94+
return new NetworkCurrencyMosaic(UInt64.fromUint(amount * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY)));
95+
}
96+
return new NetworkCurrencyMosaic(UInt64.fromUint((amount as UInt64).compact() * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY)));
97+
}
98+
99+
/**
100+
* Create NetworkCurrencyMosaic with using micro NetworkCurrencyMosaic as unit,
101+
* 1 NetworkCurrencyMosaic = 1000000 micro NetworkCurrencyMosaic.
102+
*
103+
* @param amount
104+
* @returns {NetworkCurrencyMosaic}
105+
*/
106+
public static createAbsolute(amount: UInt64 | number) {
107+
if (typeof amount === 'number') {
108+
return new NetworkCurrencyMosaic(UInt64.fromUint(amount));
109+
}
110+
return new NetworkCurrencyMosaic(amount as UInt64);
111+
}
112+
}

0 commit comments

Comments
 (0)