github.com/piotrnar/gocoin@v0.0.0-20240512203912-faa0448c5e96/tools/utxo_decompress/utxo_decompress.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "strings" 7 8 "github.com/piotrnar/gocoin/lib/others/sys" 9 "github.com/piotrnar/gocoin/lib/utxo" 10 ) 11 12 func main() { 13 var dir = "" 14 15 if len(os.Args) > 1 { 16 dir = os.Args[1] 17 } 18 19 if dir != "" && !strings.HasSuffix(dir, string(os.PathSeparator)) { 20 dir += string(os.PathSeparator) 21 } 22 23 sys.LockDatabaseDir(dir) 24 defer sys.UnlockDatabaseDir() 25 26 db := utxo.NewUnspentDb(&utxo.NewUnspentOpts{Dir: dir}) 27 if db == nil { 28 println("UTXO.db not found.") 29 return 30 } 31 32 if !db.ComprssedUTXO { 33 fmt.Println("UTXO.db is not compressed.") 34 return 35 } 36 37 fmt.Println("Decompressing UTXO records") 38 for i := range db.HashMap { 39 for k, v := range db.HashMap[i] { 40 rec := utxo.NewUtxoRecStatic(k, v) 41 db.HashMap[i][k] = utxo.SerializeU(rec, false, nil) 42 } 43 } 44 db.ComprssedUTXO = false 45 db.DirtyDB.Set() 46 fmt.Println("Saving new UTXO.db") 47 db.Close() 48 fmt.Println("Done") 49 fmt.Println("WARNING: the undo folder has not been converted") 50 }