From 30d174eaac9af23f9b38f044b9783b898faadf1b Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Mar 2026 20:27:01 +0000 Subject: [PATCH] feat(types): add TxOutMultisig and TxOutHTLC target types Output target types for HF1 HTLC and multisig transactions. Co-Authored-By: Charon --- types/transaction.go | 24 ++++++++++++++++++++++++ types/transaction_test.go | 17 +++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/types/transaction.go b/types/transaction.go index 71b74f0..2dc1a47 100644 --- a/types/transaction.go +++ b/types/transaction.go @@ -131,6 +131,30 @@ type TxOutToKey struct { // TargetType returns the wire variant tag for to_key targets. func (t TxOutToKey) TargetType() uint8 { return TargetTypeToKey } +// TxOutMultisig is the txout_multisig target variant (HF1+). +// Spendable when minimum_sigs of the listed keys sign. +type TxOutMultisig struct { + MinimumSigs uint64 + Keys []PublicKey +} + +// TargetType returns the wire variant tag for multisig targets. +func (t TxOutMultisig) TargetType() uint8 { return TargetTypeMultisig } + +// TxOutHTLC is the txout_htlc target variant (HF1+). +// Hash Time-Locked Contract: redeemable with hash preimage before +// expiration, refundable after expiration. +type TxOutHTLC struct { + HTLCHash Hash // 32-byte hash lock + Flags uint8 // bit 0: 0=SHA256, 1=RIPEMD160 + Expiration uint64 // block height deadline + PKRedeem PublicKey // recipient key (can redeem before expiration) + PKRefund PublicKey // sender key (can refund after expiration) +} + +// TargetType returns the wire variant tag for HTLC targets. +func (t TxOutHTLC) TargetType() uint8 { return TargetTypeHTLC } + // 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 index e7451b1..5b35974 100644 --- a/types/transaction_test.go +++ b/types/transaction_test.go @@ -13,3 +13,20 @@ func TestTxOutToKey_TargetType_Good(t *testing.T) { t.Errorf("TargetType: got %d, want %d", target.TargetType(), TargetTypeToKey) } } + +func TestTxOutMultisig_TargetType_Good(t *testing.T) { + var target TxOutTarget = TxOutMultisig{MinimumSigs: 2, Keys: []PublicKey{{1}, {2}}} + if target.TargetType() != TargetTypeMultisig { + t.Errorf("TargetType: got %d, want %d", target.TargetType(), TargetTypeMultisig) + } +} + +func TestTxOutHTLC_TargetType_Good(t *testing.T) { + var target TxOutTarget = TxOutHTLC{ + Flags: 0, + Expiration: 10080, + } + if target.TargetType() != TargetTypeHTLC { + t.Errorf("TargetType: got %d, want %d", target.TargetType(), TargetTypeHTLC) + } +}