1414 * limitations under the License.
1515 */
1616
17- import { BlockchainRoutesApi } from 'nem2-library' ;
17+ import { BlockRoutesApi } from 'nem2-library' ;
1818import { from as observableFrom , Observable } from 'rxjs' ;
1919import { map } from 'rxjs/operators' ;
2020import { PublicAccount } from '../model/account/PublicAccount' ;
21- import { BlockchainScore } from '../model/blockchain/BlockchainScore' ;
22- import { BlockchainStorageInfo } from '../model/blockchain/BlockchainStorageInfo' ;
2321import { BlockInfo } from '../model/blockchain/BlockInfo' ;
22+ import { MerklePathItem } from '../model/blockchain/MerklePathItem' ;
23+ import { MerkleProofInfo } from '../model/blockchain/MerkleProofInfo' ;
24+ import { MerkleProofInfoPayload } from '../model/blockchain/MerkleProofInfoPayload' ;
2425import { Transaction } from '../model/transaction/Transaction' ;
2526import { UInt64 } from '../model/UInt64' ;
26- import { BlockchainRepository } from './BlockchainRepository ' ;
27+ import { BlockRepository } from './BlockRepository ' ;
2728import { Http } from './Http' ;
2829import { QueryParams } from './QueryParams' ;
2930import { CreateTransactionFromDTO , extractBeneficiary } from './transaction/CreateTransactionFromDTO' ;
@@ -33,20 +34,20 @@ import {CreateTransactionFromDTO, extractBeneficiary} from './transaction/Create
3334 *
3435 * @since 1.0
3536 */
36- export class BlockchainHttp extends Http implements BlockchainRepository {
37+ export class BlockHttp extends Http implements BlockRepository {
3738 /**
3839 * @internal
39- * Nem2 Library blockchain routes api
40+ * Nem2 Library block routes api
4041 */
41- private blockchainRoutesApi : BlockchainRoutesApi ;
42+ private blockRoutesApi : BlockRoutesApi ;
4243
4344 /**
4445 * Constructor
4546 * @param url
4647 */
4748 constructor ( url : string ) {
4849 super ( url ) ;
49- this . blockchainRoutesApi = new BlockchainRoutesApi ( this . apiClient ) ;
50+ this . blockRoutesApi = new BlockRoutesApi ( this . apiClient ) ;
5051 }
5152
5253 /**
@@ -55,7 +56,7 @@ export class BlockchainHttp extends Http implements BlockchainRepository {
5556 * @returns Observable<BlockInfo>
5657 */
5758 public getBlockByHeight ( height : number ) : Observable < BlockInfo > {
58- return observableFrom ( this . blockchainRoutesApi . getBlockByHeight ( height ) ) . pipe ( map ( ( blockDTO ) => {
59+ return observableFrom ( this . blockRoutesApi . getBlockByHeight ( height ) ) . pipe ( map ( ( blockDTO ) => {
5960 const networkType = parseInt ( blockDTO . block . version . toString ( 16 ) . substr ( 0 , 2 ) , 16 ) ;
6061 return new BlockInfo (
6162 blockDTO . meta . hash ,
@@ -89,7 +90,7 @@ export class BlockchainHttp extends Http implements BlockchainRepository {
8990 public getBlockTransactions ( height : number ,
9091 queryParams ?: QueryParams ) : Observable < Transaction [ ] > {
9192 return observableFrom (
92- this . blockchainRoutesApi . getBlockTransactions ( height , queryParams != null ? queryParams : { } ) ) . pipe ( map ( ( transactionsDTO ) => {
93+ this . blockRoutesApi . getBlockTransactions ( height , queryParams != null ? queryParams : { } ) ) . pipe ( map ( ( transactionsDTO ) => {
9394 return transactionsDTO . map ( ( transactionDTO ) => {
9495 return CreateTransactionFromDTO ( transactionDTO ) ;
9596 } ) ;
@@ -104,7 +105,7 @@ export class BlockchainHttp extends Http implements BlockchainRepository {
104105 */
105106 public getBlocksByHeightWithLimit ( height : number , limit : number = 1 ) : Observable < BlockInfo [ ] > {
106107 return observableFrom (
107- this . blockchainRoutesApi . getBlocksByHeightWithLimit ( height , limit ) ) . pipe ( map ( ( blocksDTO ) => {
108+ this . blockRoutesApi . getBlocksByHeightWithLimit ( height , limit ) ) . pipe ( map ( ( blocksDTO ) => {
108109 return blocksDTO . map ( ( blockDTO ) => {
109110 const networkType = parseInt ( blockDTO . block . version . toString ( 16 ) . substr ( 0 , 2 ) , 16 ) ;
110111 return new BlockInfo (
@@ -132,40 +133,44 @@ export class BlockchainHttp extends Http implements BlockchainRepository {
132133 }
133134
134135 /**
135- * Gets current blockchain height
136- * @returns Observable<UInt64>
136+ * Get the merkle path for a given a receipt statement hash and block
137+ * Returns the merkle path for a [receipt statement or resolution](https://nemtech.github.io/concepts/receipt.html)
138+ * linked to a block. The path is the complementary data needed to calculate the merkle root.
139+ * A client can compare if the calculated root equals the one recorded in the block header,
140+ * verifying that the receipt was linked with the block.
141+ * @param height The height of the block.
142+ * @param hash The hash of the receipt statement or resolution.
143+ * @return Observable<MerkleProofInfo>
137144 */
138- public getBlockchainHeight ( ) : Observable < UInt64 > {
139- return observableFrom ( this . blockchainRoutesApi . getBlockchainHeight ( ) ) . pipe ( map ( ( heightDTO ) => {
140- return new UInt64 ( heightDTO . height ) ;
141- } ) ) ;
142- }
143-
144- /**
145- * Gets current blockchain score
146- * @returns Observable<BlockchainScore>
147- */
148- public getBlockchainScore ( ) : Observable < BlockchainScore > {
149- return observableFrom ( this . blockchainRoutesApi . getBlockchainScore ( ) ) . pipe ( map ( ( blockchainScoreDTO ) => {
150- return new BlockchainScore (
151- new UInt64 ( blockchainScoreDTO . scoreLow ) ,
152- new UInt64 ( blockchainScoreDTO . scoreHigh ) ,
153- ) ;
145+ public getMerkleReceipts ( height : number , hash : string ) : Observable < MerkleProofInfo > {
146+ return observableFrom (
147+ this . blockRoutesApi . getMerkleReceipts ( height , hash ) ) . pipe ( map ( ( merkleProofReceipt ) => {
148+ return new MerkleProofInfo (
149+ new MerkleProofInfoPayload (
150+ merkleProofReceipt . payload . merklePath . map ( ( payload ) => new MerklePathItem ( payload . position , payload . hash ) ) ) ,
151+ merkleProofReceipt . type ,
152+ ) ;
154153 } ) ) ;
155154 }
156155
157156 /**
158- * Gets blockchain storage info.
159- * @returns Observable<BlockchainStorageInfo>
157+ * Get the merkle path for a given a transaction and block
158+ * Returns the merkle path for a [transaction](https://nemtech.github.io/concepts/transaction.html)
159+ * included in a block. The path is the complementary data needed to calculate the merkle root.
160+ * A client can compare if the calculated root equals the one recorded in the block header,
161+ * verifying that the transaction was included in the block.
162+ * @param height The height of the block.
163+ * @param hash The hash of the transaction.
164+ * @return Observable<MerkleProofInfo>
160165 */
161- public getDiagnosticStorage ( ) : Observable < BlockchainStorageInfo > {
166+ public getMerkleTransaction ( height : number , hash : string ) : Observable < MerkleProofInfo > {
162167 return observableFrom (
163- this . blockchainRoutesApi . getDiagnosticStorage ( ) ) . pipe ( map ( ( blockchainStorageInfoDTO ) => {
164- return new BlockchainStorageInfo (
165- blockchainStorageInfoDTO . numBlocks ,
166- blockchainStorageInfoDTO . numTransactions ,
167- blockchainStorageInfoDTO . numAccounts ,
168- ) ;
168+ this . blockRoutesApi . getMerkleReceipts ( height , hash ) ) . pipe ( map ( ( merkleProofReceipt ) => {
169+ return new MerkleProofInfo (
170+ new MerkleProofInfoPayload (
171+ merkleProofReceipt . payload . merklePath . map ( ( payload ) => new MerklePathItem ( payload . position , payload . hash ) ) ) ,
172+ merkleProofReceipt . type ,
173+ ) ;
169174 } ) ) ;
170175 }
171176}
0 commit comments