-
Notifications
You must be signed in to change notification settings - Fork 0
/
utxo.go
59 lines (53 loc) · 1.02 KB
/
utxo.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
package transaction
import (
"io"
)
// UTXO represents usable coins in the UTXO model
type UTXO struct {
*TxIn
*TxOut
}
// NewUTXO returns a UTXO
func NewUTXO() *UTXO {
return &UTXO{
TxIn: NewTxIn(0),
TxOut: NewTxOut(),
}
}
// Clone returns the clonend value of it
func (utxo *UTXO) Clone() *UTXO {
return &UTXO{
TxIn: utxo.TxIn.Clone(),
TxOut: utxo.TxOut.Clone(),
}
}
// WriteTo is a serialization function
func (utxo *UTXO) WriteTo(w io.Writer) (int64, error) {
var wrote int64
if n, err := utxo.TxIn.WriteTo(w); err != nil {
return wrote, err
} else {
wrote += n
}
if n, err := utxo.TxOut.WriteTo(w); err != nil {
return wrote, err
} else {
wrote += n
}
return wrote, nil
}
// ReadFrom is a deserialization function
func (utxo *UTXO) ReadFrom(r io.Reader) (int64, error) {
var read int64
if n, err := utxo.TxIn.ReadFrom(r); err != nil {
return read, err
} else {
read += n
}
if n, err := utxo.TxOut.ReadFrom(r); err != nil {
return read, err
} else {
read += n
}
return read, nil
}