Skip to content

Commit c07875d

Browse files
authored
Merge pull request #431 from NEMStudios/master
UInt64 Height in Block and Receipt Http
2 parents 8e112a5 + 60e10d0 commit c07875d

File tree

8 files changed

+32
-27
lines changed

8 files changed

+32
-27
lines changed

e2e/infrastructure/BlockHttp.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { Deadline } from '../../src/model/transaction/Deadline';
2828
import { TransactionInfo } from '../../src/model/transaction/TransactionInfo';
2929
import { TransferTransaction } from '../../src/model/transaction/TransferTransaction';
3030
import { IntegrationTestHelper } from './IntegrationTestHelper';
31+
import { UInt64 } from '../../src/model/UInt64';
3132

3233
describe('BlockHttp', () => {
3334
const helper = new IntegrationTestHelper();
@@ -87,7 +88,7 @@ describe('BlockHttp', () => {
8788

8889
describe('getBlockByHeight', () => {
8990
it('should return block info given height', (done) => {
90-
blockRepository.getBlockByHeight('1')
91+
blockRepository.getBlockByHeight(UInt64.fromUint(1))
9192
.subscribe((blockInfo) => {
9293
blockReceiptHash = blockInfo.blockReceiptsHash;
9394
blockTransactionHash = blockInfo.blockTransactionsHash;
@@ -105,7 +106,7 @@ describe('BlockHttp', () => {
105106
let firstId: string;
106107

107108
it('should return block transactions data given height', (done) => {
108-
blockRepository.getBlockTransactions('1')
109+
blockRepository.getBlockTransactions(UInt64.fromUint(1))
109110
.subscribe((transactions) => {
110111
nextId = transactions[0].transactionInfo!.id;
111112
firstId = transactions[1].transactionInfo!.id;
@@ -115,7 +116,7 @@ describe('BlockHttp', () => {
115116
});
116117

117118
it('should return block transactions data given height with paginated transactionId', (done) => {
118-
blockRepository.getBlockTransactions('1', new QueryParams(10, nextId))
119+
blockRepository.getBlockTransactions(UInt64.fromUint(1), new QueryParams(10, nextId))
119120
.subscribe((transactions) => {
120121
expect(transactions[0].transactionInfo!.id).to.be.equal(firstId);
121122
expect(transactions.length).to.be.greaterThan(0);

src/infrastructure/BlockHttp.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export class BlockHttp extends Http implements BlockRepository {
5454
* @param height - Block height
5555
* @returns Observable<BlockInfo>
5656
*/
57-
public getBlockByHeight(height: string): Observable<BlockInfo> {
58-
return observableFrom(this.blockRoutesApi.getBlockByHeight(height)).pipe(
57+
public getBlockByHeight(height: UInt64): Observable<BlockInfo> {
58+
return observableFrom(this.blockRoutesApi.getBlockByHeight(height.toString())).pipe(
5959
map(({body}) => this.toBlockInfo(body)),
6060
catchError((error) => throwError(this.errorHandling(error))),
6161
);
@@ -67,10 +67,10 @@ export class BlockHttp extends Http implements BlockRepository {
6767
* @param queryParams - (Optional) Query params
6868
* @returns Observable<Transaction[]>
6969
*/
70-
public getBlockTransactions(height: string,
70+
public getBlockTransactions(height: UInt64,
7171
queryParams?: QueryParams): Observable<Transaction[]> {
7272
return observableFrom(
73-
this.blockRoutesApi.getBlockTransactions(height,
73+
this.blockRoutesApi.getBlockTransactions(height.toString(),
7474
this.queryParams(queryParams).pageSize,
7575
this.queryParams(queryParams).id,
7676
this.queryParams(queryParams).order))
@@ -87,9 +87,9 @@ export class BlockHttp extends Http implements BlockRepository {
8787
* @param limit - Number of blocks returned.
8888
* @returns Observable<BlockInfo[]>
8989
*/
90-
public getBlocksByHeightWithLimit(height: string, limit: number): Observable<BlockInfo[]> {
90+
public getBlocksByHeightWithLimit(height: UInt64, limit: number): Observable<BlockInfo[]> {
9191
return observableFrom(
92-
this.blockRoutesApi.getBlocksByHeightWithLimit(height, limit)).pipe(
92+
this.blockRoutesApi.getBlocksByHeightWithLimit(height.toString(), limit)).pipe(
9393
map(({body}) => body.map((blockDTO) => this.toBlockInfo(blockDTO))),
9494
catchError((error) => throwError(this.errorHandling(error))),
9595
);
@@ -136,9 +136,9 @@ export class BlockHttp extends Http implements BlockRepository {
136136
* @param hash The hash of the transaction.
137137
* @return Observable<MerkleProofInfo>
138138
*/
139-
public getMerkleTransaction(height: string, hash: string): Observable<MerkleProofInfo> {
139+
public getMerkleTransaction(height: UInt64, hash: string): Observable<MerkleProofInfo> {
140140
return observableFrom(
141-
this.blockRoutesApi.getMerkleTransaction(height, hash)).pipe(
141+
this.blockRoutesApi.getMerkleTransaction(height.toString(), hash)).pipe(
142142
map(({body}) => new MerkleProofInfo(
143143
body.merklePath!.map((payload) => new MerklePathItem(payload.position, payload.hash)),
144144
)),

src/infrastructure/BlockRepository.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import {Observable} from 'rxjs';
1818
import {BlockInfo} from '../model/blockchain/BlockInfo';
1919
import { MerkleProofInfo } from '../model/blockchain/MerkleProofInfo';
20-
import { Statement } from '../model/receipt/Statement';
2120
import {Transaction} from '../model/transaction/Transaction';
21+
import { UInt64 } from '../model/UInt64';
2222
import {QueryParams} from './QueryParams';
2323

2424
/**
@@ -33,15 +33,15 @@ export interface BlockRepository {
3333
* @param height - Block height
3434
* @returns Observable<BlockInfo>
3535
*/
36-
getBlockByHeight(height: string): Observable<BlockInfo>;
36+
getBlockByHeight(height: UInt64): Observable<BlockInfo>;
3737

3838
/**
3939
* Gets array of transactions included in a block for a block height
4040
* @param height - Block height
4141
* @param queryParams - (Optional) Query params
4242
* @returns Observable<Transaction[]>
4343
*/
44-
getBlockTransactions(height: string,
44+
getBlockTransactions(height: UInt64,
4545
queryParams?: QueryParams): Observable<Transaction[]>;
4646

4747
/**
@@ -51,7 +51,7 @@ export interface BlockRepository {
5151
* @returns Observable<BlockInfo[]>
5252
*/
5353

54-
getBlocksByHeightWithLimit(height: string, limit: number): Observable<BlockInfo[]>;
54+
getBlocksByHeightWithLimit(height: UInt64, limit: number): Observable<BlockInfo[]>;
5555

5656
/**
5757
* Get the merkle path for a given a transaction and block
@@ -63,5 +63,5 @@ export interface BlockRepository {
6363
* @param hash The hash of the transaction.
6464
* @return Observable<MerkleProofInfo>
6565
*/
66-
getMerkleTransaction(height: string, hash: string): Observable<MerkleProofInfo>;
66+
getMerkleTransaction(height: UInt64, hash: string): Observable<MerkleProofInfo>;
6767
}

src/infrastructure/ReceiptHttp.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { MerklePathItem } from '../model/blockchain/MerklePathItem';
2121
import { MerkleProofInfo } from '../model/blockchain/MerkleProofInfo';
2222
import { NetworkType } from '../model/blockchain/NetworkType';
2323
import { Statement } from '../model/receipt/Statement';
24+
import { UInt64 } from '../model/UInt64';
2425
import { Http } from './Http';
2526
import { CreateStatementFromDTO } from './receipt/CreateReceiptFromDTO';
2627
import { ReceiptRepository } from './ReceiptRepository';
@@ -64,9 +65,9 @@ export class ReceiptHttp extends Http implements ReceiptRepository {
6465
* @param hash The hash of the receipt statement or resolution.
6566
* @return Observable<MerkleProofInfo>
6667
*/
67-
public getMerkleReceipts(height: string, hash: string): Observable<MerkleProofInfo> {
68+
public getMerkleReceipts(height: UInt64, hash: string): Observable<MerkleProofInfo> {
6869
return observableFrom(
69-
this.receiptRoutesApi.getMerkleReceipts(height, hash)).pipe(
70+
this.receiptRoutesApi.getMerkleReceipts(height.toString(), hash)).pipe(
7071
map(({body}) => new MerkleProofInfo(
7172
body.merklePath!.map(
7273
(payload) => new MerklePathItem(payload.position, payload.hash)),
@@ -81,10 +82,10 @@ export class ReceiptHttp extends Http implements ReceiptRepository {
8182
* @param queryParams - (Optional) Query params
8283
* @returns Observable<Statement>
8384
*/
84-
public getBlockReceipts(height: string): Observable<Statement> {
85+
public getBlockReceipts(height: UInt64): Observable<Statement> {
8586
return this.networkTypeObservable.pipe(
8687
mergeMap((networkType) => observableFrom(
87-
this.receiptRoutesApi.getBlockReceipts(height)).pipe(
88+
this.receiptRoutesApi.getBlockReceipts(height.toString())).pipe(
8889
map(({body}) => CreateStatementFromDTO(body, networkType)),
8990
catchError((error) => throwError(this.errorHandling(error))),
9091
),

src/infrastructure/ReceiptRepository.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import {Observable} from 'rxjs';
1818
import { MerkleProofInfo } from '../model/blockchain/MerkleProofInfo';
1919
import { Statement } from '../model/receipt/Statement';
20+
import { UInt64 } from '../model/UInt64';
2021

2122
/**
2223
* Receipt interface repository.
@@ -28,10 +29,10 @@ export interface ReceiptRepository {
2829
/**
2930
* Get receipts from a block
3031
* Returns the receipts linked to a block.
31-
* @param {string} height The height of the block.
32+
* @param {UInt64} height The height of the block.
3233
* @return Observable<Statement>
3334
*/
34-
getBlockReceipts(height: string): Observable<Statement>;
35+
getBlockReceipts(height: UInt64): Observable<Statement>;
3536

3637
/**
3738
* Get the merkle path for a given a receipt statement hash and block
@@ -43,5 +44,5 @@ export interface ReceiptRepository {
4344
* @param hash The hash of the receipt statement or resolution.
4445
* @return Observable<MerkleProofInfo>
4546
*/
46-
getMerkleReceipts(height: string, hash: string): Observable<MerkleProofInfo>;
47+
getMerkleReceipts(height: UInt64, hash: string): Observable<MerkleProofInfo>;
4748
}

src/infrastructure/RepositoryFactoryHttp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { Observable, of as observableOf } from 'rxjs';
1818
import { map, share, shareReplay } from 'rxjs/operators';
1919
import { NetworkType } from '../model/blockchain/NetworkType';
20+
import { UInt64 } from '../model/UInt64';
2021
import { AccountHttp } from './AccountHttp';
2122
import { AccountRepository } from './AccountRepository';
2223
import { BlockHttp } from './BlockHttp';
@@ -69,7 +70,7 @@ export class RepositoryFactoryHttp implements RepositoryFactory {
6970
this.url = url;
7071
this.networkType = networkType ? observableOf(networkType) : this.createNetworkRepository().getNetworkType().pipe(shareReplay(1));
7172
this.generationHash = generationHash ? observableOf(generationHash) :
72-
this.createBlockRepository().getBlockByHeight('1').pipe(map((b) => b.generationHash)).pipe(shareReplay(1));
73+
this.createBlockRepository().getBlockByHeight(UInt64.fromUint(1)).pipe(map((b) => b.generationHash)).pipe(shareReplay(1));
7374
}
7475

7576
createAccountRepository(): AccountRepository {

src/service/TransactionService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export class TransactionService implements ITransactionService {
181181
* @return {Observable<Transaction>}
182182
*/
183183
private resolvedFromReceipt(transaction: Transaction, aggregateIndex: number): Observable<Transaction> {
184-
return this.receiptRepository.getBlockReceipts(transaction.transactionInfo!.height.toString()).pipe(
184+
return this.receiptRepository.getBlockReceipts(transaction.transactionInfo!.height).pipe(
185185
map((statement) => transaction.resolveAliases(statement, aggregateIndex)),
186186
);
187187
}

test/infrastructure/RepositoryFactory.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
import { expect } from 'chai';
1717
import { of as observableOf } from 'rxjs';
1818
import { map } from 'rxjs/operators';
19-
import { instance, mock, when } from 'ts-mockito';
19+
import { deepEqual, instance, mock, when } from 'ts-mockito';
2020
import { BlockRepository } from '../../src/infrastructure/BlockRepository';
2121
import { NetworkRepository } from '../../src/infrastructure/NetworkRepository';
2222
import { RepositoryFactoryHttp } from '../../src/infrastructure/RepositoryFactoryHttp';
2323
import { BlockInfo } from '../../src/model/blockchain/BlockInfo';
2424
import { NetworkType } from '../../src/model/blockchain/NetworkType';
25+
import { UInt64 } from '../../src/model/UInt64';
2526

2627
describe('RepositoryFactory', () => {
2728
it('Should create repositories', () => {
@@ -52,7 +53,7 @@ describe('RepositoryFactory', () => {
5253
counter++;
5354
return v;
5455
}));
55-
when(repositoryMock.getBlockByHeight('1')).thenReturn(observableOfBlockInfo);
56+
when(repositoryMock.getBlockByHeight(deepEqual(UInt64.fromUint(1)))).thenReturn(observableOfBlockInfo);
5657
expect(observableOfBlockInfo).to.be.equals(observableOfBlockInfo);
5758
const repositoryFactory = new (class RepositoryFactoryHttpForTest extends RepositoryFactoryHttp {
5859

0 commit comments

Comments
 (0)