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
|
|
|
}
|
|
|
|
|
|
|
|
[
|
2021-02-10 19:55:11 +07:00
|
|
|
// {regexp: /^OP_DUP OP_HASH160/, label: 'HTLC'},
|
2021-02-03 12:51:30 +07:00
|
|
|
{regexp: /^OP_IF OP_PUSHBYTES_33 \w{33} OP_ELSE OP_PUSHBYTES_2 \w{2} OP_CSV OP_DROP/, label: 'Force Close'}
|
|
|
|
].forEach((item) => {
|
|
|
|
if (item.regexp.test(this.vin.inner_witnessscript_asm)) {
|
|
|
|
this.lightning = item.label;
|
2021-02-03 02:40:31 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-02-03 19:03:59 +07:00
|
|
|
if (this.lightning) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-25 20:05:34 +07:00
|
|
|
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;
|
2020-05-09 20:37:50 +07:00
|
|
|
this.multisigM = parseInt(matches[0], 10);
|
|
|
|
this.multisigN = parseInt(matches[1], 10);
|
|
|
|
|
|
|
|
if (this.multisigM === 1 && this.multisigN === 1) {
|
|
|
|
this.multisig = false;
|
|
|
|
}
|
2020-02-25 20:05:34 +07:00
|
|
|
}
|
2020-02-16 22:15:07 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|