Fix transaction size when using esplora api

This commit is contained in:
Simon Lindh 2019-10-28 16:47:42 +08:00
parent 35c4d9676c
commit 3074983d3a
4 changed files with 4 additions and 4 deletions

View File

@ -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;

View File

@ -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 {

View File

@ -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 {

View File

@ -13,6 +13,7 @@ export interface ITransaction {
version: number;
size: number;
vsize: number;
weight: number;
locktime: number;
vin: Vin[];
vout: Vout[];