Skip to content

Commit ab037fb

Browse files
committed
Added #147 dragon features and DTOs
1 parent 947ea28 commit ab037fb

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

src/infrastructure/ChainHttps.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2018 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+
import {ChainRoutesApi} from 'nem2-library';
18+
import {from as observableFrom, Observable} from 'rxjs';
19+
import {map} from 'rxjs/operators';
20+
import {BlockchainScore} from '../model/blockchain/BlockchainScore';
21+
import {UInt64} from '../model/UInt64';
22+
import { ChainRepository } from './ChainRepository';
23+
import {Http} from './Http';
24+
25+
/**
26+
* Chian http repository.
27+
*
28+
* @since 1.0
29+
*/
30+
export class ChainHttp extends Http implements ChainRepository {
31+
/**
32+
* @internal
33+
* Nem2 Library chain routes api
34+
*/
35+
private chainRoutesApi: ChainRoutesApi;
36+
37+
/**
38+
* Constructor
39+
* @param url
40+
*/
41+
constructor(url: string) {
42+
super(url);
43+
this.chainRoutesApi = new ChainRoutesApi(this.apiClient);
44+
}
45+
46+
/**
47+
* Gets current blockchain height
48+
* @returns Observable<UInt64>
49+
*/
50+
public getBlockchainHeight(): Observable<UInt64> {
51+
return observableFrom(this.chainRoutesApi.getBlockchainHeight()).pipe(map((heightDTO) => {
52+
return new UInt64(heightDTO.height);
53+
}));
54+
}
55+
56+
/**
57+
* Gets current blockchain score
58+
* @returns Observable<BlockchainScore>
59+
*/
60+
public getBlockchainScore(): Observable<BlockchainScore> {
61+
return observableFrom(this.chainRoutesApi.getBlockchainScore()).pipe(map((blockchainScoreDTO) => {
62+
return new BlockchainScore(
63+
new UInt64(blockchainScoreDTO.scoreLow),
64+
new UInt64(blockchainScoreDTO.scoreHigh),
65+
);
66+
}));
67+
}
68+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
import {DiagnosticRoutesApi} from 'nem2-library';
18+
import {from as observableFrom, Observable} from 'rxjs';
19+
import {map} from 'rxjs/operators';
20+
import {BlockchainStorageInfo} from '../model/blockchain/BlockchainStorageInfo';
21+
import { ServerInfo } from '../model/diagnostic/ServerInfo';
22+
import {DiagnosticRepository} from './DiagnosticRepository';
23+
import {Http} from './Http';
24+
25+
/**
26+
* Diagnostic http repository.
27+
*
28+
* @since 1.0
29+
*/
30+
export class DiagnosticHttp extends Http implements DiagnosticRepository {
31+
/**
32+
* @internal
33+
* Nem2 Library diagnostic routes api
34+
*/
35+
private diagnosticRoutesApi: DiagnosticRoutesApi;
36+
37+
/**
38+
* Constructor
39+
* @param url
40+
*/
41+
constructor(url: string) {
42+
super(url);
43+
this.diagnosticRoutesApi = new DiagnosticRoutesApi(this.apiClient);
44+
}
45+
46+
/**
47+
* Gets blockchain storage info.
48+
* @returns Observable<BlockchainStorageInfo>
49+
*/
50+
public getDiagnosticStorage(): Observable<BlockchainStorageInfo> {
51+
return observableFrom(
52+
this.diagnosticRoutesApi.getDiagnosticStorage()).pipe(map((blockchainStorageInfoDTO) => {
53+
return new BlockchainStorageInfo(
54+
blockchainStorageInfoDTO.numBlocks,
55+
blockchainStorageInfoDTO.numTransactions,
56+
blockchainStorageInfoDTO.numAccounts,
57+
);
58+
}));
59+
}
60+
61+
/**
62+
* Gets blockchain server info.
63+
* @returns Observable<Server>
64+
*/
65+
public getServerInfo(): Observable<ServerInfo> {
66+
return observableFrom(
67+
this.diagnosticRoutesApi.getServerInfo()).pipe(map((serverDTO) => {
68+
return new ServerInfo(serverDTO.serverInfo.restVersion,
69+
serverDTO.serverInfo.sdkVersion);
70+
}));
71+
}
72+
}

0 commit comments

Comments
 (0)