actually test htlc, fix indentation (again) and detect multisig

This commit is contained in:
Antoni Spaanderman 2022-02-05 17:26:50 +01:00
parent 7565aa7a25
commit 148e340ea6
No known key found for this signature in database
GPG Key ID: AE0B68E552E5DF8C

View File

@ -54,7 +54,7 @@ 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$/) {
} 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 {
@ -66,39 +66,42 @@ export class AddressLabelsComponent implements OnInit {
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);
if (this.multisigM === 1 && this.multisigN === 1) {
this.multisig = false;
}
}
this.detectMultisig(this.vin.inner_witnessscript_asm);
}
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];
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;
}
}
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;
}
}