Skip to content

Commit bb46252

Browse files
author
Greg S
committed
fix #48: MosaicId, MosaicInfo, Mosaic*View, MosaicService changes to not include parent namespace anymore ; Added MosaicInfo.nonce ; MosaicName removed ; MosaicAmountView.fullName() returns hexadecimal notation ; Removed mosaics from namespace logic
1 parent b692309 commit bb46252

File tree

14 files changed

+46
-270
lines changed

14 files changed

+46
-270
lines changed

e2e/infrastructure/MosaicHttp.spec.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,29 +53,4 @@ describe('MosaicHttp', () => {
5353
});
5454
});
5555
});
56-
57-
describe('getMosaicsFromNamespace', () => {
58-
it('should return mosaics given namespaceId', (done) => {
59-
mosaicHttp.getMosaicsFromNamespace(namespaceId)
60-
.subscribe((mosaicInfos) => {
61-
expect(mosaicInfos[0].height.lower).to.be.equal(1);
62-
expect(mosaicInfos[0].height.higher).to.be.equal(0);
63-
expect(mosaicInfos[0].divisibility).to.be.equal(6);
64-
expect(mosaicInfos[0].isSupplyMutable()).to.be.equal(false);
65-
expect(mosaicInfos[0].isTransferable()).to.be.equal(true);
66-
expect(mosaicInfos[0].isLevyMutable()).to.be.equal(false);
67-
done();
68-
});
69-
});
70-
});
71-
72-
describe('getMosaicsName', () => {
73-
it('should return mosaics name given array of mosaicIds', (done) => {
74-
mosaicHttp.getMosaicsName([mosaicId])
75-
.subscribe((mosaicNames) => {
76-
expect(mosaicNames[0].name).to.be.equal('xem');
77-
done();
78-
});
79-
});
80-
});
8156
});

src/infrastructure/MosaicHttp.ts

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {map, mergeMap} from 'rxjs/operators';
2020
import {PublicAccount} from '../model/account/PublicAccount';
2121
import {MosaicId} from '../model/mosaic/MosaicId';
2222
import {MosaicInfo} from '../model/mosaic/MosaicInfo';
23-
import {MosaicName} from '../model/mosaic/MosaicName';
2423
import {MosaicProperties} from '../model/mosaic/MosaicProperties';
2524
import {NamespaceId} from '../model/namespace/NamespaceId';
2625
import {UInt64} from '../model/UInt64';
@@ -65,8 +64,8 @@ export class MosaicHttp extends Http implements MosaicRepository {
6564
mosaicInfoDTO.meta.active,
6665
mosaicInfoDTO.meta.index,
6766
mosaicInfoDTO.meta.id,
68-
new NamespaceId(mosaicInfoDTO.mosaic.namespaceId),
6967
new MosaicId(mosaicInfoDTO.mosaic.mosaicId),
68+
new UInt64(mosaicInfoDTO.mosaic.nonce),
7069
new UInt64(mosaicInfoDTO.mosaic.supply),
7170
new UInt64(mosaicInfoDTO.mosaic.height),
7271
PublicAccount.createFromPublicKey(mosaicInfoDTO.mosaic.owner, networkType),
@@ -97,8 +96,8 @@ export class MosaicHttp extends Http implements MosaicRepository {
9796
mosaicInfoDTO.meta.active,
9897
mosaicInfoDTO.meta.index,
9998
mosaicInfoDTO.meta.id,
100-
new NamespaceId(mosaicInfoDTO.mosaic.namespaceId),
10199
new MosaicId(mosaicInfoDTO.mosaic.mosaicId),
100+
new UInt64(mosaicInfoDTO.mosaic.nonce),
102101
new UInt64(mosaicInfoDTO.mosaic.supply),
103102
new UInt64(mosaicInfoDTO.mosaic.height),
104103
PublicAccount.createFromPublicKey(mosaicInfoDTO.mosaic.owner, networkType),
@@ -112,57 +111,4 @@ export class MosaicHttp extends Http implements MosaicRepository {
112111
});
113112
}))));
114113
}
115-
116-
/**
117-
* Gets array of MosaicInfo from mosaics created with provided namespace
118-
* @param namespaceId - Namespace id
119-
* @param queryParams - (Optional) Query params
120-
* @returns Observable<MosaicInfo[]>
121-
*/
122-
public getMosaicsFromNamespace(namespaceId: NamespaceId,
123-
queryParams?: QueryParams): Observable<MosaicInfo[]> {
124-
return this.getNetworkTypeObservable().pipe(
125-
mergeMap((networkType) => observableFrom(
126-
this.mosaicRoutesApi.getMosaicsFromNamespace(namespaceId.toHex(), queryParams != null ? queryParams : {})).pipe(
127-
map((mosaicsDefinitionDTO) => {
128-
return mosaicsDefinitionDTO.map((mosaicInfoDTO) => {
129-
return new MosaicInfo(
130-
mosaicInfoDTO.meta.active,
131-
mosaicInfoDTO.meta.index,
132-
mosaicInfoDTO.meta.id,
133-
new NamespaceId(mosaicInfoDTO.mosaic.namespaceId),
134-
new MosaicId(mosaicInfoDTO.mosaic.mosaicId),
135-
new UInt64(mosaicInfoDTO.mosaic.supply),
136-
new UInt64(mosaicInfoDTO.mosaic.height),
137-
PublicAccount.createFromPublicKey(mosaicInfoDTO.mosaic.owner, networkType),
138-
new MosaicProperties(
139-
new UInt64(mosaicInfoDTO.mosaic.properties[0]),
140-
(new UInt64(mosaicInfoDTO.mosaic.properties[1])).compact(),
141-
new UInt64(mosaicInfoDTO.mosaic.properties[2]),
142-
),
143-
mosaicInfoDTO.mosaic.levy,
144-
);
145-
});
146-
}))));
147-
}
148-
149-
/**
150-
* Gets array of MosaicName for different mosaicIds
151-
* @param mosaicIds - Array of mosaic ids
152-
* @returns Observable<MosaicName[]>
153-
*/
154-
public getMosaicsName(mosaicIds: MosaicId[]): Observable<MosaicName[]> {
155-
const mosaicIdsBody = {
156-
mosaicIds: mosaicIds.map((id) => id.toHex()),
157-
};
158-
return observableFrom(this.mosaicRoutesApi.getMosaicsName(mosaicIdsBody)).pipe(map((mosaicInfosDTO) => {
159-
return mosaicInfosDTO.map((mosaicInfoDTO) => {
160-
return new MosaicName(
161-
new MosaicId(mosaicInfoDTO.mosaicId),
162-
new NamespaceId(mosaicInfoDTO.parentId),
163-
mosaicInfoDTO.name,
164-
);
165-
});
166-
}));
167-
}
168114
}

src/infrastructure/MosaicRepository.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import {Observable} from 'rxjs';
1818
import {MosaicId} from '../model/mosaic/MosaicId';
1919
import {MosaicInfo} from '../model/mosaic/MosaicInfo';
20-
import {MosaicName} from '../model/mosaic/MosaicName';
21-
import {NamespaceId} from '../model/namespace/NamespaceId';
2220
import {QueryParams} from './QueryParams';
2321

2422
/**
@@ -41,20 +39,4 @@ export interface MosaicRepository {
4139
* @returns Observable<MosaicInfo[]>
4240
*/
4341
getMosaics(mosaicIds: MosaicId[]): Observable<MosaicInfo[]>;
44-
45-
/**
46-
* Gets array of MosaicInfo from mosaics created with provided namespace
47-
* @param namespaceId - Namespace id
48-
* @param queryParams - (Optional) Query params
49-
* @returns Observable<MosaicInfo[]>
50-
*/
51-
getMosaicsFromNamespace(namespaceId: NamespaceId,
52-
queryParams?: QueryParams): Observable<MosaicInfo[]>;
53-
54-
/**
55-
* Gets array of MosaicName for different mosaicIds
56-
* @param mosaicIds - Array of mosaic ids
57-
* @returns Observable<MosaicName[]>
58-
*/
59-
getMosaicsName(mosaicIds: MosaicId[]): Observable<MosaicName[]>;
6042
}

src/model/model.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export * from './blockchain/NetworkType';
3535
export * from './mosaic/Mosaic';
3636
export * from './mosaic/MosaicInfo';
3737
export * from './mosaic/MosaicId';
38-
export * from './mosaic/MosaicName';
3938
export * from './mosaic/MosaicSupplyType';
4039
export * from './mosaic/MosaicProperties';
4140
export * from '../service/MosaicView';

src/model/mosaic/MosaicInfo.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
import {PublicAccount} from '../account/PublicAccount';
1818
import {UInt64} from '../UInt64';
19-
import {MosaicProperties} from './MosaicProperties';
20-
import {NamespaceId} from '../namespace/NamespaceId';
2119
import {MosaicId} from './MosaicId';
20+
import {MosaicProperties} from './MosaicProperties';
2221

2322
/**
2423
* The mosaic info structure describes a mosaic.
@@ -29,8 +28,7 @@ export class MosaicInfo {
2928
* @param active
3029
* @param index
3130
* @param metaId
32-
* @param namespaceId
33-
* @param mosaicId
31+
* @param nonce
3432
* @param supply
3533
* @param height
3634
* @param owner
@@ -50,13 +48,13 @@ export class MosaicInfo {
5048
*/
5149
public readonly metaId: string,
5250
/**
53-
* The namespace id.
51+
* The mosaic nonce.
5452
*/
55-
public readonly namespaceId: NamespaceId,
53+
public readonly mosaicId: MosaicId,
5654
/**
57-
* The mosaic id.
55+
* The mosaic nonce.
5856
*/
59-
public readonly mosaicId: MosaicId,
57+
public readonly nonce: UInt64,
6058
/**
6159
* The mosaic supply.
6260
*/
@@ -118,4 +116,5 @@ export class MosaicInfo {
118116
public isLevyMutable(): boolean {
119117
return this.properties.levyMutable;
120118
}
119+
121120
}

src/model/mosaic/MosaicName.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/service/MosaicAmountView.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ export class MosaicAmountView {
3232
* The mosaic information
3333
*/
3434
public readonly mosaicInfo: MosaicInfo,
35-
/**
36-
* The parent namespace name
37-
*/
38-
public readonly namespaceName: string,
39-
/**
40-
* The mosaic name
41-
*/
42-
public readonly mosaicName: string,
4335
/**
4436
* The amount of absolute mosaics we have
4537
*/
@@ -63,6 +55,6 @@ export class MosaicAmountView {
6355
* @returns {string}
6456
*/
6557
public fullName(): string {
66-
return this.namespaceName + ':' + this.mosaicName;
58+
return this.mosaicInfo.mosaicId.toHex();
6759
}
6860
}

src/service/MosaicService.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { Observable, of as observableOf } from 'rxjs';
18-
import { filter, map, mergeMap, take, toArray, first } from 'rxjs/operators';
18+
import { filter, first, map, mergeMap, take, toArray } from 'rxjs/operators';
1919
import { AccountHttp } from '../infrastructure/AccountHttp';
2020
import { MosaicHttp } from '../infrastructure/MosaicHttp';
2121
import { NamespaceHttp } from '../infrastructure/NamespaceHttp';
@@ -50,16 +50,11 @@ export class MosaicService {
5050
*/
5151
mosaicsView(mosaicIds: MosaicId[]): Observable<MosaicView[]> {
5252
return observableOf(mosaicIds).pipe(
53-
mergeMap((_) => this.mosaicHttp.getMosaics(mosaicIds)),
54-
mergeMap((_) => _),
55-
mergeMap((mosaicInfo: MosaicInfo) => this.mosaicHttp.getMosaicsName([mosaicInfo.mosaicId]).pipe(map((mosaicsName) => {
56-
return { mosaicInfo, mosaicName: mosaicsName[0].name };
57-
}))),
58-
mergeMap((_) => this.namespaceHttp.getNamespacesName([_.mosaicInfo.namespaceId]).pipe(
59-
map((namespacesName) => {
60-
return new MosaicView(_.mosaicInfo, namespacesName[0].name, _.mosaicName);
61-
}))),
62-
toArray());
53+
mergeMap((_) => this.mosaicHttp.getMosaics(mosaicIds).pipe(
54+
map((mosaicInfo: MosaicInfo) => {
55+
return new MosaicView(mosaicInfo);
56+
}),
57+
toArray())));
6358
}
6459

6560
/**
@@ -73,10 +68,7 @@ export class MosaicService {
7368
mergeMap((mosaic: Mosaic) => this.mosaicsView([mosaic.id]).pipe(
7469
filter((_) => _.length !== 0),
7570
map<MosaicView[], MosaicAmountView>((mosaicViews) => {
76-
return new MosaicAmountView(mosaicViews[0].mosaicInfo,
77-
mosaicViews[0].namespaceName,
78-
mosaicViews[0].mosaicName,
79-
mosaic.amount);
71+
return new MosaicAmountView(mosaicViews[0].mosaicInfo, mosaic.amount);
8072
}),
8173
toArray())));
8274
}

src/service/MosaicView.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,7 @@ export class MosaicView {
3030
constructor(/**
3131
* The mosaic information
3232
*/
33-
public readonly mosaicInfo: MosaicInfo,
34-
/**
35-
* The parent namespace name
36-
*/
37-
public readonly namespaceName: string,
38-
/**
39-
* The mosaic name
40-
*/
41-
public readonly mosaicName: string) {
42-
43-
}
33+
public readonly mosaicInfo: MosaicInfo) {
4434

45-
/**
46-
* Namespace and mosaic description
47-
* @returns {string}
48-
*/
49-
public fullName(): string {
50-
return this.namespaceName + ':' + this.mosaicName;
5135
}
5236
}

test/model/mosaic/MosaicAmountView.spec.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ describe('MosaicAmountView', () => {
2929
let mosaicInfo: MosaicInfo;
3030

3131
before(() => {
32-
mosaicInfo = new MosaicInfo(true, 0, '59FDA0733F17CF0001772CBC', new NamespaceId([929036875, 2226345261]),
33-
new MosaicId([3646934825, 3576016193]), new UInt64([3403414400, 2095475]), new UInt64([1, 0]),
32+
mosaicInfo = new MosaicInfo(true, 0, '59FDA0733F17CF0001772CBC', new MosaicId([3294802500, 2243684972]),
33+
new UInt64([1, 0]), new UInt64([3403414400, 2095475]), new UInt64([1, 0]),
3434
PublicAccount.createFromPublicKey('B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', NetworkType.MIJIN_TEST),
3535
MosaicProperties.create({
3636
supplyMutable: true,
@@ -42,19 +42,20 @@ describe('MosaicAmountView', () => {
4242
});
4343

4444
it('should createComplete a Mosaic Amount View', () => {
45-
const mosaicAmountView = new MosaicAmountView(mosaicInfo, 'namespaceName', 'mosaicName', UInt64.fromUint(100));
45+
const mosaicAmountView = new MosaicAmountView(mosaicInfo, UInt64.fromUint(100));
4646
expect(mosaicAmountView.amount.compact()).to.be.equal(100);
47-
expect(mosaicAmountView.namespaceName).to.be.equal('namespaceName');
48-
expect(mosaicAmountView.mosaicName).to.be.equal('mosaicName');
47+
expect(mosaicAmountView.mosaicInfo).to.be.an.instanceof(MosaicInfo);
4948
});
5049

5150
it('should createComplete a Mosaic Amount View get relative amount', () => {
52-
const mosaicAmountView = new MosaicAmountView(mosaicInfo, 'namespaceName', 'mosaicName', UInt64.fromUint(100));
51+
const mosaicAmountView = new MosaicAmountView(mosaicInfo, UInt64.fromUint(100));
5352
expect(mosaicAmountView.relativeAmount()).to.be.equal(100 / Math.pow(10, 3));
53+
expect(mosaicAmountView.mosaicInfo).to.be.an.instanceof(MosaicInfo);
5454
});
5555

56-
it('should createComplete a Mosaic Amount View get correct fullName', () => {
57-
const mosaicAmountView = new MosaicAmountView(mosaicInfo, 'namespaceName', 'mosaicName', UInt64.fromUint(100));
58-
expect(mosaicAmountView.fullName()).to.be.equal('namespaceName:mosaicName');
56+
it('should createComplete a Mosaic Amount View get correct amount', () => {
57+
const mosaicAmountView = new MosaicAmountView(mosaicInfo, UInt64.fromUint(100));
58+
expect(mosaicAmountView.mosaicInfo).to.be.an.instanceof(MosaicInfo);
59+
expect(mosaicAmountView.amount.compact()).to.be.equal(100);
5960
});
6061
});

0 commit comments

Comments
 (0)