Added first seen on mempool transactions.

This commit is contained in:
softsimon
2020-02-28 01:09:07 +07:00
parent 23a61a37fd
commit 4879036216
17 changed files with 100 additions and 34 deletions

View File

@@ -52,12 +52,25 @@ class Mempool {
return this.vBytesPerSecond;
}
public getFirstSeenForTransactions(txIds: string[]): number[] {
const txTimes: number[] = [];
txIds.forEach((txId: string) => {
if (this.mempoolCache[txId]) {
txTimes.push(this.mempoolCache[txId].firstSeen);
} else {
txTimes.push(0);
}
});
return txTimes;
}
public async getTransactionExtended(txId: string): Promise<TransactionExtended | false> {
try {
const transaction: Transaction = await bitcoinApi.getRawTransaction(txId);
return Object.assign({
vsize: transaction.weight / 4,
feePerVsize: transaction.fee / (transaction.weight / 4),
firstSeen: Math.round((new Date().getTime() / 1000)),
}, transaction);
} catch (e) {
console.log(txId + ' not found');

View File

@@ -71,6 +71,7 @@ class Server {
setUpHttpApiRoutes() {
this.app
.get(config.API_ENDPOINT + 'transaction-times', routes.getTransactionTimes)
.get(config.API_ENDPOINT + 'fees/recommended', routes.getRecommendedFees)
.get(config.API_ENDPOINT + 'fees/mempool-blocks', routes.getMempoolBlocks)
.get(config.API_ENDPOINT + 'statistics/2h', routes.get2HStatistics)

View File

@@ -33,6 +33,7 @@ export interface TransactionExtended extends Transaction {
size: number;
vsize: number;
feePerVsize: number;
firstSeen: number;
}
export interface Prevout {

View File

@@ -1,6 +1,7 @@
import statistics from './api/statistics';
import feeApi from './api/fee-api';
import mempoolBlocks from './api/mempool-blocks';
import mempool from './api/mempool';
class Routes {
private cache = {};
@@ -62,6 +63,16 @@ class Routes {
res.status(500).send(e.message);
}
}
public getTransactionTimes(req, res) {
if (!Array.isArray(req.query.txId)) {
res.status(500).send('Not an array');
return;
}
const txIds = req.query.txId;
const times = mempool.getFirstSeenForTransactions(txIds);
res.send(times);
}
}
export default new Routes();