Skip to content

Commit ec38331

Browse files
committed
Added interface,
1 parent 0bb1832 commit ec38331

File tree

3 files changed

+52
-10
lines changed

3 files changed

+52
-10
lines changed

e2e/service/BlockService.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('BlockService', () => {
4848
networkType = helper.networkType;
4949
transactionRepository = helper.repositoryFactory.createTransactionRepository();
5050
receiptRepository = helper.repositoryFactory.createReceiptRepository();
51-
blockService = new BlockService(helper.repositoryFactory.createBlockRepository(), receiptRepository);
51+
blockService = new BlockService(helper.repositoryFactory);
5252
});
5353
});
5454
before(() => {
@@ -102,9 +102,9 @@ describe('BlockService', () => {
102102

103103
describe('Validate receipt', () => {
104104
it('call block service', async () => {
105-
const statement = await receiptRepository.getBlockReceipts(UInt64.fromUint(1)).toPromise();
106-
const receipt = statement.transactionStatements[0];
107-
const validationResult = await blockService.validateReceiptInBlock(receipt.generateHash(), UInt64.fromUint(1)).toPromise();
105+
const statements = await receiptRepository.getBlockReceipts(UInt64.fromUint(1)).toPromise();
106+
const statement = statements.transactionStatements[0];
107+
const validationResult = await blockService.validateStatementInBlock(statement.generateHash(), UInt64.fromUint(1)).toPromise();
108108
expect(validationResult).to.be.true;
109109
});
110110
});

src/service/BlockService.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,24 @@ import { combineLatest, Observable } from 'rxjs';
1919
import { map } from 'rxjs/operators';
2020
import { BlockRepository } from '../infrastructure/BlockRepository';
2121
import { ReceiptRepository } from '../infrastructure/ReceiptRepository';
22+
import { RepositoryFactory } from '../infrastructure/RepositoryFactory';
2223
import { MerklePathItem } from '../model/blockchain/MerklePathItem';
2324
import { UInt64 } from '../model/UInt64';
2425

2526
/**
2627
* Transaction Service
2728
*/
2829
export class BlockService {
30+
private readonly blockRepository: BlockRepository;
31+
private readonly receiptRepository: ReceiptRepository;
2932

3033
/**
3134
* Constructor
32-
* @param blockRepository
33-
* @param receiptRepository
35+
* @param repositoryFactory
3436
*/
35-
constructor(private readonly blockRepository: BlockRepository, private readonly receiptRepository: ReceiptRepository) {
37+
constructor(public readonly repositoryFactory: RepositoryFactory) {
38+
this.blockRepository = repositoryFactory.createBlockRepository();
39+
this.receiptRepository = repositoryFactory.createReceiptRepository();
3640
}
3741

3842
/**
@@ -49,11 +53,11 @@ export class BlockService {
4953
}
5054

5155
/**
52-
* Validate receipt hash in block
53-
* @param leaf receipt hash
56+
* Validate statement hash in block
57+
* @param leaf statement hash
5458
* @param height block height
5559
*/
56-
public validateReceiptInBlock(leaf: string, height: UInt64): Observable<boolean> {
60+
public validateStatementInBlock(leaf: string, height: UInt64): Observable<boolean> {
5761
const rootHashObservable = this.blockRepository.getBlockByHeight(height);
5862
const merklePathItemObservable = this.receiptRepository.getMerkleReceipts(height, leaf);
5963
return combineLatest(rootHashObservable, merklePathItemObservable).pipe(
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2020 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 { Observable } from 'rxjs';
18+
import { UInt64 } from '../../model/UInt64';
19+
20+
/**
21+
* Block Service Interface
22+
*/
23+
export interface IBlockService {
24+
25+
/**
26+
* Validate transaction hash in block
27+
* @param leaf transaction hash
28+
* @param height block height
29+
*/
30+
validateTransactionInBlock(leaf: string, height: UInt64): Observable<boolean>;
31+
32+
/**
33+
* Validate statement hash in block
34+
* @param leaf statement hash
35+
* @param height block height
36+
*/
37+
validateStatementInBlock(leaf: string, height: UInt64): Observable<boolean>;
38+
}

0 commit comments

Comments
 (0)