forked from elastos/Elastos.ELA
/
input.go
51 lines (42 loc) · 1022 Bytes
/
input.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
package core
import (
"bytes"
"encoding/hex"
"fmt"
"io"
. "github.com/elastos/Elastos.ELA.Utility/common"
)
type Input struct {
// Reference outpoint of this input
Previous OutPoint
// Sequence number
Sequence uint32
}
func (i *Input) Serialize(w io.Writer) error {
return WriteElements(w, i.Previous.TxID, i.Previous.Index, i.Sequence)
}
func (i *Input) Deserialize(r io.Reader) error {
return ReadElements(r, &i.Previous.TxID, &i.Previous.Index, &i.Sequence)
}
func (i *Input) ReferKey() string {
buf := new(bytes.Buffer)
i.Previous.Serialize(buf)
hash := Sha256D(buf.Bytes())
return hex.EncodeToString(hash[:])
}
func (i *Input) IsEqual(o Input) bool {
if !i.Previous.IsEqual(o.Previous) {
return false
}
if i.Sequence != o.Sequence {
return false
}
return true
}
func (o Input) String() string {
return "{\n\t\t" +
"tx id: " + o.Previous.TxID.String() + "\n\t\t" +
"index: " + fmt.Sprint(o.Previous.Index) + "\n\t\t" +
"sequence: " + fmt.Sprint(o.Sequence) + "\n\t\t" +
"}"
}