Address page with QR code
This commit is contained in:
@@ -13,4 +13,7 @@ export interface AbstractBitcoinApi {
|
||||
getBlockTransactionsFromIndex(hash: string, index: number): Promise<IBlock>;
|
||||
getBlocks(): Promise<string>;
|
||||
getBlocksFromHeight(height: number): Promise<string>;
|
||||
getAddress(address: string): Promise<IBlock>;
|
||||
getAddressTransactions(address: string): Promise<IBlock>;
|
||||
getAddressTransactionsFromLastSeenTxid(address: string, lastSeenTxid: string): Promise<IBlock>;
|
||||
}
|
||||
|
||||
@@ -84,22 +84,27 @@ class BitcoindApi implements AbstractBitcoinApi {
|
||||
getBlock(hash: string): Promise<IBlock> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
getBlocks(): Promise<string> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
getBlocksFromHeight(height: number): Promise<string> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
getBlockTransactions(hash: string): Promise<IBlock> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
getBlockTransactionsFromIndex(hash: string, index: number): Promise<IBlock> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
getAddress(address: string): Promise<IBlock> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
getAddressTransactions(address: string): Promise<IBlock> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
getAddressTransactionsFromLastSeenTxid(address: string, lastSeenTxid: string): Promise<IBlock> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
}
|
||||
|
||||
export default BitcoindApi;
|
||||
|
||||
@@ -149,6 +149,39 @@ class EsploraApi implements AbstractBitcoinApi {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getAddress(address: string): Promise<IBlock> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const blockInfo: AxiosResponse = await this.client.get('/address/' + address);
|
||||
resolve(blockInfo.data);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getAddressTransactions(address: string): Promise<IBlock> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const blockInfo: AxiosResponse = await this.client.get('/address/' + address + '/txs');
|
||||
resolve(blockInfo.data);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getAddressTransactionsFromLastSeenTxid(address: string, lastSeenTxid: string): Promise<IBlock> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const blockInfo: AxiosResponse = await this.client.get('/address/' + address + '/txs/chain/' + lastSeenTxid);
|
||||
resolve(blockInfo.data);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default EsploraApi;
|
||||
|
||||
@@ -272,6 +272,9 @@ class MempoolSpace {
|
||||
.get(config.API_ENDPOINT + 'explorer/block/:hash', routes.getBlock)
|
||||
.get(config.API_ENDPOINT + 'explorer/block/:hash/tx', routes.getBlockTransactions)
|
||||
.get(config.API_ENDPOINT + 'explorer/block/:hash/tx/:index', routes.getBlockTransactionsFromIndex)
|
||||
.get(config.API_ENDPOINT + 'explorer/address/:address', routes.getAddress)
|
||||
.get(config.API_ENDPOINT + 'explorer/address/:address/tx', routes.getAddressTransactions)
|
||||
.get(config.API_ENDPOINT + 'explorer/address/:address/tx/chain/:txid', routes.getAddressTransactionsFromTxid)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +126,33 @@ class Routes {
|
||||
res.status(500).send(e.message);
|
||||
}
|
||||
}
|
||||
|
||||
public async getAddress(req, res) {
|
||||
try {
|
||||
const result = await bitcoinApi.getAddress(req.params.address);
|
||||
res.send(result);
|
||||
} catch (e) {
|
||||
res.status(500).send(e.message);
|
||||
}
|
||||
}
|
||||
|
||||
public async getAddressTransactions(req, res) {
|
||||
try {
|
||||
const result = await bitcoinApi.getAddressTransactions(req.params.address);
|
||||
res.send(result);
|
||||
} catch (e) {
|
||||
res.status(500).send(e.message);
|
||||
}
|
||||
}
|
||||
|
||||
public async getAddressTransactionsFromTxid(req, res) {
|
||||
try {
|
||||
const result = await bitcoinApi.getAddressTransactionsFromLastSeenTxid(req.params.address, req.params.txid);
|
||||
res.send(result);
|
||||
} catch (e) {
|
||||
res.status(500).send(e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new Routes();
|
||||
|
||||
Reference in New Issue
Block a user