actually test htlc, fix indentation (again) and detect multisig
This commit is contained in:
parent
7565aa7a25
commit
148e340ea6
@ -54,51 +54,54 @@ export class AddressLabelsComponent implements OnInit {
|
|||||||
this.lightning = 'Force Close';
|
this.lightning = 'Force Close';
|
||||||
}
|
}
|
||||||
// https://github.com/lightning/bolts/blob/master/03-transactions.md#offered-htlc-outputs
|
// 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) {
|
if (this.vin.witness[this.vin.witness.length - 2].length == 66) {
|
||||||
this.lightning = 'Revoked HTLC';
|
this.lightning = 'Revoked HTLC';
|
||||||
} else {
|
} else {
|
||||||
this.lightning = 'HTLC';
|
this.lightning = 'HTLC';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lightning) {
|
if (this.lightning) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.vin.inner_witnessscript_asm.indexOf('OP_CHECKMULTISIG') > -1) {
|
this.detectMultisig(this.vin.inner_witnessscript_asm);
|
||||||
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.detectMultisig(this.vin.inner_redeemscript_asm);
|
||||||
this.multisig = false;
|
}
|
||||||
}
|
|
||||||
|
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 (this.vin.inner_redeemscript_asm && this.vin.inner_redeemscript_asm.indexOf('OP_CHECKMULTISIG') > -1) {
|
if (!opM.startsWith('OP_PUSHNUM_')) {
|
||||||
const matches = this.getMatches(this.vin.inner_redeemscript_asm, /OP_PUSHNUM_([0-9])/g, 1);
|
return;
|
||||||
this.multisig = true;
|
|
||||||
this.multisigM = matches[0];
|
|
||||||
this.multisigN = matches[1];
|
|
||||||
}
|
}
|
||||||
|
const m = parseInt(opN.match(/[0-9]+/)[0]);
|
||||||
|
|
||||||
|
this.multisig = true;
|
||||||
|
this.multisigM = m;
|
||||||
|
this.multisigN = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleVout() {
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user