Fix transaction size when using esplora api
This commit is contained in:
		
							parent
							
								
									35c4d9676c
								
							
						
					
					
						commit
						3074983d3a
					
				@ -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;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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 {
 | 
			
		||||
 | 
			
		||||
@ -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 {
 | 
			
		||||
 | 
			
		||||
@ -13,6 +13,7 @@ export interface ITransaction {
 | 
			
		||||
  version: number;
 | 
			
		||||
  size: number;
 | 
			
		||||
  vsize: number;
 | 
			
		||||
  weight: number;
 | 
			
		||||
  locktime: number;
 | 
			
		||||
  vin: Vin[];
 | 
			
		||||
  vout: Vout[];
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user