github.com/piotrnar/gocoin@v0.0.0-20240512203912-faa0448c5e96/lib/utxo/unspent_rec.go (about) 1 package utxo 2 3 import ( 4 "github.com/piotrnar/gocoin/lib/btc" 5 ) 6 7 /* 8 Each unspent key is 8 bytes long - these are the first 8 bytes of TXID 9 Eech value is variable length: 10 [0:24] - remainig 24 bytes of TxID 11 var_int: BlochHeight 12 var_int: 2*out_cnt + is_coinbase 13 And now set of records: 14 var_int: Output index 15 var_int: Value 16 var_int: PKscrpt_length 17 PKscript 18 ... 19 */ 20 21 type UtxoRec struct { 22 TxID [32]byte 23 Coinbase bool 24 InBlock uint32 25 Outs []*UtxoTxOut 26 } 27 28 type UtxoTxOut struct { 29 Value uint64 30 PKScr []byte 31 } 32 33 var ( 34 sta_rec UtxoRec 35 rec_outs = make([]*UtxoTxOut, 30001) 36 rec_pool = make([]UtxoTxOut, 30001) 37 ) 38 39 var ( 40 FullUtxoRec func(dat []byte) *UtxoRec = FullUtxoRecU 41 NewUtxoRecStatic func(key UtxoKeyType, dat []byte) *UtxoRec = NewUtxoRecStaticU 42 NewUtxoRec func(key UtxoKeyType, dat []byte) *UtxoRec = NewUtxoRecU 43 OneUtxoRec func(key UtxoKeyType, dat []byte, vout uint32) *btc.TxOut = OneUtxoRecU 44 Serialize func(rec *UtxoRec, full bool, use_buf []byte) (buf []byte) = SerializeU 45 ) 46 47 48 func (r *UtxoRec) ToUnspent(idx uint32, ad *btc.BtcAddr) (nr *OneUnspentTx) { 49 nr = new(OneUnspentTx) 50 nr.TxPrevOut.Hash = r.TxID 51 nr.TxPrevOut.Vout = idx 52 nr.Value = r.Outs[idx].Value 53 nr.Coinbase = r.Coinbase 54 nr.MinedAt = r.InBlock 55 nr.BtcAddr = ad 56 nr.destString = ad.String() 57 return 58 }