/
unlock_cond_expiration.go
63 lines (51 loc) · 1.99 KB
/
unlock_cond_expiration.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
package iotago
import (
"cmp"
"github.com/iotaledger/hive.go/serializer/v2"
)
// ExpirationUnlockCondition is an unlock condition which puts a time constraint on whether the receiver or return address
// can consume an output depending on the latest confirmed milestone's timestamp T:
// - only the receiver address can consume the output, if T is before than the one defined in the condition.
// - only the return address can consume the output, if T is at the same time or after the one defined in the condition.
type ExpirationUnlockCondition struct {
// The address who is allowed to use the output after the expiration has happened.
ReturnAddress Address `serix:""`
// The slot index at which the expiration happens.
Slot SlotIndex `serix:""`
}
func (s *ExpirationUnlockCondition) Clone() UnlockCondition {
return &ExpirationUnlockCondition{
ReturnAddress: s.ReturnAddress.Clone(),
Slot: s.Slot,
}
}
func (s *ExpirationUnlockCondition) StorageScore(storageScoreStruct *StorageScoreStructure, _ StorageScoreFunc) StorageScore {
return s.ReturnAddress.StorageScore(storageScoreStruct, nil)
}
func (s *ExpirationUnlockCondition) WorkScore(_ *WorkScoreParameters) (WorkScore, error) {
// ExpirationUnlockCondition does not require a signature check on creation, only consumption.
return 0, nil
}
func (s *ExpirationUnlockCondition) Compare(other UnlockCondition) int {
return cmp.Compare(s.Type(), other.Type())
}
func (s *ExpirationUnlockCondition) Equal(other UnlockCondition) bool {
otherCond, is := other.(*ExpirationUnlockCondition)
if !is {
return false
}
switch {
case !s.ReturnAddress.Equal(otherCond.ReturnAddress):
return false
case s.Slot != otherCond.Slot:
return false
}
return true
}
func (s *ExpirationUnlockCondition) Type() UnlockConditionType {
return UnlockConditionExpiration
}
func (s *ExpirationUnlockCondition) Size() int {
// UnlockType + ReturnAddress + SlotIndex
return serializer.SmallTypeDenotationByteSize + s.ReturnAddress.Size() + SlotIndexLength
}