@@ -7,84 +7,6 @@ import (
7
7
"errors"
8
8
)
9
9
10
- /*
11
- todo needs a routine that cleans up the tweak data if no more utxos exist for a tx.
12
- The routine will then remove the corresponding tweak data from the db for every txid without light utxos.
13
- In an optimal implementation this should not be needed though.
14
- */
15
-
16
- func removeSpentUTXOsAndTweaks (utxos []types.UTXO ) error {
17
- // First delete the old UTXOs
18
- err := dblevel .DeleteBatchUTXOs (utxos )
19
- if err != nil {
20
- common .ErrorLogger .Println (err )
21
- return err
22
- }
23
-
24
- // Now begin process to find the tweaks that need to be deleted
25
-
26
- // we only need to check for one utxo per txid, so we reduce the number of utxos -> fewer lookups in DB
27
- var cleanUTXOs []types.UTXO
28
- includedTxids := make (map [string ]bool )
29
-
30
- for _ , utxo := range utxos {
31
- if _ , exists := includedTxids [utxo .Txid ]; ! exists {
32
- cleanUTXOs = append (cleanUTXOs , utxo )
33
- includedTxids [utxo .Txid ] = true
34
- }
35
- }
36
-
37
- var tweaksToDelete []types.Tweak
38
- var tweaksToOverwrite []types.Tweak
39
-
40
- for _ , utxo := range cleanUTXOs {
41
- var remainingUTXOs []types.UTXO
42
- remainingUTXOs , err = dblevel .FetchByBlockHashAndTxidUTXOs (utxo .BlockHash , utxo .Txid )
43
- if err != nil && ! errors .Is (err , dblevel.NoEntryErr {}) {
44
- common .ErrorLogger .Println (err )
45
- return err
46
- } else if err != nil && errors .Is (err , dblevel.NoEntryErr {}) {
47
- // if no UTXOs are left for a certain blockHash-txid combination we can remove the tweak
48
- tweaksToDelete = append (tweaksToDelete , types.Tweak {
49
- // we only need those Fields to serialise the key
50
- BlockHash : utxo .BlockHash ,
51
- Txid : utxo .Txid ,
52
- })
53
- continue
54
- }
55
- var newBiggest * uint64
56
- newBiggest , err = types .FindBiggestRemainingUTXO (utxo , remainingUTXOs )
57
- if err != nil {
58
- common .ErrorLogger .Println (err )
59
- return err
60
- }
61
- if newBiggest != nil {
62
- // find the biggest UTXO for the tx and overwrite if necessary
63
- tweaksToOverwrite = append (tweaksToOverwrite , types.Tweak {
64
- BlockHash : utxo .BlockHash ,
65
- BlockHeight : 0 ,
66
- Txid : utxo .Txid ,
67
- Data : [33 ]byte {},
68
- HighestValue : * newBiggest ,
69
- })
70
- }
71
- }
72
-
73
- err = dblevel .DeleteBatchTweaks (tweaksToDelete )
74
- if err != nil {
75
- common .ErrorLogger .Println (err )
76
- return err
77
- }
78
-
79
- err = dblevel .OverWriteTweaks (tweaksToOverwrite )
80
- if err != nil {
81
- common .ErrorLogger .Println (err )
82
- return err
83
- }
84
-
85
- return err
86
- }
87
-
88
10
func overwriteUTXOsWithLookUp (utxos []types.UTXO ) error {
89
11
var utxosToOverwrite []types.UTXO
90
12
0 commit comments