Skip to content

Commit 1f0a772

Browse files
committed
Added mosaic property id enum
1 parent 40665b2 commit 1f0a772

File tree

5 files changed

+54
-21
lines changed

5 files changed

+54
-21
lines changed

src/infrastructure/MosaicHttp.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {MosaicId} from '../model/mosaic/MosaicId';
2222
import {MosaicInfo} from '../model/mosaic/MosaicInfo';
2323
import { MosaicNames } from '../model/mosaic/MosaicNames';
2424
import {MosaicProperties} from '../model/mosaic/MosaicProperties';
25+
import { MosaicPropertyIdEnum } from '../model/mosaic/MosaicPropertyIdEnum';
2526
import {NamespaceId} from '../model/namespace/NamespaceId';
2627
import {UInt64} from '../model/UInt64';
2728
import {Http} from './Http';
@@ -60,18 +61,19 @@ export class MosaicHttp extends Http implements MosaicRepository {
6061
return this.getNetworkTypeObservable().pipe(
6162
mergeMap((networkType) => observableFrom(
6263
this.mosaicRoutesApi.getMosaic(mosaicId.toHex())).pipe(map((mosaicInfoDTO) => {
63-
return new MosaicInfo(
64-
mosaicInfoDTO.meta.id,
65-
new MosaicId(mosaicInfoDTO.mosaic.mosaicId),
66-
new UInt64(mosaicInfoDTO.mosaic.supply),
67-
new UInt64(mosaicInfoDTO.mosaic.height),
68-
PublicAccount.createFromPublicKey(mosaicInfoDTO.mosaic.owner, networkType),
69-
mosaicInfoDTO.mosaic.revision,
70-
new MosaicProperties(
71-
new UInt64(mosaicInfoDTO.mosaic.properties[0].value),
72-
(new UInt64(mosaicInfoDTO.mosaic.properties[1].value)).compact(),
73-
),
74-
);
64+
return new MosaicInfo(
65+
mosaicInfoDTO.meta.id,
66+
new MosaicId(mosaicInfoDTO.mosaic.mosaicId),
67+
new UInt64(mosaicInfoDTO.mosaic.supply),
68+
new UInt64(mosaicInfoDTO.mosaic.height),
69+
PublicAccount.createFromPublicKey(mosaicInfoDTO.mosaic.owner, networkType),
70+
mosaicInfoDTO.mosaic.revision,
71+
new MosaicProperties(
72+
new UInt64(mosaicInfoDTO.mosaic.properties[MosaicPropertyIdEnum.MosaicFlags].value),
73+
(new UInt64(mosaicInfoDTO.mosaic.properties[MosaicPropertyIdEnum.Divisibility].value)).compact(),
74+
new UInt64(mosaicInfoDTO.mosaic.properties[MosaicPropertyIdEnum.Duration].value),
75+
),
76+
);
7577
}))));
7678
}
7779

@@ -96,8 +98,9 @@ export class MosaicHttp extends Http implements MosaicRepository {
9698
PublicAccount.createFromPublicKey(mosaicInfoDTO.mosaic.owner, networkType),
9799
mosaicInfoDTO.mosaic.revision,
98100
new MosaicProperties(
99-
new UInt64(mosaicInfoDTO.mosaic.properties[0].value),
100-
(new UInt64(mosaicInfoDTO.mosaic.properties[1].value)).compact(),
101+
new UInt64(mosaicInfoDTO.mosaic.properties[MosaicPropertyIdEnum.MosaicFlags].value),
102+
(new UInt64(mosaicInfoDTO.mosaic.properties[MosaicPropertyIdEnum.Divisibility].value)).compact(),
103+
new UInt64(mosaicInfoDTO.mosaic.properties[MosaicPropertyIdEnum.Duration].value),
101104
),
102105
);
103106
});

src/infrastructure/transaction/CreateTransactionFromDTO.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {Id} from '../../model/Id';
2222
import {Mosaic} from '../../model/mosaic/Mosaic';
2323
import {MosaicId} from '../../model/mosaic/MosaicId';
2424
import {MosaicProperties} from '../../model/mosaic/MosaicProperties';
25+
import { MosaicPropertyIdEnum } from '../../model/mosaic/MosaicPropertyIdEnum';
2526
import {NamespaceId} from '../../model/namespace/NamespaceId';
2627
import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction';
2728
import {AccountPropertyModification} from '../../model/transaction/AccountPropertyModification';
@@ -159,10 +160,10 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
159160
transactionDTO.nonce,
160161
new MosaicId(transactionDTO.mosaicId),
161162
new MosaicProperties(
162-
new UInt64(transactionDTO.properties[0].value),
163-
(new UInt64(transactionDTO.properties[1].value)).compact(),
164-
transactionDTO.properties.length === 3 && transactionDTO.properties[2].value ?
165-
new UInt64(transactionDTO.properties[2].value) : undefined,
163+
new UInt64(transactionDTO.properties[MosaicPropertyIdEnum.MosaicFlags].value),
164+
(new UInt64(transactionDTO.properties[MosaicPropertyIdEnum.Divisibility].value)).compact(),
165+
transactionDTO.properties.length === 3 && transactionDTO.properties[MosaicPropertyIdEnum.Duration].value ?
166+
new UInt64(transactionDTO.properties[MosaicPropertyIdEnum.Duration].value) : undefined,
166167
),
167168
transactionDTO.signature,
168169
transactionDTO.signer ? PublicAccount.createFromPublicKey(transactionDTO.signer,

src/model/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export * from '../service/MosaicAmountView';
5555
export * from './mosaic/NetworkCurrencyMosaic';
5656
export * from './mosaic/NetworkHarvestMosaic';
5757
export * from './mosaic/MosaicNames';
58+
export * from './mosaic/MosaicPropertyIdEnum';
5859

5960
// Namespace
6061
export * from '../service/Namespace';

src/model/mosaic/MosaicProperties.ts

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

1717
import {UInt64} from '../UInt64';
18+
import { MosaicPropertyIdEnum } from './MosaicPropertyIdEnum';
1819

1920
/**
2021
* Mosaic properties model
@@ -83,13 +84,13 @@ export class MosaicProperties {
8384
*/
8485
toDTO() {
8586
const dto = [
86-
{id: 0, value: UInt64.fromUint((this.supplyMutable ? 1 : 0) +
87+
{id: MosaicPropertyIdEnum.MosaicFlags, value: UInt64.fromUint((this.supplyMutable ? 1 : 0) +
8788
(this.transferable ? 2 : 0)).toDTO()},
88-
{id: 1, value: UInt64.fromUint(this.divisibility).toDTO()},
89+
{id: MosaicPropertyIdEnum.Divisibility, value: UInt64.fromUint(this.divisibility).toDTO()},
8990
];
9091

9192
if (this.duration !== undefined) {
92-
dto.push({id: 2, value: this.duration.toDTO()});
93+
dto.push({id: MosaicPropertyIdEnum.Duration, value: this.duration.toDTO()});
9394
}
9495

9596
return dto;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
/**
18+
* The mosaic property id means:
19+
* 0 - MosaicFlags
20+
* 1 - Divisibility
21+
* 2 - Duration
22+
*/
23+
export enum MosaicPropertyIdEnum {
24+
MosaicFlags = 0,
25+
Divisibility = 1,
26+
Duration = 2,
27+
}

0 commit comments

Comments
 (0)