-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathutxo.go
54 lines (46 loc) · 1.49 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
package bt
import (
"encoding/hex"
"github.com/libsv/go-bt/v2/bscript"
)
// UTXO an unspent transaction output, used for creating inputs
type UTXO struct {
TxID []byte `json:"txid"`
Vout uint32 `json:"vout"`
LockingScript *bscript.Script `json:"locking_script"`
Satoshis uint64 `json:"satoshis"`
SequenceNumber uint32 `json:"sequence_number"`
Unlocker *Unlocker `json:"-"`
}
// 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()
}