2020-02-16 22:15:07 +07:00
|
|
|
import { Component, OnInit, ChangeDetectionStrategy, Input } from '@angular/core';
|
|
|
|
import { Vin, Vout } from '../../interfaces/electrs.interface';
|
2020-06-10 23:52:14 +07:00
|
|
|
import { StateService } from 'src/app/services/state.service';
|
2020-02-16 22:15:07 +07:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-address-labels',
|
|
|
|
templateUrl: './address-labels.component.html',
|
|
|
|
styleUrls: ['./address-labels.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
|
})
|
|
|
|
export class AddressLabelsComponent implements OnInit {
|
2020-06-10 23:52:14 +07:00
|
|
|
network = '';
|
2020-02-16 22:15:07 +07:00
|
|
|
|
|
|
|
@Input() vin: Vin;
|
|
|
|
@Input() vout: Vout;
|
|
|
|
|
|
|
|
multisig = false;
|
|
|
|
multisigM: number;
|
|
|
|
multisigN: number;
|
|
|
|
|
2021-02-03 02:40:31 -03:00
|
|
|
lightning = null;
|
|
|
|
liquid = null;
|
2020-02-25 20:05:34 +07:00
|
|
|
|
2020-06-10 23:52:14 +07:00
|
|
|
constructor(
|
|
|
|
stateService: StateService,
|
|
|
|
) {
|
|
|
|
this.network = stateService.network;
|
|
|
|
}
|
2020-02-16 22:15:07 +07:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
if (this.vin) {
|
|
|
|
this.handleVin();
|
|
|
|
} else if (this.vout) {
|
|
|
|
this.handleVout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleVin() {
|
2020-02-25 20:05:34 +07:00
|
|
|
if (this.vin.inner_witnessscript_asm) {
|
2021-02-03 02:40:31 -03:00
|
|
|
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';
|
|
|
|
}
|
2021-02-03 19:03:59 +07:00
|
|
|
return;
|
2021-02-03 02:40:31 -03:00
|
|
|
}
|
|
|
|
|
2022-03-27 16:13:48 +02:00
|
|
|
const topElement = this.vin.witness[this.vin.witness.length - 2];
|
2022-02-05 16:50:10 +01:00
|
|
|
// https://github.com/lightning/bolts/blob/master/03-transactions.md#commitment-transaction-outputs
|
|
|
|
if (/^OP_IF OP_PUSHBYTES_33 \w{66} OP_ELSE OP_PUSHBYTES_(1 \w{2}|2 \w{4}) OP_CSV OP_DROP OP_PUSHBYTES_33 \w{66} OP_ENDIF OP_CHECKSIG$/.test(this.vin.inner_witnessscript_asm)) {
|
2022-03-27 16:13:48 +02:00
|
|
|
if (topElement === '01') {
|
|
|
|
// top element is '01' to get in the revocation path
|
|
|
|
this.lightning = 'Revoked Force Close';
|
|
|
|
} else {
|
|
|
|
// top element is '', this is a delayed to_local output
|
|
|
|
this.lightning = 'Force Close';
|
|
|
|
}
|
2022-02-05 16:50:10 +01:00
|
|
|
// https://github.com/lightning/bolts/blob/master/03-transactions.md#offered-htlc-outputs
|
2022-02-05 17:26:50 +01:00
|
|
|
} 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)) {
|
2022-03-27 16:13:48 +02:00
|
|
|
if (topElement.length === 66) {
|
|
|
|
// top element is a public key
|
|
|
|
this.lightning = 'Revoked HTLC';
|
|
|
|
} else if (topElement) {
|
|
|
|
// top element is a preimage
|
|
|
|
this.lightning = 'HTLC';
|
|
|
|
} else {
|
|
|
|
// top element is '' to get in the multisig path of the script
|
|
|
|
this.lightning = 'Expired HTLC';
|
|
|
|
}
|
|
|
|
// https://github.com/lightning/bolts/blob/master/03-transactions.md#to_local_anchor-and-to_remote_anchor-output-option_anchors
|
|
|
|
} else if (/^OP_PUSHBYTES_33 \w{66} OP_CHECKSIG OP_IFDUP OP_NOTIF OP_PUSHNUM_16 OP_CSV OP_ENDIF$/.test(this.vin.inner_witnessscript_asm)) {
|
|
|
|
if (topElement) {
|
|
|
|
// top element is a signature
|
|
|
|
this.lightning = 'Anchor';
|
2022-02-05 17:26:50 +01:00
|
|
|
} else {
|
2022-03-27 16:13:48 +02:00
|
|
|
// top element is '', it has been swept after 16 blocks
|
|
|
|
this.lightning = 'Swept Anchor';
|
2022-02-05 17:26:50 +01:00
|
|
|
}
|
2022-02-05 16:58:41 +01:00
|
|
|
}
|
2021-02-03 02:40:31 -03:00
|
|
|
|
2021-02-03 19:03:59 +07:00
|
|
|
if (this.lightning) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-05 17:26:50 +01:00
|
|
|
this.detectMultisig(this.vin.inner_witnessscript_asm);
|
2020-02-16 22:15:07 +07:00
|
|
|
}
|
|
|
|
|
2022-02-05 17:26:50 +01:00
|
|
|
this.detectMultisig(this.vin.inner_redeemscript_asm);
|
2020-02-16 22:15:07 +07:00
|
|
|
}
|
|
|
|
|
2022-02-05 17:26:50 +01:00
|
|
|
detectMultisig(script: string) {
|
2022-02-06 12:41:37 +01:00
|
|
|
if (!script) {
|
|
|
|
return;
|
|
|
|
}
|
2022-02-05 17:26:50 +01:00
|
|
|
const ops = script.split(' ');
|
2022-03-27 16:13:48 +02:00
|
|
|
if (ops.length < 3 || ops.pop() !== 'OP_CHECKMULTISIG') {
|
2022-02-05 17:26:50 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const opN = ops.pop();
|
|
|
|
if (!opN.startsWith('OP_PUSHNUM_')) {
|
|
|
|
return;
|
|
|
|
}
|
2022-03-27 16:13:48 +02:00
|
|
|
const n = parseInt(opN.match(/[0-9]+/)[0], 10);
|
2022-02-06 12:41:37 +01:00
|
|
|
if (ops.length < n * 2 + 1) {
|
|
|
|
return;
|
|
|
|
}
|
2022-02-05 17:26:50 +01:00
|
|
|
// pop n public keys
|
2022-03-27 16:13:48 +02:00
|
|
|
for (let i = 0; i < n; i++) {
|
2022-02-06 12:41:37 +01:00
|
|
|
if (!/^0((2|3)\w{64}|4\w{128})$/.test(ops.pop())) {
|
2022-02-05 17:26:50 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-02-06 12:41:37 +01:00
|
|
|
if (!/^OP_PUSHBYTES_(33|65)$/.test(ops.pop())) {
|
2022-02-05 17:26:50 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-02-16 22:15:07 +07:00
|
|
|
}
|
2022-02-05 17:26:50 +01:00
|
|
|
const opM = ops.pop();
|
|
|
|
if (!opM.startsWith('OP_PUSHNUM_')) {
|
|
|
|
return;
|
2020-02-16 22:15:07 +07:00
|
|
|
}
|
2022-03-27 16:13:48 +02:00
|
|
|
const m = parseInt(opM.match(/[0-9]+/)[0], 10);
|
2022-02-05 17:26:50 +01:00
|
|
|
|
|
|
|
this.multisig = true;
|
|
|
|
this.multisigM = m;
|
|
|
|
this.multisigN = n;
|
2020-02-16 22:15:07 +07:00
|
|
|
}
|
|
|
|
|
2022-02-05 17:26:50 +01:00
|
|
|
handleVout() {
|
|
|
|
}
|
2020-02-16 22:15:07 +07:00
|
|
|
}
|