Merge pull request #5241 from vostrnad/baremultisig-labels

Fix missing bare multisig labels
This commit is contained in:
softsimon 2024-07-01 19:06:07 +09:00 committed by GitHub
commit c4b45180dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 3 deletions

View File

@ -33,6 +33,8 @@ export class AddressLabelsComponent implements OnChanges {
this.handleAddress(); this.handleAddress();
} else if (this.vin) { } else if (this.vin) {
this.handleVin(); this.handleVin();
} else if (this.vout) {
this.handleVout();
} }
} }
@ -61,4 +63,14 @@ export class AddressLabelsComponent implements OnChanges {
} }
} }
} }
handleVout() {
const address = new AddressTypeInfo(this.network || 'mainnet', this.vout.scriptpubkey_address, this.vout.scriptpubkey_type as AddressType, undefined, this.vout);
if (address?.scripts.size) {
const script = address?.scripts.values().next().value;
if (script.template?.label) {
this.label = script.template.label;
}
}
}
} }

View File

@ -1,6 +1,6 @@
import '@angular/localize/init'; import '@angular/localize/init';
import { ScriptInfo } from './script.utils'; import { ScriptInfo } from './script.utils';
import { Vin } from '../interfaces/electrs.interface'; import { Vin, Vout } from '../interfaces/electrs.interface';
import { BECH32_CHARS_LW, BASE58_CHARS, HEX_CHARS } from './regex.utils'; import { BECH32_CHARS_LW, BASE58_CHARS, HEX_CHARS } from './regex.utils';
export type AddressType = 'fee' export type AddressType = 'fee'
@ -127,7 +127,7 @@ export class AddressTypeInfo {
isMultisig?: { m: number, n: number }; isMultisig?: { m: number, n: number };
tapscript?: boolean; tapscript?: boolean;
constructor (network: string, address: string, type?: AddressType, vin?: Vin[]) { constructor (network: string, address: string, type?: AddressType, vin?: Vin[], vout?: Vout) {
this.network = network; this.network = network;
this.address = address; this.address = address;
this.scripts = new Map(); this.scripts = new Map();
@ -137,6 +137,9 @@ export class AddressTypeInfo {
this.type = detectAddressType(address, network); this.type = detectAddressType(address, network);
} }
this.processInputs(vin); this.processInputs(vin);
if (vout) {
this.processOutput(vout);
}
} }
public clone(): AddressTypeInfo { public clone(): AddressTypeInfo {
@ -180,8 +183,21 @@ export class AddressTypeInfo {
} }
} }
} }
} else if (this.type === 'multisig') {
if (vin.length) {
const v = vin[0];
this.processScript(new ScriptInfo('scriptpubkey', v.prevout.scriptpubkey, v.prevout.scriptpubkey_asm));
}
}
// and there's nothing more to learn from processing inputs for other types
}
public processOutput(output: Vout): void {
if (this.type === 'multisig') {
if (!this.scripts.size) {
this.processScript(new ScriptInfo('scriptpubkey', output.scriptpubkey, output.scriptpubkey_asm));
}
} }
// and there's nothing more to learn from processing inputs for non-scripthash types
} }
private processScript(script: ScriptInfo): void { private processScript(script: ScriptInfo): void {