Use sigops from mempool/electrs, fix the nodejs sigop calculation
This commit is contained in:
parent
74a2cedc7a
commit
ea2a7e7505
@ -6,6 +6,7 @@ export namespace IEsploraApi {
|
|||||||
size: number;
|
size: number;
|
||||||
weight: number;
|
weight: number;
|
||||||
fee: number;
|
fee: number;
|
||||||
|
sigops?: number;
|
||||||
vin: Vin[];
|
vin: Vin[];
|
||||||
vout: Vout[];
|
vout: Vout[];
|
||||||
status: Status;
|
status: Status;
|
||||||
|
@ -116,7 +116,10 @@ class TransactionUtils {
|
|||||||
public extendMempoolTransaction(transaction: IEsploraApi.Transaction): MempoolTransactionExtended {
|
public extendMempoolTransaction(transaction: IEsploraApi.Transaction): MempoolTransactionExtended {
|
||||||
const vsize = Math.ceil(transaction.weight / 4);
|
const vsize = Math.ceil(transaction.weight / 4);
|
||||||
const fractionalVsize = (transaction.weight / 4);
|
const fractionalVsize = (transaction.weight / 4);
|
||||||
const sigops = !Common.isLiquid() ? this.countSigops(transaction) : 0;
|
let sigops = transaction.sigops;
|
||||||
|
if (sigops == null) {
|
||||||
|
sigops = !Common.isLiquid() ? this.countSigops(transaction) : 0;
|
||||||
|
}
|
||||||
// https://github.com/bitcoin/bitcoin/blob/e9262ea32a6e1d364fb7974844fadc36f931f8c6/src/policy/policy.cpp#L295-L298
|
// https://github.com/bitcoin/bitcoin/blob/e9262ea32a6e1d364fb7974844fadc36f931f8c6/src/policy/policy.cpp#L295-L298
|
||||||
const adjustedVsize = Math.max(fractionalVsize, sigops * 5); // adjusted vsize = Max(weight, sigops * bytes_per_sigop) / witness_scale_factor
|
const adjustedVsize = Math.max(fractionalVsize, sigops * 5); // adjusted vsize = Max(weight, sigops * bytes_per_sigop) / witness_scale_factor
|
||||||
const feePerVbytes = (transaction.fee || 0) / fractionalVsize;
|
const feePerVbytes = (transaction.fee || 0) / fractionalVsize;
|
||||||
@ -155,7 +158,7 @@ class TransactionUtils {
|
|||||||
sigops += 20 * (script.match(/OP_CHECKMULTISIG/g)?.length || 0);
|
sigops += 20 * (script.match(/OP_CHECKMULTISIG/g)?.length || 0);
|
||||||
} else {
|
} else {
|
||||||
// in redeem scripts and witnesses, worth N if preceded by OP_N, 20 otherwise
|
// in redeem scripts and witnesses, worth N if preceded by OP_N, 20 otherwise
|
||||||
const matches = script.matchAll(/(?:OP_(\d+))? OP_CHECKMULTISIG/g);
|
const matches = script.matchAll(/(?:OP_(?:PUSHNUM_)?(\d+))? OP_CHECKMULTISIG/g);
|
||||||
for (const match of matches) {
|
for (const match of matches) {
|
||||||
const n = parseInt(match[1]);
|
const n = parseInt(match[1]);
|
||||||
if (Number.isInteger(n)) {
|
if (Number.isInteger(n)) {
|
||||||
@ -189,6 +192,12 @@ class TransactionUtils {
|
|||||||
sigops += this.countScriptSigops(bitcoinjs.script.toASM(Buffer.from(input.witness[input.witness.length - 1], 'hex')), false, true);
|
sigops += this.countScriptSigops(bitcoinjs.script.toASM(Buffer.from(input.witness[input.witness.length - 1], 'hex')), false, true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case input.prevout.scriptpubkey_type === 'p2sh':
|
||||||
|
if (input.inner_redeemscript_asm) {
|
||||||
|
sigops += this.countScriptSigops(input.inner_redeemscript_asm);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user