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 fb827e65b..40db539b1 100644 --- a/frontend/src/app/components/address-labels/address-labels.component.ts +++ b/frontend/src/app/components/address-labels/address-labels.component.ts @@ -54,51 +54,54 @@ export class AddressLabelsComponent implements OnInit { this.lightning = 'Force Close'; } // https://github.com/lightning/bolts/blob/master/03-transactions.md#offered-htlc-outputs - } else if (/^OP_DUP OP_HASH160 OP_PUSHBYTES_20 \w{40} OP_EQUAL OP_IF OP_CHECKSIG OP_ELSE OP_PUSHBYTES_33 \w{66} OP_SWAP OP_SIZE OP_PUSHBYTES_1 20 OP_EQUAL OP_NOTIF OP_DROP OP_PUSHNUM_2 OP_SWAP OP_PUSHBYTES_33 \w{66} OP_PUSHNUM_2 OP_CHECKMULTISIG OP_ELSE OP_HASH160 OP_PUSHBYTES_20 \w{40} OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF (OP_PUSHNUM_1 OP_CHECKSEQUENCEVERIFY OP_DROP |)OP_ENDIF$/) { - if (this.vin.witness[this.vin.witness.length - 2].length == 66) { - this.lightning = 'Revoked HTLC'; - } else { - this.lightning = 'HTLC'; - } + } else if (/^OP_DUP OP_HASH160 OP_PUSHBYTES_20 \w{40} OP_EQUAL OP_IF OP_CHECKSIG OP_ELSE OP_PUSHBYTES_33 \w{66} OP_SWAP OP_SIZE OP_PUSHBYTES_1 20 OP_EQUAL OP_NOTIF OP_DROP OP_PUSHNUM_2 OP_SWAP OP_PUSHBYTES_33 \w{66} OP_PUSHNUM_2 OP_CHECKMULTISIG OP_ELSE OP_HASH160 OP_PUSHBYTES_20 \w{40} OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF (OP_PUSHNUM_1 OP_CHECKSEQUENCEVERIFY OP_DROP |)OP_ENDIF$/.test(this.vin.inner_witnessscript_asm)) { + if (this.vin.witness[this.vin.witness.length - 2].length == 66) { + this.lightning = 'Revoked HTLC'; + } else { + this.lightning = 'HTLC'; + } } if (this.lightning) { 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; - this.multisigM = parseInt(matches[0], 10); - this.multisigN = parseInt(matches[1], 10); + this.detectMultisig(this.vin.inner_witnessscript_asm); + } - if (this.multisigM === 1 && this.multisigN === 1) { - this.multisig = false; - } + this.detectMultisig(this.vin.inner_redeemscript_asm); + } + + detectMultisig(script: string) { + const ops = script.split(' '); + if (ops.pop() != 'OP_CHECKMULTISIG') { + return; + } + const opN = ops.pop(); + if (!opN.startsWith('OP_PUSHNUM_')) { + return; + } + const n = parseInt(opN.match(/[0-9]+/)[0]); + // pop n public keys + for (var i = 0; i < n; i++) { + if (ops.pop().length != 66) { + return; + } + if (ops.pop() != 'OP_PUSHBYTES_33') { + return; } } - - if (this.vin.inner_redeemscript_asm && this.vin.inner_redeemscript_asm.indexOf('OP_CHECKMULTISIG') > -1) { - const matches = this.getMatches(this.vin.inner_redeemscript_asm, /OP_PUSHNUM_([0-9])/g, 1); - this.multisig = true; - this.multisigM = matches[0]; - this.multisigN = matches[1]; + const opM = ops.pop(); + if (!opM.startsWith('OP_PUSHNUM_')) { + return; } + const m = parseInt(opN.match(/[0-9]+/)[0]); + + this.multisig = true; + this.multisigM = m; + this.multisigN = n; } handleVout() { } - - getMatches(str: string, regex: RegExp, index: number) { - if (!index) { - index = 1; - } - const matches = []; - let match; - while (match = regex.exec(str)) { - matches.push(match[index]); - } - return matches; - } - }