Explorer page with latest blocks. WIP
This commit is contained in:
@@ -7,4 +7,7 @@ export interface AbstractBitcoinApi {
|
||||
getBlockCount(): Promise<number>;
|
||||
getBlock(hash: string): Promise<IBlock>;
|
||||
getBlockHash(height: number): Promise<string>;
|
||||
|
||||
getBlocks(): Promise<string>;
|
||||
getBlocksFromHeight(height: number): Promise<string>;
|
||||
}
|
||||
|
||||
@@ -80,6 +80,14 @@ class BitcoindApi implements AbstractBitcoinApi {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getBlocks(): Promise<string> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
getBlocksFromHeight(height: number): Promise<string> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
}
|
||||
|
||||
export default BitcoindApi;
|
||||
|
||||
@@ -94,6 +94,28 @@ class EsploraApi implements AbstractBitcoinApi {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getBlocks(): Promise<string> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const response: AxiosResponse = await this.client.get('/blocks');
|
||||
resolve(response.data);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getBlocksFromHeight(height: number): Promise<string> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const response: AxiosResponse = await this.client.get('/blocks/' + height);
|
||||
resolve(response.data);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default EsploraApi;
|
||||
|
||||
@@ -263,7 +263,15 @@ class MempoolSpace {
|
||||
.get(config.API_ENDPOINT + 'statistics/3m', routes.get3MStatistics.bind(routes))
|
||||
.get(config.API_ENDPOINT + 'statistics/6m', routes.get6MStatistics.bind(routes))
|
||||
;
|
||||
|
||||
if (config.BACKEND_API === 'esplora') {
|
||||
this.app
|
||||
.get(config.API_ENDPOINT + 'explorer/blocks', routes.getBlocks)
|
||||
.get(config.API_ENDPOINT + 'explorer/blocks/:height', routes.getBlocks)
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const mempoolSpace = new MempoolSpace();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import statistics from './api/statistics';
|
||||
import feeApi from './api/fee-api';
|
||||
import projectedBlocks from './api/projected-blocks';
|
||||
import bitcoinApi from './api/bitcoin/bitcoin-api-factory';
|
||||
|
||||
class Routes {
|
||||
private cache = {};
|
||||
@@ -75,6 +76,20 @@ class Routes {
|
||||
res.status(500).send(e.message);
|
||||
}
|
||||
}
|
||||
|
||||
public async getBlocks(req, res) {
|
||||
try {
|
||||
let result: string;
|
||||
if (req.params.height) {
|
||||
result = await bitcoinApi.getBlocksFromHeight(req.params.height);
|
||||
} else {
|
||||
result = await bitcoinApi.getBlocks();
|
||||
}
|
||||
res.send(result);
|
||||
} catch (e) {
|
||||
res.status(500).send(e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new Routes();
|
||||
|
||||
Reference in New Issue
Block a user