Skip to content

Commit 33b3bef

Browse files
author
Grégory Saive
authored
Revert "Fixed compatibility issue on new rxjs version"
1 parent cfe1ea8 commit 33b3bef

21 files changed

+543
-587
lines changed

src/infrastructure/AccountHttp.ts

Lines changed: 90 additions & 130 deletions
Large diffs are not rendered by default.

src/infrastructure/BlockHttp.ts

Lines changed: 68 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { ClientResponse } from 'http';
18-
import {from as observableFrom, Observable, throwError} from 'rxjs';
19-
import {catchError, map, mergeMap} from 'rxjs/operators';
17+
import {from as observableFrom, Observable} from 'rxjs';
18+
import {map, mergeMap} from 'rxjs/operators';
2019
import {PublicAccount} from '../model/account/PublicAccount';
2120
import {BlockInfo} from '../model/blockchain/BlockInfo';
2221
import { MerklePathItem } from '../model/blockchain/MerklePathItem';
@@ -80,33 +79,29 @@ export class BlockHttp extends Http implements BlockRepository {
8079
* @returns Observable<BlockInfo>
8180
*/
8281
public getBlockByHeight(height: number): Observable<BlockInfo> {
83-
return observableFrom(this.blockRoutesApi.getBlockByHeight(height)).pipe(
84-
map((response: { response: ClientResponse; body: BlockInfoDTO; } ) => {
85-
const blockDTO = response.body;
86-
const networkType = parseInt((blockDTO.block.version as number).toString(16).substr(0, 2), 16);
87-
return new BlockInfo(
88-
blockDTO.meta.hash,
89-
blockDTO.meta.generationHash,
90-
new UInt64(blockDTO.meta.totalFee),
91-
blockDTO.meta.numTransactions,
92-
blockDTO.block.signature,
93-
PublicAccount.createFromPublicKey(blockDTO.block.signer, networkType),
94-
networkType,
95-
parseInt((blockDTO.block.version as number).toString(16).substr(2, 2), 16), // Tx version
96-
blockDTO.block.type,
97-
new UInt64(blockDTO.block.height),
98-
new UInt64(blockDTO.block.timestamp),
99-
new UInt64(blockDTO.block.difficulty),
100-
blockDTO.block.feeMultiplier,
101-
blockDTO.block.previousBlockHash,
102-
blockDTO.block.blockTransactionsHash,
103-
blockDTO.block.blockReceiptsHash,
104-
blockDTO.block.stateHash,
105-
extractBeneficiary(blockDTO, networkType),
106-
);
107-
}),
108-
catchError((error) => throwError(this.errorHandling(error))),
109-
);
82+
return observableFrom(this.blockRoutesApi.getBlockByHeight(height)).pipe(map((blockDTO: BlockInfoDTO) => {
83+
const networkType = parseInt((blockDTO.block.version as number).toString(16).substr(0, 2), 16);
84+
return new BlockInfo(
85+
blockDTO.meta.hash,
86+
blockDTO.meta.generationHash,
87+
new UInt64(blockDTO.meta.totalFee),
88+
blockDTO.meta.numTransactions,
89+
blockDTO.block.signature,
90+
PublicAccount.createFromPublicKey(blockDTO.block.signer, networkType),
91+
networkType,
92+
parseInt((blockDTO.block.version as number).toString(16).substr(2, 2), 16), // Tx version
93+
blockDTO.block.type,
94+
new UInt64(blockDTO.block.height),
95+
new UInt64(blockDTO.block.timestamp),
96+
new UInt64(blockDTO.block.difficulty),
97+
blockDTO.block.feeMultiplier,
98+
blockDTO.block.previousBlockHash,
99+
blockDTO.block.blockTransactionsHash,
100+
blockDTO.block.blockReceiptsHash,
101+
blockDTO.block.stateHash,
102+
extractBeneficiary(blockDTO, networkType),
103+
);
104+
}));
110105
}
111106

112107
/**
@@ -122,14 +117,11 @@ export class BlockHttp extends Http implements BlockRepository {
122117
this.queryParams(queryParams).pageSize,
123118
this.queryParams(queryParams).id,
124119
this.queryParams(queryParams).order))
125-
.pipe(map((response: { response: ClientResponse; body: TransactionInfoDTO[]; }) => {
126-
const transactionsDTO = response.body;
120+
.pipe(map((transactionsDTO: TransactionInfoDTO[]) => {
127121
return transactionsDTO.map((transactionDTO) => {
128122
return CreateTransactionFromDTO(transactionDTO);
129123
});
130-
}),
131-
catchError((error) => throwError(this.errorHandling(error))),
132-
);
124+
}));
133125
}
134126

135127
/**
@@ -140,35 +132,31 @@ export class BlockHttp extends Http implements BlockRepository {
140132
*/
141133
public getBlocksByHeightWithLimit(height: number, limit: LimitType = LimitType.N_25): Observable<BlockInfo[]> {
142134
return observableFrom(
143-
this.blockRoutesApi.getBlocksByHeightWithLimit(height, limit)).pipe(
144-
map((response: { response: ClientResponse; body: BlockInfoDTO[]; }) => {
145-
const blocksDTO = response.body;
146-
return blocksDTO.map((blockDTO) => {
147-
const networkType = parseInt((blockDTO.block.version as number).toString(16).substr(0, 2), 16);
148-
return new BlockInfo(
149-
blockDTO.meta.hash,
150-
blockDTO.meta.generationHash,
151-
new UInt64(blockDTO.meta.totalFee),
152-
blockDTO.meta.numTransactions,
153-
blockDTO.block.signature,
154-
PublicAccount.createFromPublicKey(blockDTO.block.signer, networkType),
155-
networkType,
156-
parseInt((blockDTO.block.version as number).toString(16).substr(2, 2), 16), // Tx version
157-
blockDTO.block.type,
158-
new UInt64(blockDTO.block.height),
159-
new UInt64(blockDTO.block.timestamp),
160-
new UInt64(blockDTO.block.difficulty),
161-
blockDTO.block.feeMultiplier,
162-
blockDTO.block.previousBlockHash,
163-
blockDTO.block.blockTransactionsHash,
164-
blockDTO.block.blockReceiptsHash,
165-
blockDTO.block.stateHash,
166-
extractBeneficiary(blockDTO, networkType),
167-
);
168-
});
169-
}),
170-
catchError((error) => throwError(this.errorHandling(error))),
171-
);
135+
this.blockRoutesApi.getBlocksByHeightWithLimit(height, limit)).pipe(map((blocksDTO: BlockInfoDTO[]) => {
136+
return blocksDTO.map((blockDTO) => {
137+
const networkType = parseInt((blockDTO.block.version as number).toString(16).substr(0, 2), 16);
138+
return new BlockInfo(
139+
blockDTO.meta.hash,
140+
blockDTO.meta.generationHash,
141+
new UInt64(blockDTO.meta.totalFee),
142+
blockDTO.meta.numTransactions,
143+
blockDTO.block.signature,
144+
PublicAccount.createFromPublicKey(blockDTO.block.signer, networkType),
145+
networkType,
146+
parseInt((blockDTO.block.version as number).toString(16).substr(2, 2), 16), // Tx version
147+
blockDTO.block.type,
148+
new UInt64(blockDTO.block.height),
149+
new UInt64(blockDTO.block.timestamp),
150+
new UInt64(blockDTO.block.difficulty),
151+
blockDTO.block.feeMultiplier,
152+
blockDTO.block.previousBlockHash,
153+
blockDTO.block.blockTransactionsHash,
154+
blockDTO.block.blockReceiptsHash,
155+
blockDTO.block.stateHash,
156+
extractBeneficiary(blockDTO, networkType),
157+
);
158+
});
159+
}));
172160
}
173161

174162
/**
@@ -183,18 +171,14 @@ export class BlockHttp extends Http implements BlockRepository {
183171
*/
184172
public getMerkleReceipts(height: number, hash: string): Observable<MerkleProofInfo> {
185173
return observableFrom(
186-
this.blockRoutesApi.getMerkleReceipts(height, hash)).pipe(
187-
map((response: { response: ClientResponse; body: MerkleProofInfoDTO; } ) => {
188-
const merkleProofReceipt = response.body;
189-
return new MerkleProofInfo(
190-
new MerkleProofInfoPayload(
191-
merkleProofReceipt.payload.merklePath!.map(
192-
(payload) => new MerklePathItem(payload.position, payload.hash))),
193-
merkleProofReceipt.type,
194-
);
195-
}),
196-
catchError((error) => throwError(this.errorHandling(error))),
197-
);
174+
this.blockRoutesApi.getMerkleReceipts(height, hash)).pipe(map((merkleProofReceipt: MerkleProofInfoDTO) => {
175+
return new MerkleProofInfo(
176+
new MerkleProofInfoPayload(
177+
merkleProofReceipt.payload.merklePath!.map(
178+
(payload) => new MerklePathItem(payload.position, payload.hash))),
179+
merkleProofReceipt.type,
180+
);
181+
}));
198182
}
199183

200184
/**
@@ -209,18 +193,13 @@ export class BlockHttp extends Http implements BlockRepository {
209193
*/
210194
public getMerkleTransaction(height: number, hash: string): Observable<MerkleProofInfo> {
211195
return observableFrom(
212-
this.blockRoutesApi.getMerkleReceipts(height, hash)).pipe(
213-
map((response: { response: ClientResponse; body: MerkleProofInfoDTO; } ) => {
214-
const merkleProofTransaction = response.body;
215-
return new MerkleProofInfo(
216-
new MerkleProofInfoPayload(
217-
merkleProofTransaction.payload.merklePath!.map((payload) =>
218-
new MerklePathItem(payload.position, payload.hash))),
219-
merkleProofTransaction.type,
220-
);
221-
}),
222-
catchError((error) => throwError(this.errorHandling(error))),
223-
);
196+
this.blockRoutesApi.getMerkleReceipts(height, hash)).pipe(map((merkleProofTransaction: MerkleProofInfoDTO) => {
197+
return new MerkleProofInfo(
198+
new MerkleProofInfoPayload(
199+
merkleProofTransaction.payload.merklePath!.map((payload) => new MerklePathItem(payload.position, payload.hash))),
200+
merkleProofTransaction.type,
201+
);
202+
}));
224203
}
225204

226205
/**
@@ -233,11 +212,9 @@ export class BlockHttp extends Http implements BlockRepository {
233212
return this.getNetworkTypeObservable().pipe(
234213
mergeMap((networkType) => observableFrom(
235214
this.blockRoutesApi.getBlockReceipts(height)).pipe(
236-
map((response: { response: ClientResponse; body: StatementsDTO; }) => {
237-
const receiptDTO = response.body;
215+
map((receiptDTO: StatementsDTO) => {
238216
return CreateStatementFromDTO(receiptDTO, networkType);
239217
}),
240-
catchError((error) => throwError(this.errorHandling(error))),
241218
),
242219
),
243220
);

src/infrastructure/ChainHttp.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { ClientResponse } from 'http';
18-
import {from as observableFrom, Observable, throwError} from 'rxjs';
19-
import {catchError, map} from 'rxjs/operators';
17+
import {from as observableFrom, Observable} from 'rxjs';
18+
import {map} from 'rxjs/operators';
2019
import {BlockchainScore} from '../model/blockchain/BlockchainScore';
2120
import {UInt64} from '../model/UInt64';
2221
import { BlockchainScoreDTO,
@@ -51,29 +50,21 @@ export class ChainHttp extends Http implements ChainRepository {
5150
* @returns Observable<UInt64>
5251
*/
5352
public getBlockchainHeight(): Observable<UInt64> {
54-
return observableFrom(this.chainRoutesApi.getBlockchainHeight()).pipe(
55-
map((response: { response: ClientResponse; body: HeightInfoDTO; } ) => {
56-
const heightDTO = response.body;
57-
return new UInt64(heightDTO.height);
58-
}),
59-
catchError((error) => throwError(this.errorHandling(error))),
60-
);
53+
return observableFrom(this.chainRoutesApi.getBlockchainHeight()).pipe(map((heightDTO: HeightInfoDTO) => {
54+
return new UInt64(heightDTO.height);
55+
}));
6156
}
6257

6358
/**
6459
* Gets current blockchain score
6560
* @returns Observable<BlockchainScore>
6661
*/
6762
public getBlockchainScore(): Observable<BlockchainScore> {
68-
return observableFrom(this.chainRoutesApi.getBlockchainScore()).pipe(
69-
map((response: { response: ClientResponse; body: BlockchainScoreDTO; } ) => {
70-
const blockchainScoreDTO = response.body;
71-
return new BlockchainScore(
72-
new UInt64(blockchainScoreDTO.scoreLow),
73-
new UInt64(blockchainScoreDTO.scoreHigh),
74-
);
75-
}),
76-
catchError((error) => throwError(this.errorHandling(error))),
77-
);
63+
return observableFrom(this.chainRoutesApi.getBlockchainScore()).pipe(map((blockchainScoreDTO: BlockchainScoreDTO) => {
64+
return new BlockchainScore(
65+
new UInt64(blockchainScoreDTO.scoreLow),
66+
new UInt64(blockchainScoreDTO.scoreHigh),
67+
);
68+
}));
7869
}
7970
}

src/infrastructure/DiagnosticHttp.ts

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { ClientResponse } from 'http';
18-
import {from as observableFrom, Observable, throwError} from 'rxjs';
19-
import {catchError, map} from 'rxjs/operators';
17+
import {from as observableFrom, Observable} from 'rxjs';
18+
import {map} from 'rxjs/operators';
2019
import {BlockchainStorageInfo} from '../model/blockchain/BlockchainStorageInfo';
2120
import { ServerInfo } from '../model/diagnostic/ServerInfo';
2221
import { DiagnosticRoutesApi, ServerDTO, StorageInfoDTO } from './api';
@@ -50,17 +49,13 @@ export class DiagnosticHttp extends Http implements DiagnosticRepository {
5049
*/
5150
public getDiagnosticStorage(): Observable<BlockchainStorageInfo> {
5251
return observableFrom(
53-
this.diagnosticRoutesApi.getDiagnosticStorage()).pipe(
54-
map((response: { response: ClientResponse; body: StorageInfoDTO; } ) => {
55-
const blockchainStorageInfoDTO = response.body;
56-
return new BlockchainStorageInfo(
57-
blockchainStorageInfoDTO.numBlocks,
58-
blockchainStorageInfoDTO.numTransactions,
59-
blockchainStorageInfoDTO.numAccounts,
60-
);
61-
}),
62-
catchError((error) => throwError(this.errorHandling(error))),
63-
);
52+
this.diagnosticRoutesApi.getDiagnosticStorage()).pipe(map((blockchainStorageInfoDTO: StorageInfoDTO) => {
53+
return new BlockchainStorageInfo(
54+
blockchainStorageInfoDTO.numBlocks,
55+
blockchainStorageInfoDTO.numTransactions,
56+
blockchainStorageInfoDTO.numAccounts,
57+
);
58+
}));
6459
}
6560

6661
/**
@@ -69,13 +64,9 @@ export class DiagnosticHttp extends Http implements DiagnosticRepository {
6964
*/
7065
public getServerInfo(): Observable<ServerInfo> {
7166
return observableFrom(
72-
this.diagnosticRoutesApi.getServerInfo()).pipe(
73-
map((response: { response: ClientResponse; body: ServerDTO; } ) => {
74-
const serverDTO = response.body;
75-
return new ServerInfo(serverDTO.serverInfo.restVersion,
76-
serverDTO.serverInfo.sdkVersion);
77-
}),
78-
catchError((error) => throwError(this.errorHandling(error))),
79-
);
67+
this.diagnosticRoutesApi.getServerInfo()).pipe(map((serverDTO: ServerDTO) => {
68+
return new ServerInfo(serverDTO.serverInfo.restVersion,
69+
serverDTO.serverInfo.sdkVersion);
70+
}));
8071
}
8172
}

src/infrastructure/Http.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,4 @@ export abstract class Http {
5757
order: queryParams ? queryParams.order : undefined,
5858
};
5959
}
60-
61-
errorHandling(error: any): Error {
62-
if (error.response && error.response.statusCode && error.response.body) {
63-
const formattedError = {
64-
statusCode: error.response.statusCode,
65-
errorDetails: error.response.body,
66-
};
67-
return new Error(JSON.stringify(formattedError));
68-
}
69-
return new Error(error);
70-
}
7160
}

0 commit comments

Comments
 (0)