Skip to content

Commit bdcf5d2

Browse files
author
Greg S
committed
PR#63: updated nonce field to hold Uint8Array with 4 bytes ; added MosaicNonce type ; fixed Listener error handling
1 parent 3707d3e commit bdcf5d2

File tree

10 files changed

+75
-26
lines changed

10 files changed

+75
-26
lines changed

e2e/infrastructure/TransactionHttp.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ describe('TransactionHttp', () => {
151151
it('standalone', (done) => {
152152
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
153153
Deadline.create(),
154-
UInt64.fromUint(1),
154+
new Uint8Array([0xE6, 0xDE, 0x84, 0xB8]),
155155
UInt64.fromUint(1),
156156
MosaicProperties.create({
157157
supplyMutable: true,
@@ -170,7 +170,7 @@ describe('TransactionHttp', () => {
170170
it('aggregate', (done) => {
171171
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
172172
Deadline.create(),
173-
UInt64.fromUint(1),
173+
new Uint8Array([0xE6, 0xDE, 0x84, 0xB8]),
174174
UInt64.fromUint(1),
175175
MosaicProperties.create({
176176
supplyMutable: true,

e2e/infrastructure/transaction/CreateTransactionFromDTO.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ describe('CreateTransactionFromDTO', () => {
413413
3248159581,
414414
740240531,
415415
],
416-
mosaicNonce: [
416+
nonce: [
417417
1,
418418
0,
419419
],
@@ -501,7 +501,7 @@ describe('CreateTransactionFromDTO', () => {
501501
3248159581,
502502
740240531,
503503
],
504-
mosaicNonce: [
504+
nonce: [
505505
1,
506506
0,
507507
],

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nem2-sdk",
3-
"version": "0.10.1",
3+
"version": "0.10.2",
44
"description": "Reactive Nem2 sdk for typescript and javascript",
55
"scripts": {
66
"pretest": "npm run build",
@@ -53,7 +53,7 @@
5353
"@types/crypto-js": "^3.1.43",
5454
"crypto-js": "^3.1.9-1",
5555
"js-joda": "^1.6.2",
56-
"nem2-library": "^0.9.5",
56+
"nem2-library": ">=0.9.5",
5757
"request": "^2.83.0",
5858
"request-promise-native": "^1.0.5",
5959
"rxjs": "^6.2.1",

src/infrastructure/transaction/CreateTransactionFromDTO.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr
144144
extractTransactionVersion(transactionDTO.version),
145145
Deadline.createFromDTO(transactionDTO.deadline),
146146
new UInt64(transactionDTO.fee),
147-
new UInt64(transactionDTO.mosaicNonce),
147+
transactionDTO.nonce,
148148
new MosaicId(transactionDTO.mosaicId),
149149
new MosaicProperties(
150150
new UInt64(transactionDTO.properties[0].value),

src/model/mosaic/MosaicNonce.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 nonce structure
19+
*
20+
* @since 1.0
21+
*/
22+
export class MosaicNonce {
23+
24+
/**
25+
* Mosaic id
26+
*/
27+
public readonly nonce: Uint8Array;
28+
29+
/**
30+
* Create MosaicId from mosaic and namespace string id (ex: nem:xem or domain.subdom.subdome:token)
31+
* or id in form of array number (ex: [3646934825, 3576016193])
32+
*
33+
* @param id
34+
*/
35+
constructor(nonce: Uint8Array) {
36+
if (nonce.length !== 4) {
37+
throw Error('Invalid byte size for nonce, should be 4 bytes but received ' + nonce.length);
38+
}
39+
40+
this.nonce = nonce;
41+
}
42+
43+
/**
44+
* @internal
45+
* @returns {[number,number]}
46+
*/
47+
public toDTO(): Uint8Array {
48+
return this.nonce;
49+
}
50+
}

src/model/transaction/MosaicDefinitionTransaction.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { MosaicCreationTransaction as MosaicDefinitionTransactionLibrary, mosaic
1818
import { PublicAccount } from '../account/PublicAccount';
1919
import { NetworkType } from '../blockchain/NetworkType';
2020
import { MosaicId } from '../mosaic/MosaicId';
21+
import { MosaicNonce } from '../mosaic/MosaicNonce';
2122
import { MosaicProperties } from '../mosaic/MosaicProperties';
2223
import { NamespaceId } from '../namespace/NamespaceId';
2324
import { UInt64 } from '../UInt64';
@@ -36,22 +37,22 @@ export class MosaicDefinitionTransaction extends Transaction {
3637
/**
3738
* Create a mosaic creation transaction object
3839
* @param deadline - The deadline to include the transaction.
39-
* @param mosaicName - The mosaic name ex: xem.
40-
* @param namespaceName - The namespace where mosaic will be included ex: nem.
40+
* @param nonce - The mosaic nonce ex: [0xE6, 0xDE, 0x84, 0xB8].
41+
* @param mosaicId - The mosaic id ex: [481110499, 231112638].
4142
* @param mosaicProperties - The mosaic properties.
4243
* @param networkType - The network type.
4344
* @returns {MosaicDefinitionTransaction}
4445
*/
4546
public static create(deadline: Deadline,
46-
mosaicNonce: UInt64,
47+
nonce: Uint8Array,
4748
mosaicId: UInt64,
4849
mosaicProperties: MosaicProperties,
4950
networkType: NetworkType): MosaicDefinitionTransaction {
5051
return new MosaicDefinitionTransaction(networkType,
5152
TransactionVersion.MOSAIC_DEFINITION,
5253
deadline,
5354
new UInt64([0, 0]),
54-
mosaicNonce,
55+
new MosaicNonce(nonce),
5556
new MosaicId(mosaicId.toDTO()),
5657
mosaicProperties,
5758
);
@@ -76,7 +77,7 @@ export class MosaicDefinitionTransaction extends Transaction {
7677
/**
7778
* The mosaic nonce.
7879
*/
79-
public readonly mosaicNonce: UInt64,
80+
public readonly nonce: MosaicNonce,
8081
/**
8182
* The mosaic id.
8283
*/
@@ -102,7 +103,7 @@ export class MosaicDefinitionTransaction extends Transaction {
102103
.addVersion(this.versionToDTO())
103104
.addDivisibility(this.mosaicProperties.divisibility)
104105
.addDuration(this.mosaicProperties.duration.toDTO())
105-
.addNonce(this.mosaicNonce.toDTO())
106+
.addNonce(this.nonce.toDTO())
106107
.addMosaicId(this.mosaicId.id.toDTO());
107108

108109
if (this.mosaicProperties.supplyMutable === true) {

src/model/transaction/RegisterNamespaceTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class RegisterNamespaceTransaction extends Transaction {
7474
parentId = parentNamespace;
7575
}
7676
return new RegisterNamespaceTransaction(networkType,
77-
2,
77+
TransactionVersion.REGISTER_NAMESPACE,
7878
deadline,
7979
new UInt64([0, 0]),
8080
NamespaceType.SubNamespace,

test/infrastructure/Listener.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ describe('Listener', () => {
4040
throw new Error('This should not be called when expecting error');
4141
})
4242
.catch((error) => {
43-
expect(error.toString()).to.be.equal("Error: getaddrinfo ENOTFOUND notcorrecturl notcorrecturl:0000");
44-
})
43+
expect(error.message.toString()).to.be.equal("getaddrinfo ENOTFOUND notcorrecturl notcorrecturl:0000");
44+
});
4545
});
4646
});
4747
});

test/model/transaction/AggregateTransaction.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ describe('AggregateTransaction', () => {
9898
it('should createComplete an AggregateTransaction object with MosaicDefinitionTransaction', () => {
9999
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
100100
Deadline.create(),
101-
UInt64.fromUint(1), // nonce
101+
new Uint8Array([0xE6, 0xDE, 0x84, 0xB8]), // nonce
102102
UInt64.fromUint(1), // ID
103103
MosaicProperties.create({
104104
supplyMutable: true,
@@ -119,12 +119,12 @@ describe('AggregateTransaction', () => {
119119

120120
const signedTransaction = aggregateTransaction.signWith(account);
121121

122-
expect(signedTransaction.payload.substring(0, 8)).to.be.equal('B4000000');
123-
expect(signedTransaction.payload.substring(240, 256)).to.be.equal('3800000038000000');
122+
expect(signedTransaction.payload.substring(0, 8)).to.be.equal('BC000000');
123+
expect(signedTransaction.payload.substring(240, 256)).to.be.equal('4000000040000000');
124124
expect(signedTransaction.payload.substring(
125125
320,
126126
signedTransaction.payload.length,
127-
)).to.be.equal('03904D41010000000000000001070302E8030000');
127+
)).to.be.equal('03904D41E6DE84B8010000000000000001070302E803000000000000');
128128
});
129129

130130
it('should createComplete an AggregateTransaction object with MosaicSupplyChangeTransaction', () => {

test/model/transaction/MosaicDefinitionTransaction.spec.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('MosaicDefinitionTransaction', () => {
3434
it('should createComplete an MosaicDefinitionTransaction object and sign it with flags 7', () => {
3535
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
3636
Deadline.create(),
37-
UInt64.fromUint(1),
37+
new Uint8Array([0xE6, 0xDE, 0x84, 0xB8]),
3838
UInt64.fromUint(1),
3939
MosaicProperties.create({
4040
supplyMutable: true,
@@ -46,7 +46,6 @@ describe('MosaicDefinitionTransaction', () => {
4646
NetworkType.MIJIN_TEST,
4747
);
4848

49-
expect(mosaicDefinitionTransaction.mosaicNonce.compact()).to.be.equal(1);
5049
expect(mosaicDefinitionTransaction.mosaicProperties.duration.lower).to.be.equal(1000);
5150
expect(mosaicDefinitionTransaction.mosaicProperties.duration.higher).to.be.equal(0);
5251
expect(mosaicDefinitionTransaction.mosaicProperties.divisibility).to.be.equal(3);
@@ -59,7 +58,7 @@ describe('MosaicDefinitionTransaction', () => {
5958
expect(signedTransaction.payload.substring(
6059
240,
6160
signedTransaction.payload.length,
62-
)).to.be.equal('010000000000000001070302E8030000');
61+
)).to.be.equal('E6DE84B8010000000000000001070302E803000000000000');
6362

6463
});
6564

@@ -68,7 +67,7 @@ describe('MosaicDefinitionTransaction', () => {
6867
const nonce = [0xE6, 0xDE, 0x84, 0xB8];
6968
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
7069
Deadline.create(),
71-
UInt64.fromUint(0xE6DE84B8),
70+
new Uint8Array(nonce),
7271
UInt64.fromUint(mosaicId(nonce, convert.hexToUint8(account.publicKey))),
7372
MosaicProperties.create({
7473
supplyMutable: false,
@@ -80,7 +79,6 @@ describe('MosaicDefinitionTransaction', () => {
8079
NetworkType.MIJIN_TEST,
8180
);
8281

83-
expect(mosaicDefinitionTransaction.mosaicNonce.compact()).to.be.equal(0xE6DE84B8);
8482
expect(mosaicDefinitionTransaction.mosaicProperties.duration.lower).to.be.equal(1000);
8583
expect(mosaicDefinitionTransaction.mosaicProperties.duration.higher).to.be.equal(0);
8684
expect(mosaicDefinitionTransaction.mosaicProperties.divisibility).to.be.equal(3);
@@ -93,7 +91,7 @@ describe('MosaicDefinitionTransaction', () => {
9391
expect(signedTransaction.payload.substring(
9492
240,
9593
signedTransaction.payload.length,
96-
)).to.be.equal('000000000000000001000302E8030000');
94+
)).to.be.equal('E6DE84B8000000000000000001000302E803000000000000');
9795

9896
});
9997
});

0 commit comments

Comments
 (0)