Skip to content

Commit fa035d8

Browse files
authored
Merge pull request #467 from NEMStudios/task/g466_mosaic_nonce_uint32
Changed mosaicNonce to uint32 in dto
2 parents 67e1a50 + 22821fb commit fa035d8

File tree

8 files changed

+21
-15
lines changed

8 files changed

+21
-15
lines changed

src/infrastructure/transaction/CreateTransactionFromDTO.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {EmptyMessage, PlainMessage} from '../../model/message/PlainMessage';
2525
import {Mosaic} from '../../model/mosaic/Mosaic';
2626
import {MosaicFlags} from '../../model/mosaic/MosaicFlags';
2727
import {MosaicId} from '../../model/mosaic/MosaicId';
28+
import { MosaicNonce } from '../../model/mosaic/MosaicNonce';
2829
import {NamespaceId} from '../../model/namespace/NamespaceId';
2930
import {AccountAddressRestrictionTransaction} from '../../model/transaction/AccountAddressRestrictionTransaction';
3031
import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction';
@@ -54,6 +55,7 @@ import {TransactionInfo} from '../../model/transaction/TransactionInfo';
5455
import {TransactionType} from '../../model/transaction/TransactionType';
5556
import {TransferTransaction} from '../../model/transaction/TransferTransaction';
5657
import {UInt64} from '../../model/UInt64';
58+
5759
// tslint:disable: no-use-before-declare
5860
/**
5961
* @internal
@@ -159,7 +161,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
159161
transactionDTO.version,
160162
Deadline.createFromDTO(transactionDTO.deadline),
161163
UInt64.fromNumericString(transactionDTO.maxFee || '0'),
162-
transactionDTO.nonce,
164+
MosaicNonce.createFromHex(transactionDTO.nonce.toString(16)),
163165
new MosaicId(transactionDTO.id),
164166
new MosaicFlags(transactionDTO.flags),
165167
transactionDTO.divisibility,

src/infrastructure/transaction/NamespaceMosaicIdGenerator.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ import { IdGenerator } from '../../core/format';
1919

2020
export class NamespaceMosaicIdGenerator {
2121
/**
22+
* @param {Uint8Array} nonce Mosaic nonce
23+
* @param {Uint8Array} ownerPublicId Public key
2224
* @returns mosaic Id
2325
*/
24-
public static mosaicId = (nonce, ownerPublicId) => {
26+
public static mosaicId = (nonce: Uint8Array, ownerPublicId: Uint8Array) => {
2527
return IdGenerator.generateMosaicId(nonce, ownerPublicId);
2628
}
2729

@@ -36,7 +38,7 @@ export class NamespaceMosaicIdGenerator {
3638
* @param {string} namespaceName - The namespace name
3739
* @returns sub namespace id
3840
*/
39-
public static namespaceId = (namespaceName) => {
41+
public static namespaceId = (namespaceName: string) => {
4042
const path = IdGenerator.generateNamespacePath(namespaceName);
4143
return path.length ? IdGenerator.generateNamespacePath(namespaceName)[path.length - 1] : [];
4244
}
@@ -55,7 +57,7 @@ export class NamespaceMosaicIdGenerator {
5557
* @param {string} namespaceName - The namespace name
5658
* @returns sub namespace id
5759
*/
58-
public static subnamespaceNamespaceId = (parentNamespaceName, namespaceName) => {
60+
public static subnamespaceNamespaceId = (parentNamespaceName: string, namespaceName: string) => {
5961
const path = IdGenerator.generateNamespacePath(`${parentNamespaceName}.${namespaceName}`);
6062
return path[path.length - 1];
6163
}

src/infrastructure/transaction/SerializeTransactionToJSON.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => {
139139
case TransactionType.MOSAIC_DEFINITION:
140140
const mosaicDefinitionTx = transaction as MosaicDefinitionTransaction;
141141
return {
142-
nonce: mosaicDefinitionTx.nonce,
142+
nonce: mosaicDefinitionTx.nonce.toDTO(),
143143
id: mosaicDefinitionTx.mosaicId.toHex(),
144144
flags: mosaicDefinitionTx.flags.getValue(),
145145
divisibility: mosaicDefinitionTx.divisibility,

src/model/mosaic/MosaicInfo.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ import { MosaicId } from './MosaicId';
2525
export class MosaicInfo {
2626

2727
/**
28-
* @param active
29-
* @param index
30-
* @param nonce
28+
* @param id
3129
* @param supply
3230
* @param height
3331
* @param owner
34-
* @param properties
32+
* @param revision
33+
* @param flags
34+
* @param divisibility
35+
* @param duration
3536
*/
3637
constructor(
3738
/**

src/model/mosaic/MosaicNonce.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export class MosaicNonce {
7171
* @internal
7272
* @returns {[number,number,number,number]}
7373
*/
74-
public toDTO(): Uint8Array {
75-
return this.nonce;
74+
public toDTO(): number {
75+
return (this.nonce[0] + (this.nonce[1] << 8) + (this.nonce[2] << 16) + (this.nonce[3] << 24)) >>> 0;
7676
}
7777

7878
/**

src/model/transaction/MosaicDefinitionTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export class MosaicDefinitionTransaction extends Transaction {
178178
* @memberof MosaicDefinitionTransaction
179179
*/
180180
public getMosaicNonceIntValue(): number {
181-
return GeneratorUtils.readUint32At(this.nonce.toDTO(), 0);
181+
return this.nonce.toDTO();
182182
}
183183

184184
/**

test/infrastructure/transaction/CreateTransactionFromDTO.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ describe('CreateTransactionFromDTO', () => {
347347
deadline: '1',
348348
maxFee: '0',
349349
id: '85BBEA6CC462B244',
350-
nonce: '1',
350+
nonce: 1177824765,
351351
flags: 7,
352352
diversibility: 6,
353353
duration: '1000',
@@ -398,7 +398,7 @@ describe('CreateTransactionFromDTO', () => {
398398
},
399399
transaction: {
400400
id: '85BBEA6CC462B244',
401-
nonce: '1',
401+
nonce: 1177824765,
402402
flags: 7,
403403
divisibility: 6,
404404
duration: '1000',

test/model/mosaic/MosaicNonce.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('MosaicNonce', () => {
2424
it('should be created from Uint8Array', () => {
2525
const nonce = new MosaicNonce(new Uint8Array([0x0, 0x0, 0x0, 0x0]));
2626
deepEqual(nonce.nonce, new Uint8Array([0x0, 0x0, 0x0, 0x0]));
27-
deepEqual(nonce.toDTO(), new Uint8Array([0x0, 0x0, 0x0, 0x0]));
27+
deepEqual(nonce.toDTO(), 0);
2828
});
2929

3030
it('should create random nonce', () => {
@@ -44,6 +44,7 @@ describe('MosaicNonce', () => {
4444
const nonce = MosaicNonce.createFromHex('00000000');
4545
expect(nonce.nonce).to.not.be.null;
4646
deepEqual(nonce.nonce, new Uint8Array([0x0, 0x0, 0x0, 0x0]));
47+
deepEqual(nonce.toDTO(), 0);
4748
});
4849

4950
describe('toHex()', () => {

0 commit comments

Comments
 (0)