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 <charon@lethean.io>
This commit is contained in:
parent
5a53c719de
commit
00e83582b7
2 changed files with 24 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
15
types/transaction_test.go
Normal file
15
types/transaction_test.go
Normal file
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue