-
Notifications
You must be signed in to change notification settings - Fork 95
/
output_basic.go
125 lines (101 loc) · 3.21 KB
/
output_basic.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package iotago
import (
"github.com/iotaledger/hive.go/serializer/v2"
)
type (
BasicOutputUnlockCondition interface{ UnlockCondition }
BasicOutputFeature interface{ Feature }
BasicOutputUnlockConditions = UnlockConditions[BasicOutputUnlockCondition]
BasicOutputFeatures = Features[BasicOutputFeature]
)
// BasicOutputs is a slice of BasicOutput(s).
type BasicOutputs []*BasicOutput
// BasicOutput is an output type which can hold native tokens and features.
type BasicOutput struct {
// The amount of IOTA tokens held by the output.
Amount BaseToken `serix:""`
// The stored mana held by the output.
Mana Mana `serix:""`
// The unlock conditions on this output.
UnlockConditions BasicOutputUnlockConditions `serix:",omitempty"`
// The features on the output.
Features BasicOutputFeatures `serix:",omitempty"`
}
// IsSimpleTransfer tells whether this BasicOutput fulfills the criteria of being a simple transfer.
func (e *BasicOutput) IsSimpleTransfer() bool {
return len(e.FeatureSet()) == 0 && len(e.UnlockConditionSet()) == 1
}
func (e *BasicOutput) Clone() Output {
return &BasicOutput{
Amount: e.Amount,
Mana: e.Mana,
UnlockConditions: e.UnlockConditions.Clone(),
Features: e.Features.Clone(),
}
}
func (e *BasicOutput) Equal(other Output) bool {
otherOutput, isSameType := other.(*BasicOutput)
if !isSameType {
return false
}
if e.Amount != otherOutput.Amount {
return false
}
if e.Mana != otherOutput.Mana {
return false
}
if !e.UnlockConditions.Equal(otherOutput.UnlockConditions) {
return false
}
if !e.Features.Equal(otherOutput.Features) {
return false
}
return true
}
func (e *BasicOutput) UnlockableBy(addr Address, pastBoundedSlotIndex SlotIndex, futureBoundedSlotIndex SlotIndex) bool {
ok, _ := outputUnlockableBy(e, nil, addr, pastBoundedSlotIndex, futureBoundedSlotIndex)
return ok
}
func (e *BasicOutput) StorageScore(storageScoreStruct *StorageScoreStructure, _ StorageScoreFunc) StorageScore {
return storageScoreStruct.OffsetOutput +
storageScoreStruct.FactorData().Multiply(StorageScore(e.Size())) +
e.UnlockConditions.StorageScore(storageScoreStruct, nil) +
e.Features.StorageScore(storageScoreStruct, nil)
}
func (e *BasicOutput) WorkScore(workScoreParameters *WorkScoreParameters) (WorkScore, error) {
workScoreConditions, err := e.UnlockConditions.WorkScore(workScoreParameters)
if err != nil {
return 0, err
}
workScoreFeatures, err := e.Features.WorkScore(workScoreParameters)
if err != nil {
return 0, err
}
return workScoreParameters.Output.Add(workScoreConditions, workScoreFeatures)
}
func (e *BasicOutput) FeatureSet() FeatureSet {
return e.Features.MustSet()
}
func (e *BasicOutput) UnlockConditionSet() UnlockConditionSet {
return e.UnlockConditions.MustSet()
}
func (e *BasicOutput) BaseTokenAmount() BaseToken {
return e.Amount
}
func (e *BasicOutput) StoredMana() Mana {
return e.Mana
}
func (e *BasicOutput) Owner() Address {
return e.UnlockConditions.MustSet().Address().Address
}
func (e *BasicOutput) Type() OutputType {
return OutputBasic
}
func (e *BasicOutput) Size() int {
// OutputType
return serializer.OneByte +
BaseTokenSize +
ManaSize +
e.UnlockConditions.Size() +
e.Features.Size()
}