From 12285465d9ea3a034f6b054a158cf63e9ebbd2ce Mon Sep 17 00:00:00 2001 From: Mononaut Date: Fri, 30 Aug 2024 21:39:22 +0000 Subject: [PATCH] Add support for anchor output type --- backend/src/api/bitcoin/bitcoin-api.ts | 1 + .../address-labels/address-labels.component.ts | 2 +- frontend/src/app/shared/address-utils.ts | 11 +++++++++++ .../address-type/address-type.component.html | 3 +++ frontend/src/app/shared/script.utils.ts | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/backend/src/api/bitcoin/bitcoin-api.ts b/backend/src/api/bitcoin/bitcoin-api.ts index 3e1fe2108..7fa431db6 100644 --- a/backend/src/api/bitcoin/bitcoin-api.ts +++ b/backend/src/api/bitcoin/bitcoin-api.ts @@ -323,6 +323,7 @@ class BitcoinApi implements AbstractBitcoinApi { 'witness_v1_taproot': 'v1_p2tr', 'nonstandard': 'nonstandard', 'multisig': 'multisig', + 'anchor': 'anchor', 'nulldata': 'op_return' }; diff --git a/frontend/src/app/components/address-labels/address-labels.component.ts b/frontend/src/app/components/address-labels/address-labels.component.ts index dd81b9809..ff3c27240 100644 --- a/frontend/src/app/components/address-labels/address-labels.component.ts +++ b/frontend/src/app/components/address-labels/address-labels.component.ts @@ -55,7 +55,7 @@ export class AddressLabelsComponent implements OnChanges { } 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) { const script = address?.scripts.values().next().value; if (script.template?.label) { diff --git a/frontend/src/app/shared/address-utils.ts b/frontend/src/app/shared/address-utils.ts index 92646af14..59c85014b 100644 --- a/frontend/src/app/shared/address-utils.ts +++ b/frontend/src/app/shared/address-utils.ts @@ -17,6 +17,7 @@ export type AddressType = 'fee' | 'v0_p2wsh' | 'v1_p2tr' | 'confidential' + | 'anchor' | 'unknown' const ADDRESS_PREFIXES = { @@ -188,6 +189,12 @@ export class AddressTypeInfo { const v = vin[0]; 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 } @@ -197,6 +204,10 @@ export class AddressTypeInfo { if (!this.scripts.size) { this.processScript(new ScriptInfo('scriptpubkey', output.scriptpubkey, output.scriptpubkey_asm)); } + } else if (this.type === 'unknown') { + if (output.scriptpubkey === '51024e73') { + this.type = 'anchor'; + } } } diff --git a/frontend/src/app/shared/components/address-type/address-type.component.html b/frontend/src/app/shared/components/address-type/address-type.component.html index fe4286689..598c21a6e 100644 --- a/frontend/src/app/shared/components/address-type/address-type.component.html +++ b/frontend/src/app/shared/components/address-type/address-type.component.html @@ -20,6 +20,9 @@ @case ('multisig') { bare multisig } + @case ('anchor') { + anchor + } @case (null) { unknown } diff --git a/frontend/src/app/shared/script.utils.ts b/frontend/src/app/shared/script.utils.ts index 171112dcc..637eede30 100644 --- a/frontend/src/app/shared/script.utils.ts +++ b/frontend/src/app/shared/script.utils.ts @@ -166,6 +166,7 @@ export const ScriptTemplates: { [type: string]: (...args: any) => ScriptTemplate ln_anchor: () => ({ type: 'ln_anchor', label: '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:` }), + anchor: () => ({ type: 'anchor', label: 'anchor' }), }; export class ScriptInfo {