Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions e2e/infrastructure/NetworkHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,15 @@ describe('NetworkHttp', () => {
});
});
});

describe('getNetworkName', () => {
it('should return network name and description', (done) => {
networkHttp.getNetworkName()
.subscribe((networkName) => {
expect(networkName.name.toLowerCase()).to.be.equal('mijintest');
expect(networkName.description.toLowerCase()).to.be.equal('catapult development network');
done();
});
});
});
});
25 changes: 20 additions & 5 deletions src/infrastructure/NetworkHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
import { ClientResponse } from 'http';
import {from as observableFrom, Observable, throwError} from 'rxjs';
import {catchError, map} from 'rxjs/operators';
import { NetworkName } from '../model/blockchain/NetworkName';
import {NetworkType} from '../model/blockchain/NetworkType';
import { NodeInfo } from '../model/node/NodeInfo';
import { NetworkRoutesApi } from './api/apis';
import {Http} from './Http';
import { NetworkTypeDTO } from './model/networkTypeDTO';
import {NetworkRepository} from './NetworkRepository';
import { NodeHttp } from './NodeHttp';

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

/**
* Constructor
Expand All @@ -42,20 +46,31 @@ export class NetworkHttp extends Http implements NetworkRepository {
constructor(url: string) {
super();
this.nodeHttp = new NodeHttp(url);
this.networkRouteApi = new NetworkRoutesApi(url);

}

/**
* Get current network type.
* Get current network identifier.
*
* @return network type enum.
* @return network identifier.
*/
public getNetworkType(): Observable<NetworkType> {
return observableFrom(this.nodeHttp.getNodeInfo()).pipe(
map(((nodeInfo: NodeInfo) => {
return nodeInfo.networkIdentifier;
}),
map(((nodeInfo: NodeInfo) => nodeInfo.networkIdentifier),
catchError((error) => throwError(this.errorHandling(error)))),
);
}

/**
* Get current network type name and description
*
* @return current network type name and description
*/
public getNetworkName(): Observable<NetworkName> {
return observableFrom(this.networkRouteApi.getNetworkType()).pipe(
map((({body}) => new NetworkName(body.name, body.description))),
catchError((error) => throwError(this.errorHandling(error))),
);
}
}
8 changes: 8 additions & 0 deletions src/infrastructure/NetworkRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import {Observable} from 'rxjs';
import { NetworkName } from '../model/blockchain/NetworkName';
import {NetworkType} from '../model/blockchain/NetworkType';

/**
Expand All @@ -29,4 +30,11 @@ export interface NetworkRepository {
* @return network type enum.
*/
getNetworkType(): Observable<NetworkType>;

/**
* Get current network type name and description
*
* @return current network type name and description
*/
getNetworkName(): Observable<NetworkName>;
}
196 changes: 108 additions & 88 deletions src/infrastructure/transaction/SerializeTransactionToJSON.ts

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions src/model/blockchain/NetworkName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2019 NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* The block merkle proof info
*/
export class NetworkName {

/**
* @param name - Network name
* @param description - Network description
*/
constructor(public readonly name: string, public readonly description: string) {
}
}
1 change: 1 addition & 0 deletions src/model/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export * from './blockchain/BlockInfo';
export * from './blockchain/NetworkType';
export * from './blockchain/MerklePathItem';
export * from './blockchain/MerkleProofInfo';
export * from './blockchain/NetworkName';

// Diagnostic
export * from './diagnostic/ServerInfo';
Expand Down
3 changes: 3 additions & 0 deletions src/model/mosaic/MosaicId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export class MosaicId {
* @param id
*/
constructor(id: string | number[]) {
if (id === undefined) {
throw new Error('MosaicId undefined');
}
if (id instanceof Array) {
this.id = new Id(id);
} else if (typeof id === 'string') {
Expand Down