-
Notifications
You must be signed in to change notification settings - Fork 95
/
input_utxo.go
78 lines (63 loc) · 1.93 KB
/
input_utxo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package iotago
import (
"encoding/binary"
"github.com/iotaledger/hive.go/serializer/v2"
)
const (
// RefUTXOIndexMin is the minimum index of a referenced UTXO.
RefUTXOIndexMin = 0
// RefUTXOIndexMax is the maximum index of a referenced UTXO.
RefUTXOIndexMax = MaxOutputsCount - 1
)
// UTXOInput references an unspent transaction output by the Transaction's ID and the corresponding index of the Output.
type UTXOInput struct {
// The transaction ID of the referenced transaction.
TransactionID TransactionID `serix:""`
// The output index of the output on the referenced transaction.
TransactionOutputIndex uint16 `serix:""`
}
func (u *UTXOInput) Clone() Input {
return &UTXOInput{
TransactionID: u.TransactionID,
TransactionOutputIndex: u.TransactionOutputIndex,
}
}
func (u *UTXOInput) Type() InputType {
return InputUTXO
}
func (u *UTXOInput) IsReadOnly() bool {
return false
}
func (u *UTXOInput) OutputID() OutputID {
var id OutputID
copy(id[:TransactionIDLength], u.TransactionID[:])
binary.LittleEndian.PutUint16(id[TransactionIDLength:], u.TransactionOutputIndex)
return id
}
func (u *UTXOInput) Index() uint16 {
return u.TransactionOutputIndex
}
// CreationSlot returns the slot the Output was created in.
func (u *UTXOInput) CreationSlot() SlotIndex {
return u.TransactionID.Slot()
}
func (u *UTXOInput) Equals(other *UTXOInput) bool {
if u == nil {
return other == nil
}
if other == nil {
return false
}
if u.TransactionID != other.TransactionID {
return false
}
return u.TransactionOutputIndex == other.TransactionOutputIndex
}
func (u *UTXOInput) Size() int {
// InputType + TransactionID + TransactionOutputIndex
return serializer.SmallTypeDenotationByteSize + TransactionIDLength + OutputIndexLength
}
func (u *UTXOInput) WorkScore(workScoreParameters *WorkScoreParameters) (WorkScore, error) {
// inputs require lookup of the UTXO, so requires extra work.
return workScoreParameters.Input, nil
}