feat(types): add TxOutMultisig and TxOutHTLC target types
Output target types for HF1 HTLC and multisig transactions. Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
cc99c92c42
commit
30d174eaac
2 changed files with 41 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue