Skip to content

Commit

Permalink
fix pointers and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
yenda committed Dec 19, 2019
1 parent c1facdf commit 4524e74
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 36 deletions.
3 changes: 2 additions & 1 deletion api/geth_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ func (b *GethStatusBackend) saveAccountsAndSettings(settings accounts.Settings,
func (b *GethStatusBackend) loadNodeConfig() (*params.NodeConfig, error) {
b.mu.Lock()
defer b.mu.Unlock()
conf, err := accounts.NewDB(b.appDB).GetNodeConfig()
var conf params.NodeConfig
err := accounts.NewDB(b.appDB).GetNodeConfig(&conf)
if err != nil {
return nil, err
}
Expand Down
20 changes: 10 additions & 10 deletions appdatabase/migrations/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 19 additions & 21 deletions multiaccounts/accounts/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/sqlite"
)

Expand Down Expand Up @@ -84,42 +83,42 @@ type Settings struct {
DappsAddress common.Address `json:"dapps-address"`
// required
EIP1581Address common.Address `json:"eip1581-address"`
Fleet string `json:"fleet,omitempty"`
Fleet *string `json:"fleet,omitempty"`
HideHomeTooltip bool `json:"hide-home-tooltip,omitempty"`
// required
InstallationID string `json:"installation-id"`
// required
KeyUID string `json:"key-uid"`
KeycardInstanceUID string `json:"keycard-instance-uid,omitempty"`
KeycardPAiredOn time.Time `json:"keycard-paired-on,omitempty"`
KeycardPAiredOn int64 `json:"keycard-paired-on,omitempty"`
KeycardPairing string `json:"keycard-pairing,omitempty"`
// required
LatestDerivedPath uint `json:"last-derived-path"`
LogLevel string `json:"log-level,omitempty"`
LogLevel *string `json:"log-level,omitempty"`
Mnemonic string `json:"mnemonic,omitempty"`
// required
Name string `json:"name,omitempty"`
NotificationsEnabled bool `json:"notification-enabled,omitempty"`
// required
PhotoPath string `json:"photo-path"`
PinnedMailserver *json.RawMessage `json:"pinned-mailserver,omitempty"`
PreferredName string `json:"preferred-name,omitempty"`
PreferredName *string `json:"preferred-name,omitempty"`
// required
PreviewPrivacy bool `json:"preview-privacy"`
// required
PublicKey string `json:"public-key"`
RememberSyncingChoice bool `json:"remember-syncing-choice,omitempty"`
ShowName bool `json:"show-name,omitempty"`
ShowName *bool `json:"show-name,omitempty"`
// required
SigningPhrase string `json:"signing-phrase"`
StickerPacksInstalled *json.RawMessage `json:"stickers-packs-installed,omitempty"`
StickersRecentStickers *json.RawMessage `json:"stickers-recent-stickers,omitempty"`
SyncingOnMobileNetwork bool `json:"syncing-on-mobile-network,omitempty"`
Usernames []string `json:"usernames,omitempty"`
Usernames *[]string `json:"usernames,omitempty"`
// required
WalletRootAddress common.Address `json:"wallet-root-address,omitempty"`
WalletSetupPassed bool `json:"wallet-setup-passed,omitempty"`
WalletVisibleTokens []string `json:"wallet-visible-tokens,omitempty"`
WalletVisibleTokens *[]string `json:"wallet-visible-tokens,omitempty"`
}

func NewDB(db *sql.DB) *Database {
Expand All @@ -136,7 +135,7 @@ func (db Database) Close() error {
return db.db.Close()
}

func (db *Database) CreateSettings(s Settings, NodeConfig *params.NodeConfig) error {
func (db *Database) CreateSettings(s Settings, nodecfg interface{}) error {
_, err := db.db.Exec(`
INSERT INTO settings (
address,
Expand All @@ -148,19 +147,19 @@ INSERT INTO settings (
keycard_paired_on,
keycard_pairing,
latest_derived_path,
last_updated,
mnemonic,
name,
node_config,
photo_path,
preview_privacy,
public_key,
signing_phrase,
synthetic_id,
wallet_root_address,
last_updated,
synthetic_id
) VALUES (
?,?,?,?,?,?,?,?,?,datetime('now'),
?,?,?,?,?,?,?,?,?)`,
?,?,?,?,?,?,?,?,?,?,
?,?,?,?,?,?,?,?,'id')`,
s.Address,
s.DappsAddress,
s.EIP1581Address,
Expand All @@ -172,13 +171,13 @@ INSERT INTO settings (
s.LatestDerivedPath,
s.Mnemonic,
s.Name,
&NodeConfig,
&sqlite.JSONBlob{nodecfg},
s.PhotoPath,
s.PreviewPrivacy,
s.PublicKey,
s.SigningPhrase,
"id",
s.WalletRootAddress)
s.WalletRootAddress,
time.Now())

return err
}
Expand All @@ -193,15 +192,14 @@ func (db *Database) SaveSetting(typ string, value interface{}) error {
return err
}

func (db *Database) GetNodeConfig() (params.NodeConfig, error) {
var nodecfg params.NodeConfig
err := db.db.QueryRow("SELECT node_config FROM settings WHERE synthetic_id = 'id'").Scan(&nodecfg)
return nodecfg, err
func (db *Database) GetNodeConfig(nodecfg interface{}) (error) {
err := db.db.QueryRow("SELECT node_config FROM settings WHERE synthetic_id = 'id'").Scan(&sqlite.JSONBlob{nodecfg})
return err
}

func (db *Database) GetSettings() (Settings, error) {
var s Settings
err := db.db.QueryRow("SELECT address, chaos_mode, currency', custom_bootnodes, custom_bootnodes_enabled, dapps_address, eip1581_address, fleet, hide_home_tooltip, installation_id, key_uid, keycard_instance_uid, keycard_paired_on, keycard_pairing, latest_derived_path, log_level, mnemonic, name, notification_enabled, photo_path, pinned_mailserver, preferred_name, preview_privacy, public_key, remember_syncing_choice, show_name, signing_phrase, stickers_packs_installed, stickers_recent_stickers, syncing_on_mobile_network, synthetic_id, usernames, wallet_root_address, wallet_set_up_passed, wallet_visible_tokens FROM settings WHERE synthetic_id = 'id'").Scan(
err := db.db.QueryRow("SELECT address, chaos_mode, currency, custom_bootnodes, custom_bootnodes_enabled, dapps_address, eip1581_address, fleet, hide_home_tooltip, installation_id, key_uid, keycard_instance_uid, keycard_paired_on, keycard_pairing, latest_derived_path, log_level, mnemonic, name, notification_enabled, photo_path, pinned_mailserver, preferred_name, preview_privacy, public_key, remember_syncing_choice, show_name, signing_phrase, stickers_packs_installed, stickers_recent_stickers, syncing_on_mobile_network, usernames, wallet_root_address, wallet_set_up_passed, wallet_visible_tokens FROM settings WHERE synthetic_id = 'id'").Scan(
&s.Address,
&s.ChaosMode,
&s.Currency,
Expand Down
11 changes: 7 additions & 4 deletions multiaccounts/accounts/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import (

var (
addr = common.Address{1}
config = params.NodeConfig{}
config = params.NodeConfig{
NetworkID: 10,
DataDir: "test",
}
settings = Settings{
Address: common.HexToAddress("0xdC540f3745Ff2964AFC1171a5A0DD726d1F6B472"),
DappsAddress: common.HexToAddress("0xD1300f99fDF7346986CbC766903245087394ecd0"),
Expand Down Expand Up @@ -47,7 +50,7 @@ func TestCreateSettings(t *testing.T) {
db, stop := setupTestDB(t)
defer stop()

require.NoError(t, db.CreateSettings(settings, &config))
require.NoError(t, db.CreateSettings(settings, config))

_, err := db.GetSettings()
require.NoError(t, err)
Expand All @@ -57,7 +60,7 @@ func TestSaveSetting(t *testing.T) {
db, stop := setupTestDB(t)
defer stop()

require.NoError(t, db.CreateSettings(settings, &config))
require.NoError(t, db.CreateSettings(settings, config))
require.NoError(t, db.SaveSetting("currency", "usd"))

_, err := db.GetSettings()
Expand All @@ -68,7 +71,7 @@ func TestGetNodeConfig(t *testing.T) {
db, stop := setupTestDB(t)
defer stop()

require.NoError(t, db.CreateSettings(settings, &config))
require.NoError(t, db.CreateSettings(settings, config))

_, err := db.GetSettings()
require.NoError(t, err)
Expand Down

0 comments on commit 4524e74

Please sign in to comment.