From 276117fba94ca5dff9128d27addcba8e01076b96 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Wed, 3 Feb 2021 02:40:31 -0300 Subject: [PATCH] better identification of lightning outputs. (#320) * better identification of lightning outputs. * identify liquid pegouts and emergency pegouts. fixes #324 --- .../address-labels.component.html | 20 ++++++++++++-- .../address-labels.component.ts | 27 +++++++++++++++---- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/frontend/src/app/components/address-labels/address-labels.component.html b/frontend/src/app/components/address-labels/address-labels.component.html index 2b986aecf..3ef9e092a 100644 --- a/frontend/src/app/components/address-labels/address-labels.component.html +++ b/frontend/src/app/components/address-labels/address-labels.component.html @@ -1,2 +1,18 @@ -multisig {{ multisigM }} of {{ multisigN }} -Layer{{ network === 'liquid' ? '3' : '2' }} Peg-out +multisig {{ multisigM }} of {{ multisigN }} +Lightning {{ lightning }} +Liquid {{ liquid }} diff --git a/frontend/src/app/components/address-labels/address-labels.component.ts b/frontend/src/app/components/address-labels/address-labels.component.ts index e7a48dc07..ba9413ea8 100644 --- a/frontend/src/app/components/address-labels/address-labels.component.ts +++ b/frontend/src/app/components/address-labels/address-labels.component.ts @@ -18,7 +18,8 @@ export class AddressLabelsComponent implements OnInit { multisigM: number; multisigN: number; - secondLayerClose = false; + lightning = null; + liquid = null; constructor( stateService: StateService, @@ -36,6 +37,26 @@ export class AddressLabelsComponent implements OnInit { handleVin() { if (this.vin.inner_witnessscript_asm) { + if (this.vin.inner_witnessscript_asm.indexOf('OP_DEPTH OP_PUSHNUM_12 OP_EQUAL OP_IF OP_PUSHNUM_11') === 0) { + if (this.vin.witness.length > 11) { + this.liquid = 'Peg Out'; + } else { + this.liquid = 'Emergency Peg Out'; + } + } + + [ + [/^OP_DUP OP_HASH160/, 'HTLC'], + [/^OP_IF OP_PUSHBYTES_33 \w{33} OP_ELSE OP_PUSHBYTES_2 \w{2} OP_CSV OP_DROP/, 'Force Close'] + ].forEach( + ([re, label]) => { + if (re.test(this.vin.inner_witnessscript_asm)) { + this.lightning = label; + return; + } + } + ); + if (this.vin.inner_witnessscript_asm.indexOf('OP_CHECKMULTISIG') > -1) { const matches = this.getMatches(this.vin.inner_witnessscript_asm, /OP_PUSHNUM_([0-9])/g, 1); this.multisig = true; @@ -46,10 +67,6 @@ export class AddressLabelsComponent implements OnInit { this.multisig = false; } } - - if (/OP_IF (.+) OP_ELSE (.+) OP_CSV OP_DROP/.test(this.vin.inner_witnessscript_asm)) { - this.secondLayerClose = true; - } } if (this.vin.inner_redeemscript_asm && this.vin.inner_redeemscript_asm.indexOf('OP_CHECKMULTISIG') > -1) {