From 00e83582b7678205ddd4d542c11630d885fb14bf Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Mar 2026 20:20:26 +0000 Subject: [PATCH] feat(types): add TxOutTarget interface with TargetType method Establishes the interface that all output target types will implement. TxOutToKey now satisfies TxOutTarget via its TargetType() method. Prepares for HF1 output target types (TxOutMultisig, TxOutHTLC). Co-Authored-By: Charon --- types/transaction.go | 9 +++++++++ types/transaction_test.go | 15 +++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 types/transaction_test.go diff --git a/types/transaction.go b/types/transaction.go index b7d4ba8..d8308ac 100644 --- a/types/transaction.go +++ b/types/transaction.go @@ -115,6 +115,12 @@ type TxInputGenesis struct { // InputType returns the wire variant tag for genesis inputs. func (t TxInputGenesis) InputType() uint8 { return InputTypeGenesis } +// TxOutTarget is the interface implemented by all output target types +// within a TxOutputBare. Each target variant has a unique wire tag. +type TxOutTarget interface { + TargetType() uint8 +} + // TxOutToKey is the txout_to_key target variant. On the wire it is // serialised as a 33-byte packed blob: 32-byte public key + 1-byte mix_attr. type TxOutToKey struct { @@ -122,6 +128,9 @@ type TxOutToKey struct { MixAttr uint8 } +// TargetType returns the wire variant tag for to_key targets. +func (t TxOutToKey) TargetType() uint8 { return TargetTypeToKey } + // TxOutRef is one element of a txin_to_key key_offsets vector. // Each element is a variant: either a uint64 global index or a ref_by_id. type TxOutRef struct { diff --git a/types/transaction_test.go b/types/transaction_test.go new file mode 100644 index 0000000..e7451b1 --- /dev/null +++ b/types/transaction_test.go @@ -0,0 +1,15 @@ +// Copyright (c) 2017-2026 Lethean (https://lt.hn) +// +// Licensed under the European Union Public Licence (EUPL) version 1.2. +// SPDX-License-Identifier: EUPL-1.2 + +package types + +import "testing" + +func TestTxOutToKey_TargetType_Good(t *testing.T) { + var target TxOutTarget = TxOutToKey{Key: PublicKey{1}, MixAttr: 0} + if target.TargetType() != TargetTypeToKey { + t.Errorf("TargetType: got %d, want %d", target.TargetType(), TargetTypeToKey) + } +}