Skip to content

Commit 5c2feaa

Browse files
authored
Merge pull request #354 from NEMStudios/task/g348_mosaic_constructor
Added GetNetworkName and other small fixes
2 parents c1707f9 + b45654d commit 5c2feaa

File tree

7 files changed

+179
-93
lines changed

7 files changed

+179
-93
lines changed

e2e/infrastructure/NetworkHttp.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,15 @@ describe('NetworkHttp', () => {
4040
});
4141
});
4242
});
43+
44+
describe('getNetworkName', () => {
45+
it('should return network name and description', (done) => {
46+
networkHttp.getNetworkName()
47+
.subscribe((networkName) => {
48+
expect(networkName.name.toLowerCase()).to.be.equal('mijintest');
49+
expect(networkName.description.toLowerCase()).to.be.equal('catapult development network');
50+
done();
51+
});
52+
});
53+
});
4354
});

src/infrastructure/NetworkHttp.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
import { ClientResponse } from 'http';
1818
import {from as observableFrom, Observable, throwError} from 'rxjs';
1919
import {catchError, map} from 'rxjs/operators';
20+
import { NetworkName } from '../model/blockchain/NetworkName';
2021
import {NetworkType} from '../model/blockchain/NetworkType';
2122
import { NodeInfo } from '../model/node/NodeInfo';
23+
import { NetworkRoutesApi } from './api/apis';
2224
import {Http} from './Http';
25+
import { NetworkTypeDTO } from './model/networkTypeDTO';
2326
import {NetworkRepository} from './NetworkRepository';
2427
import { NodeHttp } from './NodeHttp';
2528

@@ -34,6 +37,7 @@ export class NetworkHttp extends Http implements NetworkRepository {
3437
* Nem2 Library account routes api
3538
*/
3639
private nodeHttp: NodeHttp;
40+
private networkRouteApi: NetworkRoutesApi;
3741

3842
/**
3943
* Constructor
@@ -42,20 +46,31 @@ export class NetworkHttp extends Http implements NetworkRepository {
4246
constructor(url: string) {
4347
super();
4448
this.nodeHttp = new NodeHttp(url);
49+
this.networkRouteApi = new NetworkRoutesApi(url);
4550

4651
}
4752

4853
/**
49-
* Get current network type.
54+
* Get current network identifier.
5055
*
51-
* @return network type enum.
56+
* @return network identifier.
5257
*/
5358
public getNetworkType(): Observable<NetworkType> {
5459
return observableFrom(this.nodeHttp.getNodeInfo()).pipe(
55-
map(((nodeInfo: NodeInfo) => {
56-
return nodeInfo.networkIdentifier;
57-
}),
60+
map(((nodeInfo: NodeInfo) => nodeInfo.networkIdentifier),
5861
catchError((error) => throwError(this.errorHandling(error)))),
5962
);
6063
}
64+
65+
/**
66+
* Get current network type name and description
67+
*
68+
* @return current network type name and description
69+
*/
70+
public getNetworkName(): Observable<NetworkName> {
71+
return observableFrom(this.networkRouteApi.getNetworkType()).pipe(
72+
map((({body}) => new NetworkName(body.name, body.description))),
73+
catchError((error) => throwError(this.errorHandling(error))),
74+
);
75+
}
6176
}

src/infrastructure/NetworkRepository.ts

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

1717
import {Observable} from 'rxjs';
18+
import { NetworkName } from '../model/blockchain/NetworkName';
1819
import {NetworkType} from '../model/blockchain/NetworkType';
1920

2021
/**
@@ -29,4 +30,11 @@ export interface NetworkRepository {
2930
* @return network type enum.
3031
*/
3132
getNetworkType(): Observable<NetworkType>;
33+
34+
/**
35+
* Get current network type name and description
36+
*
37+
* @return current network type name and description
38+
*/
39+
getNetworkName(): Observable<NetworkName>;
3240
}

src/infrastructure/transaction/SerializeTransactionToJSON.ts

Lines changed: 108 additions & 88 deletions
Large diffs are not rendered by default.

src/model/blockchain/NetworkName.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 block merkle proof info
19+
*/
20+
export class NetworkName {
21+
22+
/**
23+
* @param name - Network name
24+
* @param description - Network description
25+
*/
26+
constructor(public readonly name: string, public readonly description: string) {
27+
}
28+
}

src/model/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export * from './blockchain/BlockInfo';
3535
export * from './blockchain/NetworkType';
3636
export * from './blockchain/MerklePathItem';
3737
export * from './blockchain/MerkleProofInfo';
38+
export * from './blockchain/NetworkName';
3839

3940
// Diagnostic
4041
export * from './diagnostic/ServerInfo';

src/model/mosaic/MosaicId.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ export class MosaicId {
5050
* @param id
5151
*/
5252
constructor(id: string | number[]) {
53+
if (id === undefined) {
54+
throw new Error('MosaicId undefined');
55+
}
5356
if (id instanceof Array) {
5457
this.id = new Id(id);
5558
} else if (typeof id === 'string') {

0 commit comments

Comments
 (0)