Skip to content

Commit 8166ba9

Browse files
committed
[#348, #319] Added getNetworkName
1 parent c1707f9 commit 8166ba9

File tree

7 files changed

+63
-3
lines changed

7 files changed

+63
-3
lines changed

src/infrastructure/NetworkHttp.ts

Lines changed: 21 additions & 2 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,13 +46,14 @@ 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(
@@ -58,4 +63,18 @@ export class NetworkHttp extends Http implements NetworkRepository {
5863
catchError((error) => throwError(this.errorHandling(error)))),
5964
);
6065
}
66+
67+
/**
68+
* Get current network type name and description
69+
*
70+
* @return current network type name and description
71+
*/
72+
public getNetworkName(): Observable<NetworkName> {
73+
return observableFrom(this.networkRouteApi.getNetworkType()).pipe(
74+
map((response: { response: ClientResponse; body: NetworkTypeDTO; }) => {
75+
return new NetworkName(response.body.name, response.body.description);
76+
}),
77+
catchError((error) => throwError(this.errorHandling(error))),
78+
);
79+
}
6180
}

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => {
130130
case TransactionType.MOSAIC_DEFINITION:
131131
return {
132132
nonce: (transaction as MosaicDefinitionTransaction).nonce,
133-
mosaicId: (transaction as MosaicDefinitionTransaction).mosaicId.toHex(),
133+
id: (transaction as MosaicDefinitionTransaction).mosaicId.toHex(),
134134
flags: (transaction as MosaicDefinitionTransaction).flags.getValue(),
135135
divisibility: (transaction as MosaicDefinitionTransaction).divisibility,
136136
duration: (transaction as MosaicDefinitionTransaction).duration.toString(),
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') {

test/core/utils/TransactionMapping.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () =>
837837
NetworkType.MIJIN_TEST,
838838
);
839839

840+
console.log(mosaicDefinitionTransaction.toJSON());
840841
const transaction =
841842
TransactionMapping.createFromDTO(mosaicDefinitionTransaction.toJSON()) as MosaicDefinitionTransaction;
842843

0 commit comments

Comments
 (0)