@@ -6,29 +6,39 @@ import (
66 "gorm.io/datatypes"
77)
88
9- // UserUtxos is a table holding user's Unspent Transaction Outputs (UTXOs).
10- // TODO: It should be renamed to UserUTXO.
11- type UserUtxos struct {
12- UserID string `gorm:"primaryKey;uniqueIndex:idx_window,sort:asc,priority:1"`
13- TxID string `gorm:"primaryKey;uniqueIndex:idx_window,sort:asc,priority:4"`
14- Vout uint32 `gorm:"primaryKey;uniqueIndex:idx_window,sort:asc,priority:5"`
15- Satoshis uint64
16- UnlockingScriptEstimatedSize uint64
17- Bucket string `gorm:"check:chk_not_data_bucket,bucket <> 'data'"`
18- CreatedAt time.Time `gorm:"uniqueIndex:idx_window,sort:asc,priority:3"`
19- TouchedAt time.Time `gorm:"uniqueIndex:idx_window,sort:asc,priority:2"`
20- CustomInstructions datatypes.JSONSlice [CustomInstruction ]
9+ // EstimatedInputSizeForP2PKH is the estimated size increase when adding and unlocking P2PKH input to transaction.
10+ // 32 bytes txID
11+ // + 4 bytes vout index
12+ // + 1 byte script length
13+ // + 107 bytes script pub key
14+ // + 4 bytes nSequence
15+ const EstimatedInputSizeForP2PKH = 148
16+
17+ // UserUTXO is a table holding user's Unspent Transaction Outputs (UTXOs).
18+ type UserUTXO struct {
19+ UserID string `gorm:"primaryKey;uniqueIndex:idx_window,sort:asc,priority:1"`
20+ TxID string `gorm:"primaryKey;uniqueIndex:idx_window,sort:asc,priority:4"`
21+ Vout uint32 `gorm:"primaryKey;uniqueIndex:idx_window,sort:asc,priority:5"`
22+ Satoshis uint64
23+ // EstimatedInputSize is the estimated size increase when adding and unlocking this UTXO to a transaction.
24+ EstimatedInputSize uint64
25+ Bucket string `gorm:"check:chk_not_data_bucket,bucket <> 'data'"`
26+ CreatedAt time.Time `gorm:"uniqueIndex:idx_window,sort:asc,priority:3"`
27+ // TouchedAt is the time when the UTXO was last touched (selected for preparing transaction outline) - used for prioritizing UTXO selection.
28+ TouchedAt time.Time `gorm:"uniqueIndex:idx_window,sort:asc,priority:2"`
29+ // CustomInstructions is the list of instructions for unlocking given UTXO (it should be understood by client).
30+ CustomInstructions datatypes.JSONSlice [CustomInstruction ]
2131}
2232
23- // NewP2PKHUserUTXO creates a new UserUtxos instance for a P2PKH output based on the given output and custom instructions.
24- func NewP2PKHUserUTXO (output * TrackedOutput , customInstructions datatypes.JSONSlice [CustomInstruction ]) * UserUtxos {
25- return & UserUtxos {
26- UserID : output .UserID ,
27- TxID : output .TxID ,
28- Vout : output .Vout ,
29- Satoshis : uint64 (output .Satoshis ),
30- UnlockingScriptEstimatedSize : 106 ,
31- Bucket : "bsv" ,
32- CustomInstructions : customInstructions ,
33+ // NewP2PKHUserUTXO creates a new UserUTXO instance for a P2PKH output based on the given output and custom instructions.
34+ func NewP2PKHUserUTXO (output * TrackedOutput , customInstructions datatypes.JSONSlice [CustomInstruction ]) * UserUTXO {
35+ return & UserUTXO {
36+ UserID : output .UserID ,
37+ TxID : output .TxID ,
38+ Vout : output .Vout ,
39+ Satoshis : uint64 (output .Satoshis ),
40+ EstimatedInputSize : EstimatedInputSizeForP2PKH ,
41+ Bucket : "bsv" ,
42+ CustomInstructions : customInstructions ,
3343 }
3444}
0 commit comments