Add support for anchor output type

This commit is contained in:
Mononaut 2024-08-30 21:39:22 +00:00
parent 3bea10ea35
commit 12285465d9
No known key found for this signature in database
GPG Key ID: A3F058E41374C04E
5 changed files with 17 additions and 1 deletions

View File

@ -323,6 +323,7 @@ class BitcoinApi implements AbstractBitcoinApi {
'witness_v1_taproot': 'v1_p2tr', 'witness_v1_taproot': 'v1_p2tr',
'nonstandard': 'nonstandard', 'nonstandard': 'nonstandard',
'multisig': 'multisig', 'multisig': 'multisig',
'anchor': 'anchor',
'nulldata': 'op_return' 'nulldata': 'op_return'
}; };

View File

@ -55,7 +55,7 @@ export class AddressLabelsComponent implements OnChanges {
} }
handleVin() { handleVin() {
const address = new AddressTypeInfo(this.network || 'mainnet', this.vin.prevout?.scriptpubkey_address, this.vin.prevout?.scriptpubkey_type as AddressType, [this.vin]) const address = new AddressTypeInfo(this.network || 'mainnet', this.vin.prevout?.scriptpubkey_address, this.vin.prevout?.scriptpubkey_type as AddressType, [this.vin]);
if (address?.scripts.size) { if (address?.scripts.size) {
const script = address?.scripts.values().next().value; const script = address?.scripts.values().next().value;
if (script.template?.label) { if (script.template?.label) {

View File

@ -17,6 +17,7 @@ export type AddressType = 'fee'
| 'v0_p2wsh' | 'v0_p2wsh'
| 'v1_p2tr' | 'v1_p2tr'
| 'confidential' | 'confidential'
| 'anchor'
| 'unknown' | 'unknown'
const ADDRESS_PREFIXES = { const ADDRESS_PREFIXES = {
@ -188,6 +189,12 @@ export class AddressTypeInfo {
const v = vin[0]; const v = vin[0];
this.processScript(new ScriptInfo('scriptpubkey', v.prevout.scriptpubkey, v.prevout.scriptpubkey_asm)); this.processScript(new ScriptInfo('scriptpubkey', v.prevout.scriptpubkey, v.prevout.scriptpubkey_asm));
} }
} else if (this.type === 'unknown') {
for (const v of vin) {
if (v.prevout?.scriptpubkey === '51024e73') {
this.type = 'anchor';
}
}
} }
// and there's nothing more to learn from processing inputs for other types // and there's nothing more to learn from processing inputs for other types
} }
@ -197,6 +204,10 @@ export class AddressTypeInfo {
if (!this.scripts.size) { if (!this.scripts.size) {
this.processScript(new ScriptInfo('scriptpubkey', output.scriptpubkey, output.scriptpubkey_asm)); this.processScript(new ScriptInfo('scriptpubkey', output.scriptpubkey, output.scriptpubkey_asm));
} }
} else if (this.type === 'unknown') {
if (output.scriptpubkey === '51024e73') {
this.type = 'anchor';
}
} }
} }

View File

@ -20,6 +20,9 @@
@case ('multisig') { @case ('multisig') {
<span i18n="address.bare-multisig">bare multisig</span> <span i18n="address.bare-multisig">bare multisig</span>
} }
@case ('anchor') {
<span>anchor</span>
}
@case (null) { @case (null) {
<span>unknown</span> <span>unknown</span>
} }

View File

@ -166,6 +166,7 @@ export const ScriptTemplates: { [type: string]: (...args: any) => ScriptTemplate
ln_anchor: () => ({ type: 'ln_anchor', label: 'Lightning Anchor' }), ln_anchor: () => ({ type: 'ln_anchor', label: 'Lightning Anchor' }),
ln_anchor_swept: () => ({ type: 'ln_anchor_swept', label: 'Swept Lightning Anchor' }), ln_anchor_swept: () => ({ type: 'ln_anchor_swept', label: 'Swept Lightning Anchor' }),
multisig: (m: number, n: number) => ({ type: 'multisig', m, n, label: $localize`:@@address-label.multisig:Multisig ${m}:multisigM: of ${n}:multisigN:` }), multisig: (m: number, n: number) => ({ type: 'multisig', m, n, label: $localize`:@@address-label.multisig:Multisig ${m}:multisigM: of ${n}:multisigN:` }),
anchor: () => ({ type: 'anchor', label: 'anchor' }),
}; };
export class ScriptInfo { export class ScriptInfo {