mirror of
https://github.com/mempool/mempool.git
synced 2025-09-27 23:57:11 +02:00
refactor simplicity tapleaf detection
This commit is contained in:
@@ -320,7 +320,7 @@ export class TaprootAddressScriptsComponent implements OnChanges {
|
||||
const hex = node.value.script.hex.slice(0, 300);
|
||||
asmContent = `
|
||||
<div style="margin-top: 10px; border-top: 1px solid #333; padding-top: 5px; word-break: break-all; white-space: normal; font-family: monospace; font-size: 12px;">
|
||||
<td>Simplicity tapscript: ${hex} ${node.value.script.hex.length > 300 ? '...' : ''}</td>
|
||||
<td>Simplicity script: ${hex} ${node.value.script.hex.length > 300 ? '...' : ''}</td>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
|
@@ -234,7 +234,7 @@
|
||||
</tr>
|
||||
<tr *ngIf="vin.inner_witnessscript_asm">
|
||||
@if (isLiquid && vin.inner_simplicityscript) {
|
||||
<td i18n="transactions-list.p2tr-simplicity-tapscript">P2TR Simplicity tapscript</td>
|
||||
<td i18n="transactions-list.p2tr-simplicity-script">P2TR Simplicity script</td>
|
||||
<td style="text-align: left;">
|
||||
<div [innerHTML]="showFullScript[vindex] ? vin.inner_simplicityscript : vin.inner_simplicityscript.slice(0, 1000)"></div>
|
||||
<div *ngIf="vin.inner_simplicityscript.length > 1000" style="display: flex;">
|
||||
|
@@ -338,14 +338,15 @@ export class TransactionsListComponent implements OnInit, OnChanges, OnDestroy {
|
||||
} else { // check for simplicity script spends
|
||||
for (const vin of tx.vin) {
|
||||
if (vin.prevout?.scriptpubkey_type === 'v1_p2tr' && vin.inner_witnessscript_asm) {
|
||||
const hasAnnex = vin.witness?.[vin.witness.length - 1].startsWith('50');
|
||||
// script spend
|
||||
if (vin.witness.length > (hasAnnex ? 2 : 1)) {
|
||||
const controlBlock = vin.witness[vin.witness.length - (hasAnnex ? 2 : 1)];
|
||||
const script = vin.witness[vin.witness.length - (hasAnnex ? 3 : 2)];
|
||||
// simplicity tapleaf version
|
||||
if (controlBlock.startsWith('be') || controlBlock.startsWith('bf')) {
|
||||
vin.inner_simplicityscript = script;
|
||||
const hasAnnex = vin.witness[vin.witness.length - 1].startsWith('50');
|
||||
const isScriptSpend = vin.witness.length > (hasAnnex ? 2 : 1);
|
||||
if (isScriptSpend) {
|
||||
const controlBlock = hasAnnex ? vin.witness[vin.witness.length - 2] : vin.witness[vin.witness.length - 1];
|
||||
const scriptHex = hasAnnex ? vin.witness[vin.witness.length - 3] : vin.witness[vin.witness.length - 2];
|
||||
const tapleafVersion = parseInt(controlBlock.slice(0, 2), 16) & 0xfe;
|
||||
// simplicity script spend
|
||||
if (tapleafVersion === 0xbe) {
|
||||
vin.inner_simplicityscript = scriptHex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -128,6 +128,7 @@ export class AddressTypeInfo {
|
||||
// flags
|
||||
isMultisig?: { m: number, n: number };
|
||||
tapscript?: boolean;
|
||||
simplicity?: boolean;
|
||||
|
||||
constructor (network: string, address: string, type?: AddressType, vin?: Vin[], vout?: Vout) {
|
||||
this.network = network;
|
||||
@@ -157,19 +158,20 @@ export class AddressTypeInfo {
|
||||
if (this.type === 'v1_p2tr') {
|
||||
for (let i = 0; i < vin.length; i++) {
|
||||
const v = vin[i];
|
||||
if (v.inner_witnessscript_asm) {
|
||||
this.tapscript = true;
|
||||
const hasAnnex = v.witness[v.witness.length - 1].startsWith('50');
|
||||
const hasAnnex = v.witness[v.witness.length - 1].startsWith('50');
|
||||
const isScriptSpend = v.witness.length > (hasAnnex ? 2 : 1);
|
||||
if (isScriptSpend) {
|
||||
const controlBlock = hasAnnex ? v.witness[v.witness.length - 2] : v.witness[v.witness.length - 1];
|
||||
const scriptHex = hasAnnex ? v.witness[v.witness.length - 3] : v.witness[v.witness.length - 2];
|
||||
const tapleafVersion = parseInt(controlBlock.slice(0, 2), 16) & 0xfe;
|
||||
|
||||
if ((this.network === 'liquid' || this.network === 'liquidtestnet')
|
||||
&& (controlBlock.startsWith('be') || controlBlock.startsWith('bf'))
|
||||
) {
|
||||
if (tapleafVersion === 0xc0 && v.inner_witnessscript_asm) {
|
||||
this.tapscript = true;
|
||||
this.processScript(new ScriptInfo('inner_witnessscript', scriptHex, v.inner_witnessscript_asm, v.witness, controlBlock, vinIds?.[i]));
|
||||
} else if (this.network === 'liquid' || this.network === 'liquidtestnet' && tapleafVersion === 0xbe) {
|
||||
this.simplicity = true;
|
||||
v.inner_simplicityscript = scriptHex;
|
||||
this.processScript(new ScriptInfo('inner_simplicityscript', scriptHex, null, v.witness, controlBlock, vinIds?.[i]));
|
||||
} else {
|
||||
this.processScript(new ScriptInfo('inner_witnessscript', scriptHex, v.inner_witnessscript_asm, v.witness, controlBlock, vinIds?.[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user