Skip to content

Commit 282937a

Browse files
author
Grégory Saive
authored
Merge pull request #43 from rg911/master
Issue #36, Error handling on Uint64.fromUnit with negative value.
2 parents 5d2a35d + 4d86a57 commit 282937a

File tree

6 files changed

+31
-11
lines changed

6 files changed

+31
-11
lines changed

src/infrastructure/Listener.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export class Listener {
201201
share(),
202202
filter((_) => _.channelName === ListenerChannelName.block),
203203
filter((_) => _.message instanceof BlockInfo),
204-
map((_) => _.message as BlockInfo),);
204+
map((_) => _.message as BlockInfo));
205205
}
206206

207207
/**
@@ -218,7 +218,7 @@ export class Listener {
218218
filter((_) => _.channelName === ListenerChannelName.confirmedAdded),
219219
filter((_) => _.message instanceof Transaction),
220220
map((_) => _.message as Transaction),
221-
filter((_) => this.transactionFromAddress(_, address)),);
221+
filter((_) => this.transactionFromAddress(_, address)));
222222
}
223223

224224
/**
@@ -235,7 +235,7 @@ export class Listener {
235235
filter((_) => _.channelName === ListenerChannelName.unconfirmedAdded),
236236
filter((_) => _.message instanceof Transaction),
237237
map((_) => _.message as Transaction),
238-
filter((_) => this.transactionFromAddress(_, address)),);
238+
filter((_) => this.transactionFromAddress(_, address)));
239239
}
240240

241241
/**
@@ -251,7 +251,7 @@ export class Listener {
251251
return this.messageSubject.asObservable().pipe(
252252
filter((_) => _.channelName === ListenerChannelName.unconfirmedRemoved),
253253
filter((_) => typeof _.message === 'string'),
254-
map((_) => _.message as string),);
254+
map((_) => _.message as string));
255255
}
256256

257257
/**
@@ -268,7 +268,7 @@ export class Listener {
268268
filter((_) => _.channelName === ListenerChannelName.aggregateBondedAdded),
269269
filter((_) => _.message instanceof AggregateTransaction),
270270
map((_) => _.message as AggregateTransaction),
271-
filter((_) => this.transactionFromAddress(_, address)),);
271+
filter((_) => this.transactionFromAddress(_, address)));
272272
}
273273

274274
/**
@@ -284,7 +284,7 @@ export class Listener {
284284
return this.messageSubject.asObservable().pipe(
285285
filter((_) => _.channelName === ListenerChannelName.aggregateBondedRemoved),
286286
filter((_) => typeof _.message === 'string'),
287-
map((_) => _.message as string),);
287+
map((_) => _.message as string));
288288
}
289289

290290
/**
@@ -300,7 +300,7 @@ export class Listener {
300300
return this.messageSubject.asObservable().pipe(
301301
filter((_) => _.channelName === ListenerChannelName.status),
302302
filter((_) => _.message instanceof TransactionStatusError),
303-
map((_) => _.message as TransactionStatusError),);
303+
map((_) => _.message as TransactionStatusError));
304304
}
305305

306306
/**
@@ -316,7 +316,7 @@ export class Listener {
316316
return this.messageSubject.asObservable().pipe(
317317
filter((_) => _.channelName === ListenerChannelName.cosignature),
318318
filter((_) => _.message instanceof CosignatureSignedTransaction),
319-
map((_) => _.message as CosignatureSignedTransaction),);
319+
map((_) => _.message as CosignatureSignedTransaction));
320320
}
321321

322322
/**
@@ -332,6 +332,18 @@ export class Listener {
332332
this.webSocket.send(JSON.stringify(subscriptionMessage));
333333
}
334334

335+
/**
336+
* @internal
337+
* @param channel - Channel to unsubscribe
338+
*/
339+
private unsubscribeTo(channel: string) {
340+
const unsubscribeMessage = {
341+
uid: this.uid,
342+
unsubscribe: channel,
343+
};
344+
this.webSocket.send(JSON.stringify(unsubscribeMessage));
345+
}
346+
335347
/**
336348
* @internal
337349
* Filters if a transaction has been initiated or signed by an address

src/model/UInt64.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export class UInt64 {
3737
* @returns {UInt64}
3838
*/
3939
public static fromUint(value: number): UInt64 {
40+
if (value < 0) {
41+
throw new Error('Unsigned integer cannot be negative');
42+
}
4043
return new UInt64(uint64.fromUint(value));
4144
}
4245

src/model/mosaic/Mosaic.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export class Mosaic {
4141

4242
}
4343

44-
4544
/**
4645
* @internal
4746
* @returns {{amount: number[], id: number[]}}

src/model/mosaic/MosaicProperties.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class MosaicProperties {
6060
* The duration in blocks a mosaic will be available.
6161
* After the duration finishes mosaic is inactive and can be renewed.
6262
*/
63-
public readonly duration: UInt64,) {
63+
public readonly duration: UInt64) {
6464
let binaryFlags = '00' + (flags.lower >>> 0).toString(2);
6565
binaryFlags = binaryFlags.substr(binaryFlags.length - 3, 3);
6666
this.supplyMutable = binaryFlags[2] === '1';

test/model/UInt64.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ describe('Uint64', () => {
6464
expect(uint64Compact).to.be.equal(51110867862);
6565
});
6666

67+
it('should fromUnit throw exception with negative unit value', () => {
68+
expect(() => {
69+
UInt64.fromUint(-1);
70+
}).to.throw(Error, 'Unsigned integer cannot be negative');
71+
});
72+
6773
describe('equal', () => {
6874
it('should return true if the inside values are the same', () => {
6975
const value = new UInt64([12, 12]);

tslint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
}
4646
],
4747
"no-arg": true,
48-
"no-bitwise": true,
48+
"no-bitwise": false,
4949
"no-console": [
5050
true,
5151
"debug",

0 commit comments

Comments
 (0)