-
Notifications
You must be signed in to change notification settings - Fork 12
/
state_reference.go
53 lines (42 loc) · 1.26 KB
/
state_reference.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
package mempool
import (
"github.com/iotaledger/hive.go/lo"
iotago "github.com/iotaledger/iota.go/v4"
)
// A reference to a state (like an output or a commitment).
type StateReference interface {
// The identifier of the state to which it resolves.
ReferencedStateID() iotago.Identifier
// The type of state.
Type() StateType
}
// A thin wrapper around a UTXO input.
type UTXOInputStateRef struct {
Input *iotago.UTXOInput
}
func (r UTXOInputStateRef) ReferencedStateID() iotago.Identifier {
return iotago.IdentifierFromData(lo.PanicOnErr(r.Input.OutputID().Bytes()))
}
func (r UTXOInputStateRef) Type() StateType {
return StateTypeUTXOInput
}
func UTXOInputStateRefFromInput(input *iotago.UTXOInput) UTXOInputStateRef {
return UTXOInputStateRef{
Input: input,
}
}
// A thin wrapper around a Commitment input.
type CommitmentInputStateRef struct {
Input *iotago.CommitmentInput
}
func (r CommitmentInputStateRef) ReferencedStateID() iotago.Identifier {
return iotago.IdentifierFromData(lo.PanicOnErr(r.Input.CommitmentID.Bytes()))
}
func (r CommitmentInputStateRef) Type() StateType {
return StateTypeCommitment
}
func CommitmentInputStateRefFromInput(input *iotago.CommitmentInput) CommitmentInputStateRef {
return CommitmentInputStateRef{
Input: input,
}
}