forked from libsv/go-bt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utxo.go
53 lines (45 loc) · 1.32 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
package bt
import (
"encoding/hex"
"github.com/sCrypt-Inc/go-bt/v2/bscript"
)
// UTXO an unspent transaction output, used for creating inputs
type UTXO struct {
TxID []byte
Vout uint32
LockingScript *bscript.Script
Satoshis uint64
SequenceNumber uint32
}
// UTXOs a collection of *bt.UTXO.
type UTXOs []*UTXO
// NodeJSON returns a wrapped *bt.UTXO for marshalling/unmarshalling into a node utxo format.
//
// Marshalling usage example:
// bb, err := json.Marshal(utxo.NodeJSON())
//
// Unmarshalling usage example:
// utxo := &bt.UTXO{}
// if err := json.Unmarshal(bb, utxo.NodeJSON()); err != nil {}
func (u *UTXO) NodeJSON() interface{} {
return &nodeUTXOWrapper{UTXO: u}
}
// NodeJSON returns a wrapped bt.UTXOs for marshalling/unmarshalling into a node utxo format.
//
// Marshalling usage example:
// bb, err := json.Marshal(utxos.NodeJSON())
//
// Unmarshalling usage example:
// var txs bt.UTXOs
// if err := json.Unmarshal(bb, utxos.NodeJSON()); err != nil {}
func (u *UTXOs) NodeJSON() interface{} {
return (*nodeUTXOsWrapper)(u)
}
// TxIDStr return the tx id as a string.
func (u *UTXO) TxIDStr() string {
return hex.EncodeToString(u.TxID)
}
// LockingScriptHexString retur nthe locking script in hex format.
func (u *UTXO) LockingScriptHexString() string {
return u.LockingScript.String()
}