Skip to content

Commit

Permalink
upgrade mobile wallets db to badgerbd
Browse files Browse the repository at this point in the history
  • Loading branch information
dreacot committed Oct 24, 2024
1 parent 2b2d178 commit a7d2b96
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 6 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ require (
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
Expand All @@ -203,6 +203,7 @@ require (
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yeqown/reedsolomon v1.0.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
github.com/zquestz/grab v0.0.0-20190224022517-abcee96e61b1 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/net v0.28.0 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
Expand Down Expand Up @@ -1448,6 +1449,8 @@ github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c/go.mod h1:/PevMnwAx
github.com/shirou/gopsutil v0.0.0-20180427012116-c95755e4bcd7/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil/v3 v3.21.4/go.mod h1:ghfMypLDrFSWN2c9cDYFLHyynQ+QUht0cv/18ZqVczw=
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk=
Expand Down Expand Up @@ -1611,6 +1614,8 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
github.com/zquestz/grab v0.0.0-20190224022517-abcee96e61b1 h1:1qKTeMTSIEvRIjvVYzgcRp0xVp0eoiRTTiHSncb5gD8=
github.com/zquestz/grab v0.0.0-20190224022517-abcee96e61b1/go.mod h1:bslhAiUxakrA6z6CHmVyvkfpnxx18RJBwVyx2TluJWw=
go.etcd.io/bbolt v1.3.0/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
Expand Down
5 changes: 5 additions & 0 deletions libwallet/assets_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,11 @@ func (mgr *AssetsManager) LogDir() string {
return filepath.Join(mgr.params.RootDir, logFileName)
}

// DBDriver returns the db driver in use
func (mgr *AssetsManager) DBDriver() string {
return mgr.params.DbDriver
}

// OpenWallets opens all wallets in the assets manager.
func (mgr *AssetsManager) OpenWallets(startupPassphrase string) error {
for _, wallet := range mgr.AllWallets() {
Expand Down
85 changes: 80 additions & 5 deletions ui/page/start_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package page

import (
"context"
"fmt"
"os"
"strings"
"time"

gioApp "gioui.org/app"
"gioui.org/font"
"gioui.org/layout"
"gioui.org/text"
Expand All @@ -14,6 +16,7 @@ import (
"golang.org/x/text/language"

"github.com/crypto-power/cryptopower/app"
"github.com/crypto-power/cryptopower/appos"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
libutils "github.com/crypto-power/cryptopower/libwallet/utils"
"github.com/crypto-power/cryptopower/ui/cryptomaterial"
Expand All @@ -24,6 +27,7 @@ import (
"github.com/crypto-power/cryptopower/ui/page/settings"
"github.com/crypto-power/cryptopower/ui/preference"
"github.com/crypto-power/cryptopower/ui/values"
"github.com/shirou/gopsutil/mem"
)

const (
Expand Down Expand Up @@ -140,12 +144,13 @@ func (sp *startPage) OnNavigatedTo() {
sp.setLanguagePref(true)
// Set the log levels.
sp.AssetsManager.GetLogLevels()
if sp.AssetsManager.IsStartupSecuritySet() {
sp.unlock()
} else {
sp.loading = true
go func() { _ = sp.openWalletsAndDisplayHomePage("") }()
// Mobile devices usually have very limited amount of ram available to an application
// Ensure mobile users are using badgedb
if appos.Current().IsMobile() {
sp.checkDBFile()
return
}
sp.checkStartupSecurityAndStartApp()
} else {
sp.loading = false
}
Expand Down Expand Up @@ -729,3 +734,73 @@ func (sp *startPage) updateSettings() {
sp.AssetsManager.SetHTTPAPIPrivacyMode(libutils.VspAPI, true)
sp.AssetsManager.SetHTTPAPIPrivacyMode(libutils.UpdateAPI, true)
}

func (sp *startPage) checkDBFile() {
isNewDB := sp.AssetsManager.DBDriver() == "badgerdb"
numberOfRam, err := getNumberOfRam()

Check failure on line 740 in ui/page/start_page.go

View workflow job for this annotation

GitHub Actions / Build

var-naming: var numberOfRam should be numberOfRAM (revive)

Check warning on line 740 in ui/page/start_page.go

View workflow job for this annotation

GitHub Actions / Build

var-naming: var numberOfRam should be numberOfRAM (revive)
if err != nil {
log.Errorf("Error getting number of ram: %v", err)
return
}
fmt.Println("number of ram", numberOfRam)

if numberOfRam < 4 && !isNewDB {
sp.showRemoveWalletWarning()
return
}

sp.checkStartupSecurityAndStartApp()
}

func (sp *startPage) checkStartupSecurityAndStartApp() {
if sp.AssetsManager.IsStartupSecuritySet() {
sp.unlock()
} else {
sp.loading = true
go func() { _ = sp.openWalletsAndDisplayHomePage("") }()
}
}

func (sp *startPage) clearAppDir() {
homeDir, err := gioApp.DataDir()
if err != nil {
log.Error("unable to get home dir: %v", err)
// return nil, fmt.Errorf("unable to get android home dir: %v", err)
}

err = os.RemoveAll(homeDir)
if err != nil {
// If an error occurs, handle it (e.g., log it or show a message)
// showErrorMessage(err)
log.Error("unable to remove home dir: %v", err)
return
}
}

func (sp *startPage) showRemoveWalletWarning() {
warningModal := modal.NewCustomModal(sp.Load).
Title(values.String(values.StrDataFileErrorTitle)).
Body(values.String(values.StrDataFileErrorBody)).
SetNegativeButtonText(values.String(values.StrCancel)).
SetNegativeButtonCallback(func() {
sp.checkStartupSecurityAndStartApp()
}).
SetNegativeButtonText(values.String(values.StrNo)).
PositiveButtonStyle(sp.Theme.Color.Surface, sp.Theme.Color.Danger).
SetPositiveButtonText(values.String(values.StrYes)).
SetPositiveButtonCallback(func(_ bool, _ *modal.InfoModal) bool {
sp.clearAppDir()
return true
})
sp.ParentWindow().ShowModal(warningModal)
}

// Function to get the number of RAM in GB
func getNumberOfRam() (int, error) {

Check failure on line 799 in ui/page/start_page.go

View workflow job for this annotation

GitHub Actions / Build

var-naming: func getNumberOfRam should be getNumberOfRAM (revive)

Check warning on line 799 in ui/page/start_page.go

View workflow job for this annotation

GitHub Actions / Build

var-naming: func getNumberOfRam should be getNumberOfRAM (revive)
vmStat, err := mem.VirtualMemory()
if err != nil {
return 0, err
}
// Convert bytes to gigabytes
return int(vmStat.Total / (1024 * 1024 * 1024)), nil
}
19 changes: 19 additions & 0 deletions ui/page/wallet/wallet_settings_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,25 @@ func (pg *SettingsPage) generalSection() layout.Widget {
func (pg *SettingsPage) debug() layout.Widget {
dim := func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Inset{
Bottom: values.MarginPadding24,
}.Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
databaseTypeLabel := pg.Theme.Label(values.TextSizeTransform(pg.Load.IsMobileView(), values.TextSize16), values.String(values.StrDatabaseType))
return databaseTypeLabel.Layout(gtx)
}),
layout.Flexed(1, func(gtx C) D {
return layout.E.Layout(gtx, func(gtx C) D {
dbDriverLabel := pg.Theme.Label(values.TextSizeTransform(pg.Load.IsMobileView(), values.TextSize16), pg.AssetsManager.DBDriver())
dbDriverLabel.Color = pg.Theme.Color.GrayText2
return dbDriverLabel.Layout(gtx)
})
}),
)
})
}),
layout.Rigid(pg.sectionContent(pg.rescan, values.String(values.StrRescanBlockchain))),
layout.Rigid(func(gtx C) D {
if pg.wallet.GetAssetType() == libutils.DCRWalletAsset {
Expand Down
3 changes: 3 additions & 0 deletions ui/values/localizable/en.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,4 +956,7 @@ const EN = `
"privacy" = "Privacy"
"removeRecipient" = "Remove recipient"
"removeRecipientWarning" = "Are you sure you want to proceed with removing the recipient?"
"dataFileErrorTitle" = "Data file error"
"dataFileErrorBody" = "We have detected a problem with your data files from an older version. To fix it, you will need to re-enter your wallet seed phrase. Can you do this now?"
"databaseType" = "Database type"
`
3 changes: 3 additions & 0 deletions ui/values/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -1065,4 +1065,7 @@ const (
StrPrivacy = "privacy"
StrRemoveRecipient = "removeRecipient"
StrRemoveRecipientWarning = "removeRecipientWarning"
StrDataFileErrorTitle = "dataFileErrorTitle"
StrDataFileErrorBody = "dataFileErrorBody"
StrDatabaseType = "databaseType"
)

0 comments on commit a7d2b96

Please sign in to comment.