-
Notifications
You must be signed in to change notification settings - Fork 95
/
output_account.go
177 lines (146 loc) · 5.14 KB
/
output_account.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package iotago
import (
"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/serializer/v2"
)
var (
// ErrImplicitAccountDestructionDisallowed gets returned if an implicit account is destroyed, which is not allowed.
ErrImplicitAccountDestructionDisallowed = ierrors.New("cannot destroy implicit account; must be transitioned to account")
// ErrMultipleImplicitAccountCreationAddresses gets return when there is more than one
// Implicit Account Creation Address on the input side of a transaction.
ErrMultipleImplicitAccountCreationAddresses = ierrors.New("multiple implicit account creation addresses on the input side")
// ErrAccountInvalidFoundryCounter gets returned when the foundry counter in an account decreased
// or did not increase by the number of new foundries.
ErrAccountInvalidFoundryCounter = ierrors.New("foundry counter in account decreased or did not increase by the number of new foundries")
)
type (
AccountOutputUnlockCondition interface{ UnlockCondition }
AccountOutputFeature interface{ Feature }
AccountOutputImmFeature interface{ Feature }
AccountOutputUnlockConditions = UnlockConditions[AccountOutputUnlockCondition]
AccountOutputFeatures = Features[AccountOutputFeature]
AccountOutputImmFeatures = Features[AccountOutputImmFeature]
)
// AccountOutput is an output type which represents an account.
type AccountOutput struct {
// The amount of IOTA tokens held by the output.
Amount BaseToken `serix:""`
// The stored mana held by the output.
Mana Mana `serix:""`
// The identifier for this account.
AccountID AccountID `serix:""`
// The counter that denotes the number of foundries created by this account.
FoundryCounter uint32 `serix:""`
// The unlock conditions on this output.
UnlockConditions AccountOutputUnlockConditions `serix:",omitempty"`
// The features on the output.
Features AccountOutputFeatures `serix:",omitempty"`
// The immutable feature on the output.
ImmutableFeatures AccountOutputImmFeatures `serix:",omitempty"`
}
func (a *AccountOutput) Clone() Output {
return &AccountOutput{
Amount: a.Amount,
Mana: a.Mana,
AccountID: a.AccountID,
FoundryCounter: a.FoundryCounter,
UnlockConditions: a.UnlockConditions.Clone(),
Features: a.Features.Clone(),
ImmutableFeatures: a.ImmutableFeatures.Clone(),
}
}
func (a *AccountOutput) Equal(other Output) bool {
otherOutput, isSameType := other.(*AccountOutput)
if !isSameType {
return false
}
if a.Amount != otherOutput.Amount {
return false
}
if a.Mana != otherOutput.Mana {
return false
}
if a.AccountID != otherOutput.AccountID {
return false
}
if a.FoundryCounter != otherOutput.FoundryCounter {
return false
}
if !a.UnlockConditions.Equal(otherOutput.UnlockConditions) {
return false
}
if !a.Features.Equal(otherOutput.Features) {
return false
}
if !a.ImmutableFeatures.Equal(otherOutput.ImmutableFeatures) {
return false
}
return true
}
func (a *AccountOutput) UnlockableBy(addr Address, pastBoundedSlotIndex SlotIndex, futureBoundedSlotIndex SlotIndex) bool {
ok, _ := outputUnlockableBy(a, nil, addr, pastBoundedSlotIndex, futureBoundedSlotIndex)
return ok
}
func (a *AccountOutput) StorageScore(storageScoreStruct *StorageScoreStructure, _ StorageScoreFunc) StorageScore {
return storageScoreStruct.OffsetOutput +
storageScoreStruct.FactorData().Multiply(StorageScore(a.Size())) +
a.UnlockConditions.StorageScore(storageScoreStruct, nil) +
a.Features.StorageScore(storageScoreStruct, nil) +
a.ImmutableFeatures.StorageScore(storageScoreStruct, nil)
}
func (a *AccountOutput) WorkScore(workScoreParameters *WorkScoreParameters) (WorkScore, error) {
workScoreConditions, err := a.UnlockConditions.WorkScore(workScoreParameters)
if err != nil {
return 0, err
}
workScoreFeatures, err := a.Features.WorkScore(workScoreParameters)
if err != nil {
return 0, err
}
workScoreImmutableFeatures, err := a.ImmutableFeatures.WorkScore(workScoreParameters)
if err != nil {
return 0, err
}
return workScoreParameters.Output.Add(workScoreConditions, workScoreFeatures, workScoreImmutableFeatures)
}
func (a *AccountOutput) Owner() Address {
return a.UnlockConditions.MustSet().Address().Address
}
func (a *AccountOutput) ChainID() ChainID {
return a.AccountID
}
func (a *AccountOutput) FeatureSet() FeatureSet {
return a.Features.MustSet()
}
func (a *AccountOutput) UnlockConditionSet() UnlockConditionSet {
return a.UnlockConditions.MustSet()
}
func (a *AccountOutput) ImmutableFeatureSet() FeatureSet {
return a.ImmutableFeatures.MustSet()
}
func (a *AccountOutput) BaseTokenAmount() BaseToken {
return a.Amount
}
func (a *AccountOutput) StoredMana() Mana {
return a.Mana
}
func (a *AccountOutput) Target() (Address, error) {
addr := new(AccountAddress)
copy(addr[:], a.AccountID[:])
return addr, nil
}
func (a *AccountOutput) Type() OutputType {
return OutputAccount
}
func (a *AccountOutput) Size() int {
// OutputType
return serializer.OneByte +
BaseTokenSize +
ManaSize +
AccountIDLength +
// FoundryCounter
serializer.UInt32ByteSize +
a.UnlockConditions.Size() +
a.Features.Size() +
a.ImmutableFeatures.Size()
}