forked from elastos/Elastos.ELA
/
outpoint.go
54 lines (44 loc) · 922 Bytes
/
outpoint.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
package core
import (
"bytes"
"io"
. "github.com/elastos/Elastos.ELA.Utility/common"
)
type OutPoint struct {
TxID Uint256
Index uint16
}
func (op *OutPoint) IsEqual(o OutPoint) bool {
if !op.TxID.IsEqual(o.TxID) {
return false
}
if op.Index != o.Index {
return false
}
return true
}
func (op *OutPoint) Serialize(w io.Writer) error {
return WriteElements(w, op.TxID, op.Index)
}
func (op *OutPoint) Deserialize(r io.Reader) error {
return ReadElements(r, &op.TxID, &op.Index)
}
func (op *OutPoint) Bytes() []byte {
buf := new(bytes.Buffer)
op.Serialize(buf)
return buf.Bytes()
}
func NewOutPoint(txId Uint256, index uint16) *OutPoint {
return &OutPoint{
TxID: txId,
Index: index,
}
}
func OutPointFromBytes(value []byte) (*OutPoint, error) {
outPoint := new(OutPoint)
err := outPoint.Deserialize(bytes.NewReader(value))
if err != nil {
return nil, err
}
return outPoint, nil
}