From 3074983d3ae300c0bb7c6865bd3b114e5a3ca3f6 Mon Sep 17 00:00:00 2001 From: Simon Lindh Date: Mon, 28 Oct 2019 16:47:42 +0800 Subject: [PATCH] Fix transaction size when using esplora api --- backend/src/api/bitcoin/esplora-api.ts | 3 +-- backend/src/api/mempool.ts | 2 +- backend/src/api/projected-blocks.ts | 2 +- backend/src/interfaces.ts | 1 + 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/api/bitcoin/esplora-api.ts b/backend/src/api/bitcoin/esplora-api.ts index 1d449eb3e..4709aed0c 100644 --- a/backend/src/api/bitcoin/esplora-api.ts +++ b/backend/src/api/bitcoin/esplora-api.ts @@ -43,8 +43,7 @@ class EsploraApi implements AbstractBitcoinApi { try { const response: AxiosResponse = await this.client.get('/tx/' + txId); - response.data.vsize = response.data.size; - response.data.size = response.data.weight; + response.data.vsize = Math.round(response.data.weight / 4); response.data.fee = response.data.fee / 100000000; response.data.blockhash = response.data.status.block_hash; diff --git a/backend/src/api/mempool.ts b/backend/src/api/mempool.ts index a78aef247..089ce604b 100644 --- a/backend/src/api/mempool.ts +++ b/backend/src/api/mempool.ts @@ -57,7 +57,7 @@ class Mempool { transaction.vout.forEach((output) => totalOut += output.value); if (config.BACKEND_API === 'esplora') { - transaction.feePerWeightUnit = (transaction.fee * 100000000) / (transaction.vsize * 4) || 0; + transaction.feePerWeightUnit = (transaction.fee * 100000000) / transaction.weight || 0; transaction.feePerVsize = (transaction.fee * 100000000) / (transaction.vsize) || 0; transaction.totalOut = totalOut / 100000000; } else { diff --git a/backend/src/api/projected-blocks.ts b/backend/src/api/projected-blocks.ts index 4f8b590a8..9b8a9b252 100644 --- a/backend/src/api/projected-blocks.ts +++ b/backend/src/api/projected-blocks.ts @@ -54,7 +54,7 @@ class ProjectedBlocks { let transactions: ITransaction[] = []; this.transactionsSorted.forEach((tx) => { if (blockWeight + tx.vsize * 4 < 4000000 || projectedBlocks.length === numberOfBlocks) { - blockWeight += tx.vsize * 4; + blockWeight += tx.weight || tx.vsize * 4; blockSize += tx.size; transactions.push(tx); } else { diff --git a/backend/src/interfaces.ts b/backend/src/interfaces.ts index 4926b0666..c51ded07d 100644 --- a/backend/src/interfaces.ts +++ b/backend/src/interfaces.ts @@ -13,6 +13,7 @@ export interface ITransaction { version: number; size: number; vsize: number; + weight: number; locktime: number; vin: Vin[]; vout: Vout[];