diff --git a/api/backend.go b/api/backend.go index 56a2e282f..ea0618226 100644 --- a/api/backend.go +++ b/api/backend.go @@ -16,7 +16,7 @@ type StatusBackend interface { StartNode(config *params.NodeConfig) error // NOTE: Only used in canary StartNodeWithKey(acc multiaccounts.Account, password string, keyHex string) error StartNodeWithAccount(acc multiaccounts.Account, password string) error - StartNodeWithAccountAndConfig(account multiaccounts.Account, password string, conf *params.NodeConfig, subaccs []accounts.Account) error + StartNodeWithAccountAndConfig(account multiaccounts.Account, password string, settings accounts.Settings, conf *params.NodeConfig, subaccs []accounts.Account) error StopNode() error // RestartNode() error // NOTE: Only used in tests @@ -27,7 +27,7 @@ type StatusBackend interface { OpenAccounts() error GetAccounts() ([]multiaccounts.Account, error) // SaveAccount(account multiaccounts.Account) error - SaveAccountAndStartNodeWithKey(acc multiaccounts.Account, password string, conf *params.NodeConfig, subaccs []accounts.Account, keyHex string) error + SaveAccountAndStartNodeWithKey(acc multiaccounts.Account, password string, settings accounts.Settings, conf *params.NodeConfig, subaccs []accounts.Account, keyHex string) error Recover(rpcParams personal.RecoverParams) (types.Address, error) Logout() error diff --git a/api/backend_test.go b/api/backend_test.go index bb5214ed3..a6bd4963b 100644 --- a/api/backend_test.go +++ b/api/backend_test.go @@ -28,6 +28,25 @@ import ( "github.com/stretchr/testify/require" ) +var ( + networks = json.RawMessage("{}") + settings = accounts.Settings{ + Address: types.HexToAddress("0xeC540f3745Ff2964AFC1171a5A0DD726d1F6B472"), + CurrentNetwork: "mainnet_rpc", + DappsAddress: types.HexToAddress("0xe1300f99fDF7346986CbC766903245087394ecd0"), + EIP1581Address: types.HexToAddress("0xe1DDDE9235a541d1344550d969715CF43982de9f"), + InstallationID: "d3efcff6-cffa-560e-a547-21d3858cbc51", + KeyUID: "0x4e8129f3edfc004875be17bf468a784098a9f69b53c095be1f52deff286935ab", + LatestDerivedPath: 0, + Name: "Jittery Cornflowerblue Kingbird", + Networks: &networks, + PhotoPath: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAAjklEQVR4nOzXwQmFMBAAUZXUYh32ZB32ZB02sxYQQSZGsod55/91WFgSS0RM+SyjA56ZRZhFmEWYRRT6h+M6G16zrxv6fdJpmUWYRbxsYr13dKfanpN0WmYRZhGzXz6AWYRZRIfbaX26fT9Jk07LLMIsosPt9I/dTDotswizCG+nhFmEWYRZhFnEHQAA///z1CFkYamgfQAAAABJRU5ErkJggg==", + PreviewPrivacy: false, + PublicKey: "0x04211fe0f69772ecf7eb0b5bfc7678672508a9fb01f2d699096f0d59ef7fe1a0cb1e648a80190db1c0f5f088872444d846f2956d0bd84069f3f9f69335af852ac0", + SigningPhrase: "yurt joey vibe", + WalletRootAddress: types.HexToAddress("0xeB591fd819F86D0A6a2EF2Bcb94f77807a7De1a6")} +) + func TestBackendStartNodeConcurrently(t *testing.T) { utils.Init() @@ -586,7 +605,7 @@ func TestLoginWithKey(t *testing.T) { require.NoError(t, b.OpenAccounts()) address := crypto.PubkeyToAddress(walletKey.PublicKey) - require.NoError(t, b.SaveAccountAndStartNodeWithKey(main, "test-pass", conf, []accounts.Account{{Address: address, Wallet: true}}, keyhex)) + require.NoError(t, b.SaveAccountAndStartNodeWithKey(main, "test-pass", settings, conf, []accounts.Account{{Address: address, Wallet: true}}, keyhex)) require.NoError(t, b.Logout()) require.NoError(t, b.StopNode()) diff --git a/api/geth_backend.go b/api/geth_backend.go index 135efd44a..4dfdd5c7f 100644 --- a/api/geth_backend.go +++ b/api/geth_backend.go @@ -186,26 +186,6 @@ func (b *GethStatusBackend) ensureAppDBOpened(account multiaccounts.Account, pas return nil } -func (b *GethStatusBackend) SaveAccountAndStartNodeWithKey(acc multiaccounts.Account, password string, conf *params.NodeConfig, subaccs []accounts.Account, keyHex string) error { - err := b.SaveAccount(acc) - if err != nil { - return err - } - err = b.ensureAppDBOpened(acc, password) - if err != nil { - return err - } - err = b.saveNodeConfig(conf) - if err != nil { - return err - } - err = accounts.NewDB(b.appDB).SaveAccounts(subaccs) - if err != nil { - return err - } - return b.StartNodeWithKey(acc, password, keyHex) -} - // StartNodeWithKey instead of loading addresses from database this method derives address from key // and uses it in application. // TODO: we should use a proper struct with optional values instead of duplicating the regular functions @@ -322,10 +302,32 @@ func (b *GethStatusBackend) StartNodeWithAccount(acc multiaccounts.Account, pass return err } +func (b *GethStatusBackend) SaveAccountAndStartNodeWithKey(acc multiaccounts.Account, password string, settings accounts.Settings, nodecfg *params.NodeConfig, subaccs []accounts.Account, keyHex string) error { + err := b.SaveAccount(acc) + if err != nil { + return err + } + err = b.ensureAppDBOpened(acc, password) + if err != nil { + return err + } + err = b.saveAccountsAndSettings(settings, nodecfg, subaccs) + if err != nil { + return err + } + return b.StartNodeWithKey(acc, password, keyHex) +} + // StartNodeWithAccountAndConfig is used after account and config was generated. // In current setup account name and config is generated on the client side. Once/if it will be generated on // status-go side this flow can be simplified. -func (b *GethStatusBackend) StartNodeWithAccountAndConfig(account multiaccounts.Account, password string, conf *params.NodeConfig, subaccs []accounts.Account) error { +func (b *GethStatusBackend) StartNodeWithAccountAndConfig( + account multiaccounts.Account, + password string, + settings accounts.Settings, + nodecfg *params.NodeConfig, + subaccs []accounts.Account, +) error { err := b.SaveAccount(account) if err != nil { return err @@ -334,28 +336,29 @@ func (b *GethStatusBackend) StartNodeWithAccountAndConfig(account multiaccounts. if err != nil { return err } - err = b.saveNodeConfig(conf) - if err != nil { - return err - } - err = accounts.NewDB(b.appDB).SaveAccounts(subaccs) + err = b.saveAccountsAndSettings(settings, nodecfg, subaccs) if err != nil { return err } return b.StartNodeWithAccount(account, password) } -func (b *GethStatusBackend) saveNodeConfig(config *params.NodeConfig) error { +func (b *GethStatusBackend) saveAccountsAndSettings(settings accounts.Settings, nodecfg *params.NodeConfig, subaccs []accounts.Account) error { b.mu.Lock() defer b.mu.Unlock() - return accounts.NewDB(b.appDB).SaveConfig(accounts.NodeConfigTag, config) + accdb := accounts.NewDB(b.appDB) + err := accdb.CreateSettings(settings, *nodecfg) + if err != nil { + return err + } + return accdb.SaveAccounts(subaccs) } func (b *GethStatusBackend) loadNodeConfig() (*params.NodeConfig, error) { b.mu.Lock() defer b.mu.Unlock() - conf := params.NodeConfig{} - err := accounts.NewDB(b.appDB).GetConfig(accounts.NodeConfigTag, &conf) + var conf params.NodeConfig + err := accounts.NewDB(b.appDB).GetNodeConfig(&conf) if err != nil { return nil, err } diff --git a/appdatabase/migrations/bindata.go b/appdatabase/migrations/bindata.go index 98038c088..8a099beee 100644 --- a/appdatabase/migrations/bindata.go +++ b/appdatabase/migrations/bindata.go @@ -4,6 +4,8 @@ // 0001_app.up.sql (3.088kB) // 0002_tokens.down.sql (19B) // 0002_tokens.up.sql (248B) +// 0003_settings.down.sql (118B) +// 0003_settings.up.sql (1.341kB) // doc.go (74B) package migrations @@ -88,7 +90,7 @@ func _0001_appDownSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "0001_app.down.sql", size: 387, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "0001_app.down.sql", size: 387, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xbc, 0x9c, 0xd2, 0xe1, 0x1d, 0x8, 0x34, 0x6a, 0xc8, 0x37, 0x13, 0xb3, 0x9f, 0x26, 0x23, 0x33, 0xd4, 0x25, 0x8, 0xed, 0x53, 0xe6, 0xd, 0x46, 0xc9, 0xf4, 0x24, 0xf8, 0x1, 0x1f, 0xf5, 0xc8}} return a, nil } @@ -108,7 +110,7 @@ func _0001_appUpSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "0001_app.up.sql", size: 3088, mode: os.FileMode(0644), modTime: time.Unix(1576507278, 0)} + info := bindataFileInfo{name: "0001_app.up.sql", size: 3088, mode: os.FileMode(0644), modTime: time.Unix(1576607640, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x93, 0xb8, 0x68, 0x17, 0x49, 0x51, 0xc0, 0xe8, 0xbc, 0x36, 0xa4, 0x29, 0xc9, 0x93, 0x6c, 0x3e, 0xdf, 0x3d, 0x23, 0x22, 0xab, 0x18, 0x49, 0xbd, 0x6, 0xf, 0xc5, 0xec, 0xf8, 0xcf, 0x1b, 0x6a}} return a, nil } @@ -128,7 +130,7 @@ func _0002_tokensDownSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "0002_tokens.down.sql", size: 19, mode: os.FileMode(0644), modTime: time.Unix(1575999124, 0)} + info := bindataFileInfo{name: "0002_tokens.down.sql", size: 19, mode: os.FileMode(0644), modTime: time.Unix(1576607640, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xd1, 0x31, 0x2, 0xcc, 0x2f, 0x38, 0x90, 0xf7, 0x58, 0x37, 0x47, 0xf4, 0x18, 0xf7, 0x72, 0x74, 0x67, 0x14, 0x7e, 0xf3, 0xb1, 0xd6, 0x5f, 0xb0, 0xd5, 0xe7, 0x91, 0xf4, 0x26, 0x77, 0x8e, 0x68}} return a, nil } @@ -148,11 +150,51 @@ func _0002_tokensUpSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "0002_tokens.up.sql", size: 248, mode: os.FileMode(0644), modTime: time.Unix(1575999124, 0)} + info := bindataFileInfo{name: "0002_tokens.up.sql", size: 248, mode: os.FileMode(0644), modTime: time.Unix(1576607640, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xcc, 0xd6, 0xde, 0xd3, 0x7b, 0xee, 0x92, 0x11, 0x38, 0xa4, 0xeb, 0x84, 0xca, 0xcb, 0x37, 0x75, 0x5, 0x77, 0x7f, 0x14, 0x39, 0xee, 0xa1, 0x8b, 0xd4, 0x5c, 0x6e, 0x55, 0x6, 0x50, 0x16, 0xd4}} return a, nil } +var __0003_settingsDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x3c\xca\xb1\x0a\xc2\x40\x0c\x06\xe0\x3d\x4f\xf1\x8f\x0a\xbe\x41\xa7\x5c\x1b\x69\xb0\x9a\x92\x46\x6b\x47\x87\x43\x04\x11\xe1\x4e\xc1\xb7\x77\x11\xd7\x8f\xaf\x73\x1b\x11\x9c\x06\x41\xc9\xb5\xde\x1e\xd7\xd2\x50\xeb\xc2\x21\x3f\xd6\x2d\x0e\x16\x90\xb3\x4e\x31\xfd\x13\x56\x04\xd4\xcf\x33\xe3\xc4\xde\xf6\xec\x18\x5d\xf7\xec\x0b\x76\xb2\x6c\x08\x78\x5f\xee\xaf\x8c\x34\x58\xa2\x35\x66\x8d\xde\x8e\x01\xb7\x59\xbb\x86\xe8\x1b\x00\x00\xff\xff\x49\x2e\x16\x6c\x76\x00\x00\x00") + +func _0003_settingsDownSqlBytes() ([]byte, error) { + return bindataRead( + __0003_settingsDownSql, + "0003_settings.down.sql", + ) +} + +func _0003_settingsDownSql() (*asset, error) { + bytes, err := _0003_settingsDownSqlBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "0003_settings.down.sql", size: 118, mode: os.FileMode(0644), modTime: time.Unix(1576866163, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe5, 0xa6, 0xf5, 0xc0, 0x60, 0x64, 0x77, 0xe2, 0xe7, 0x3c, 0x9b, 0xb1, 0x52, 0xa9, 0x95, 0x16, 0xf8, 0x60, 0x2f, 0xa5, 0xeb, 0x46, 0xb9, 0xb9, 0x8f, 0x4c, 0xf4, 0xfd, 0xbb, 0xe7, 0xe5, 0xe5}} + return a, nil +} + +var __0003_settingsUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x94\xbd\x6e\xdb\x30\x10\xc7\x77\x3f\x05\xb7\xb4\x40\x87\x66\x28\x50\x20\x93\x1c\xab\x89\x50\x57\x0a\x54\xb9\x41\x26\x82\x26\xcf\xd6\xc1\x14\x8f\xe0\x51\x36\xfc\xf6\x85\x1c\x59\x56\x53\xd9\xa3\x78\xbf\xfb\xbe\xbf\x16\x65\xf1\x22\xaa\x64\xbe\x4c\x05\x43\x8c\xe8\xb6\xfc\x30\x7b\x2c\xd3\xa4\x4a\x3f\x3c\x8b\x4f\x33\x21\x94\x31\x01\x98\xc5\x9f\xa4\x7c\x7c\x4e\x4a\x91\x17\x95\xc8\x57\xcb\xe5\x97\x99\x10\xba\x56\xc4\xb2\x21\x03\x62\x5e\x14\xcb\x34\xc9\xc5\x22\xfd\x91\xac\x96\x95\xd8\x28\xcb\x70\x62\xda\x10\xc0\xe9\xe3\x10\xe0\x4c\xdc\xb5\x6c\xee\x2e\x44\x94\x0e\xe2\x81\xc2\x6e\x3a\x53\xcb\x91\x1a\xb9\x26\x8a\x8e\x0c\xb0\x98\x2f\x8b\xf9\x94\x41\x82\x53\x6b\x0b\x66\x00\x8c\xf2\x9e\xe5\xad\x2e\x00\xfd\xfd\xb7\xef\xf7\x37\x99\x8d\x05\x88\x67\x4b\xf7\x50\xa3\x01\x59\x53\x03\x32\x12\xd9\x88\xfe\xfa\x04\xd0\x71\x54\xd6\xaa\x88\xe4\x24\x9a\xc9\xf8\x3b\x38\xca\xf6\xba\x4d\xab\x60\xe4\x29\x8e\xd3\x30\x06\xc7\x76\xaf\x30\x80\x91\xe4\xc4\x2a\xff\x9d\x3d\xe5\xe9\x42\xcc\xb3\xa7\x2c\xaf\x3e\x42\xe8\xb6\x63\x7f\xab\x38\xca\xd6\x1b\x15\xc1\x4c\xb9\x5a\x15\x81\xa3\x34\x10\x70\x0f\x5d\x84\x58\x5f\xb0\x2c\xaf\x86\x8e\xbf\x9e\x68\xda\x4a\x0b\x7b\xb0\xe3\x14\x8d\x83\x86\x1c\xea\xf1\x9b\x53\x0d\x4c\xf6\xdb\xdf\xc1\xfb\x8e\xff\xb5\x90\x01\xa9\xc9\x6d\x70\x3b\xec\xd7\x51\xc4\x0d\xea\xd3\x74\x47\xdb\xbf\xb6\x0c\x5f\x53\xa4\xf7\x1e\xfe\x0b\xef\xd1\x39\x30\xb2\x51\x68\x19\xc2\x1e\xc2\xe5\xcc\x7c\x80\x0d\x84\x6e\xbc\xe3\xb2\x7b\xcb\x1e\xe1\x20\x7d\xc0\xbd\xd2\xc7\x1b\x99\xdb\xb5\x45\x2d\x77\x70\x9c\xec\x3a\x40\x03\xcd\x1a\x82\xe4\xa3\xd3\xe8\xb6\x52\xd7\x84\xfa\x86\xb0\xb8\xa6\xc3\x7b\x35\x3d\x72\x7a\xc4\xad\xeb\x9c\x7d\x1d\x14\x4f\x8f\x97\x23\xea\x1d\x04\x96\x5e\xe9\x1d\xcb\xfe\x3a\x47\x8a\x19\x80\x00\xba\xd3\xe5\xf9\xfb\x02\xf4\x15\x92\x93\x0d\xad\xd1\xc2\x20\xdd\xeb\xc5\x1e\x5d\xac\x21\xa2\x1e\x0b\x60\xf8\x13\xa0\xb9\x13\x2f\x65\xf6\x2b\x29\xdf\xc4\xcf\xf4\xad\x73\x68\x19\x42\xd7\xdc\x25\xeb\xa1\xab\x32\xca\x40\x14\x6f\x4a\xb5\xe7\x18\xba\xa3\x96\x5e\x31\xdf\xba\x87\x9e\xde\x23\xe3\xda\x76\x62\xde\x81\x1b\xe2\xce\x3e\x8b\xd7\xac\x7a\x2e\x56\x95\x28\x8b\xd7\x6c\xf1\x30\xfb\x1b\x00\x00\xff\xff\xa5\xef\xfe\xe7\x3d\x05\x00\x00") + +func _0003_settingsUpSqlBytes() ([]byte, error) { + return bindataRead( + __0003_settingsUpSql, + "0003_settings.up.sql", + ) +} + +func _0003_settingsUpSql() (*asset, error) { + bytes, err := _0003_settingsUpSqlBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "0003_settings.up.sql", size: 1341, mode: os.FileMode(0644), modTime: time.Unix(1576866163, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xcb, 0x11, 0x7, 0x32, 0x73, 0xa0, 0x71, 0x99, 0x31, 0x49, 0xd0, 0x8, 0x34, 0x54, 0xc7, 0x8c, 0x8, 0x2e, 0x27, 0x91, 0xc7, 0x9d, 0x33, 0x32, 0xe, 0xd8, 0x4e, 0x3f, 0x3f, 0x63, 0x1e, 0x44}} + return a, nil +} + var _docGo = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x2c\xc9\xb1\x0d\xc4\x20\x0c\x05\xd0\x9e\x29\xfe\x02\xd8\xfd\x6d\xe3\x4b\xac\x2f\x44\x82\x09\x78\x7f\xa5\x49\xfd\xa6\x1d\xdd\xe8\xd8\xcf\x55\x8a\x2a\xe3\x47\x1f\xbe\x2c\x1d\x8c\xfa\x6f\xe3\xb4\x34\xd4\xd9\x89\xbb\x71\x59\xb6\x18\x1b\x35\x20\xa2\x9f\x0a\x03\xa2\xe5\x0d\x00\x00\xff\xff\x60\xcd\x06\xbe\x4a\x00\x00\x00") func docGoBytes() ([]byte, error) { @@ -168,7 +210,7 @@ func docGo() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "doc.go", size: 74, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "doc.go", size: 74, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xde, 0x7c, 0x28, 0xcd, 0x47, 0xf2, 0xfa, 0x7c, 0x51, 0x2d, 0xd8, 0x38, 0xb, 0xb0, 0x34, 0x9d, 0x4c, 0x62, 0xa, 0x9e, 0x28, 0xc3, 0x31, 0x23, 0xd9, 0xbb, 0x89, 0x9f, 0xa0, 0x89, 0x1f, 0xe8}} return a, nil } @@ -272,6 +314,10 @@ var _bindata = map[string]func() (*asset, error){ "0002_tokens.up.sql": _0002_tokensUpSql, + "0003_settings.down.sql": _0003_settingsDownSql, + + "0003_settings.up.sql": _0003_settingsUpSql, + "doc.go": docGo, } @@ -316,11 +362,13 @@ type bintree struct { } var _bintree = &bintree{nil, map[string]*bintree{ - "0001_app.down.sql": &bintree{_0001_appDownSql, map[string]*bintree{}}, - "0001_app.up.sql": &bintree{_0001_appUpSql, map[string]*bintree{}}, - "0002_tokens.down.sql": &bintree{_0002_tokensDownSql, map[string]*bintree{}}, - "0002_tokens.up.sql": &bintree{_0002_tokensUpSql, map[string]*bintree{}}, - "doc.go": &bintree{docGo, map[string]*bintree{}}, + "0001_app.down.sql": &bintree{_0001_appDownSql, map[string]*bintree{}}, + "0001_app.up.sql": &bintree{_0001_appUpSql, map[string]*bintree{}}, + "0002_tokens.down.sql": &bintree{_0002_tokensDownSql, map[string]*bintree{}}, + "0002_tokens.up.sql": &bintree{_0002_tokensUpSql, map[string]*bintree{}}, + "0003_settings.down.sql": &bintree{_0003_settingsDownSql, map[string]*bintree{}}, + "0003_settings.up.sql": &bintree{_0003_settingsUpSql, map[string]*bintree{}}, + "doc.go": &bintree{docGo, map[string]*bintree{}}, }} // RestoreAsset restores an asset under the given directory. diff --git a/appdatabase/migrations/sql/0003_settings.down.sql b/appdatabase/migrations/sql/0003_settings.down.sql new file mode 100644 index 000000000..3122ab6a2 --- /dev/null +++ b/appdatabase/migrations/sql/0003_settings.down.sql @@ -0,0 +1,6 @@ +DROP TABLE settings; +CREATE TABLE IF NOT EXISTS settings ( + type VARCHAR PRIMARY KEY, + value BLOB +) WITHOUT ROWID; + diff --git a/appdatabase/migrations/sql/0003_settings.up.sql b/appdatabase/migrations/sql/0003_settings.up.sql new file mode 100644 index 000000000..51c325655 --- /dev/null +++ b/appdatabase/migrations/sql/0003_settings.up.sql @@ -0,0 +1,42 @@ +DROP TABLE settings; +CREATE TABLE settings ( + address VARCHAR NOT NULL, + chaos_mode BOOLEAN DEFAULT false, + currency VARCHAR DEFAULT 'usd', + current_network VARCHAR NOT NULL, + custom_bootnodes BLOB, + custom_bootnodes_enabled BLOB, + dapps_address VARCHAR NOT NULL, + eip1581_address VARCHAR NOT NULL, + fleet VARCHAR, + hide_home_tooltip BOOLEAN DEFAULT false, + installation_id VARCHAR NOT NULL, + key_uid VARCHAR NOT NULL, + keycard_instance_uid VARCHAR, + keycard_paired_on UNSIGNED BIGINT, + keycard_pairing VARCHAR, + last_updated UNSIGNED BIGINT, + latest_derived_path UNSIGNED INT DEFAULT 0, + log_level VARCHAR, + mnemonic VARCHAR, + name VARCHAR NOT NULL, + networks BLOB NOT NULL, + node_config BLOB, + notifications_enabled BOOLEAN DEFAULT false, + photo_path BLOB NOT NULL, + pinned_mailservers BLOB, + preferred_name VARCHAR, + preview_privacy BOOLEAN DEFAULT false, + public_key VARCHAR NOT NULL, + remember_syncing_choice BOOLEAN DEFAULT false, + show_name BOOLEAN, + signing_phrase VARCHAR NOT NULL, + stickers_packs_installed BLOB, + stickers_recent_stickers BLOB, + syncing_on_mobile_network BOOLEAN DEFAULT false, + synthetic_id VARCHAR DEFAULT 'id' PRIMARY KEY, + usernames BLOB, + wallet_root_address VARCHAR NOT NULL, + wallet_set_up_passed BOOLEAN DEFAULT false, + wallet_visible_tokens VARCHAR +) WITHOUT ROWID; diff --git a/lib/library.go b/lib/library.go index 7848b362d..3dee2c5ba 100644 --- a/lib/library.go +++ b/lib/library.go @@ -356,14 +356,19 @@ func Login(accountData, password *C.char) *C.char { // SaveAccountAndLogin saves account in status-go database.. //export SaveAccountAndLogin -func SaveAccountAndLogin(accountData, password, configJSON, subaccountData *C.char) *C.char { - data, confJSON, subData := C.GoString(accountData), C.GoString(configJSON), C.GoString(subaccountData) +func SaveAccountAndLogin(accountData, password, settingsJSON, configJSON, subaccountData *C.char) *C.char { + data, setJSON, confJSON, subData := C.GoString(accountData), C.GoString(settingsJSON), C.GoString(configJSON), C.GoString(subaccountData) var account multiaccounts.Account err := json.Unmarshal([]byte(data), &account) if err != nil { return makeJSONResponse(err) } - conf := params.NodeConfig{} + var settings accounts.Settings + err = json.Unmarshal([]byte(setJSON), &settings) + if err != nil { + return makeJSONResponse(err) + } + var conf params.NodeConfig err = json.Unmarshal([]byte(confJSON), &conf) if err != nil { return makeJSONResponse(err) @@ -373,10 +378,10 @@ func SaveAccountAndLogin(accountData, password, configJSON, subaccountData *C.ch if err != nil { return makeJSONResponse(err) } - api.RunAsync(func() error { - return statusBackend.StartNodeWithAccountAndConfig(account, C.GoString(password), &conf, subaccs) + err = <-api.RunAsync(func() error { + return statusBackend.StartNodeWithAccountAndConfig(account, C.GoString(password), settings, &conf, subaccs) }) - return makeJSONResponse(nil) + return makeJSONResponse(err) } // InitKeystore initialize keystore before doing any operations with keys. @@ -563,7 +568,7 @@ func WriteHeapProfile(dataDir *C.char) *C.char { //nolint: deadcode func makeJSONResponse(err error) *C.char { errString := "" if err != nil { - fmt.Fprintln(os.Stderr, err) + fmt.Fprintf(os.Stderr, "makeJSONResponse with an error: %v\n", err) errString = err.Error() } diff --git a/lib/library_test_utils.go b/lib/library_test_utils.go index 0aba4cb4b..f94a2bad7 100644 --- a/lib/library_test_utils.go +++ b/lib/library_test_utils.go @@ -37,11 +37,6 @@ import ( "github.com/stretchr/testify/require" ) -const initJS = ` - var _status_catalog = { - foo: 'bar' - };` - var ( testChainDir string keystoreDir string @@ -55,6 +50,25 @@ func buildAccountData(name, chatAddress string) *C.char { }`, name, chatAddress)) } +func buildAccountSettings(name string) *C.char { + return C.CString(fmt.Sprintf(`{ +"address": "0xdC540f3745Ff2964AFC1171a5A0DD726d1F6B472", +"current-network": "mainnet_rpc", +"dapps-address": "0xD1300f99fDF7346986CbC766903245087394ecd0", +"eip1581-address": "0xB1DDDE9235a541d1344550d969715CF43982de9f", +"installation-id": "d3efcff6-cffa-560e-a547-21d3858cbc51", +"key-uid": "0x4e8129f3edfc004875be17bf468a784098a9f69b53c095be1f52deff286935ab", +"last-derived-path": 0, +"name": "%s", +"networks/networks": {}, +"photo-path": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAAjklEQVR4nOzXwQmFMBAAUZXUYh32ZB32ZB02sxYQQSZGsod55/91WFgSS0RM+SyjA56ZRZhFmEWYRRT6h+M6G16zrxv6fdJpmUWYRbxsYr13dKfanpN0WmYRZhGzXz6AWYRZRIfbaX26fT9Jk07LLMIsosPt9I/dTDotswizCG+nhFmEWYRZhFnEHQAA///z1CFkYamgfQAAAABJRU5ErkJggg==", +"preview-privacy": false, +"public-key": "0x04211fe0f69772ecf7eb0b5bfc7678672508a9fb01f2d699096f0d59ef7fe1a0cb1e648a80190db1c0f5f088872444d846f2956d0bd84069f3f9f69335af852ac0", +"signing-phrase": "yurt joey vibe", +"wallet-root-address": "0x3B591fd819F86D0A6a2EF2Bcb94f77807a7De1a6" +}`, name)) +} + func buildSubAccountData(chatAddress string) *C.char { accs := []accounts.Account{ { @@ -67,14 +81,6 @@ func buildSubAccountData(chatAddress string) *C.char { return C.CString(string(data)) } -func buildLoginParams(mainAccountAddress, chatAddress, password string) account.LoginParams { - return account.LoginParams{ - ChatAddress: types.HexToAddress(chatAddress), - Password: password, - MainAccount: types.HexToAddress(mainAccountAddress), - } -} - func waitSignal(feed *event.Feed, event string, timeout time.Duration) error { events := make(chan signal.Envelope) sub := feed.Subscribe(events) @@ -97,29 +103,53 @@ func createAccountAndLogin(t *testing.T, feed *event.Feed) account.Info { require.NoError(t, err) t.Logf("account created: {address: %s, key: %s}", account1.WalletAddress, account1.WalletPubKey) - // select account - loginResponse := APIResponse{} - rawResponse := SaveAccountAndLogin(buildAccountData("test", account1.WalletAddress), C.CString(TestConfig.Account1.Password), C.CString(nodeConfigJSON), buildSubAccountData(account1.WalletAddress)) + signalErrC := make(chan error, 1) + go func() { + signalErrC <- waitSignal(feed, signal.EventLoggedIn, 5*time.Second) + }() + + // SaveAccountAndLogin must be called only once when an account is created. + // If the account already exists, Login should be used. + rawResponse := SaveAccountAndLogin( + buildAccountData("test", account1.WalletAddress), + C.CString(TestConfig.Account1.Password), + buildAccountSettings("test"), + C.CString(nodeConfigJSON), + buildSubAccountData(account1.WalletAddress), + ) + var loginResponse APIResponse require.NoError(t, json.Unmarshal([]byte(C.GoString(rawResponse)), &loginResponse)) require.Empty(t, loginResponse.Error) - require.NoError(t, waitSignal(feed, signal.EventLoggedIn, 5*time.Second)) + require.NoError(t, <-signalErrC) return account1 } +func loginUsingAccount(t *testing.T, feed *event.Feed, addr string) { + signalErrC := make(chan error, 1) + go func() { + signalErrC <- waitSignal(feed, signal.EventLoggedIn, 5*time.Second) + }() + + // SaveAccountAndLogin must be called only once when an account is created. + // If the account already exists, Login should be used. + rawResponse := SaveAccountAndLogin( + buildAccountData("test", addr), + C.CString(TestConfig.Account1.Password), + buildAccountSettings("test"), + C.CString(nodeConfigJSON), + buildSubAccountData(addr), + ) + var loginResponse APIResponse + require.NoError(t, json.Unmarshal([]byte(C.GoString(rawResponse)), &loginResponse)) + require.Empty(t, loginResponse.Error) + require.NoError(t, <-signalErrC) +} + // nolint: deadcode func testExportedAPI(t *testing.T) { - testDir := filepath.Join(TestDataDir, TestNetworkNames[GetNetworkID()]) - _ = OpenAccounts(C.CString(testDir)) - // inject test accounts - testKeyDir := filepath.Join(testDir, "keystore") - _ = InitKeystore(C.CString(testKeyDir)) - require.NoError(t, ImportTestAccount(testKeyDir, GetAccount1PKFile())) - require.NoError(t, ImportTestAccount(testKeyDir, GetAccount2PKFile())) - - // FIXME(tiabc): All of that is done because usage of cgo is not supported in tests. + // All of that is done because usage of cgo is not supported in tests. // Probably, there should be a cleaner way, for example, test cgo bindings in e2e tests // separately from other internal tests. - // NOTE(dshulyak) tests are using same backend with same keystore. but after every test we explicitly logging out. tests := []struct { name string fn func(t *testing.T, feed *event.Feed) bool @@ -128,12 +158,10 @@ func testExportedAPI(t *testing.T) { "StopResumeNode", testStopResumeNode, }, - { "RPCInProc", testCallRPC, }, - { "RPCPrivateAPI", testCallRPCWithPrivateAPI, @@ -155,11 +183,11 @@ func testExportedAPI(t *testing.T) { testLoginWithKeycard, }, { - "AccountLoout", + "AccountLogout", testAccountLogout, }, { - "SendTransaction", + "SendTransactionWithLogin", testSendTransactionWithLogin, }, { @@ -190,6 +218,30 @@ func testExportedAPI(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { + testDir := filepath.Join(TestDataDir, TestNetworkNames[GetNetworkID()]) + defer os.RemoveAll(testDir) + + err := os.MkdirAll(testDir, os.ModePerm) + require.NoError(t, err) + + testKeyDir := filepath.Join(testDir, "keystore") + require.NoError(t, ImportTestAccount(testKeyDir, GetAccount1PKFile())) + require.NoError(t, ImportTestAccount(testKeyDir, GetAccount2PKFile())) + + // Inject test accounts. + response := InitKeystore(C.CString(testKeyDir)) + if C.GoString(response) != `{"error":""}` { + t.Fatalf("failed to InitKeystore: %v", C.GoString(response)) + } + + // Initialize the accounts database. It must be called + // after the test account got injected. + result := OpenAccounts(C.CString(testDir)) + if C.GoString(response) != `{"error":""}` { + t.Fatalf("OpenAccounts() failed: %v", C.GoString(result)) + } + + // Create a custom signals handler so that we can examine them here. feed := &event.Feed{} signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { var envelope signal.Envelope @@ -197,11 +249,15 @@ func testExportedAPI(t *testing.T) { feed.Send(envelope) }) defer func() { - if snode := statusBackend.StatusNode(); snode == nil || !snode.IsRunning() { + errCh := make(chan error, 1) + go func() { + errCh <- waitSignal(feed, signal.EventNodeStopped, 5*time.Second) + }() + if n := statusBackend.StatusNode(); n == nil || !n.IsRunning() { return } Logout() - waitSignal(feed, signal.EventNodeStopped, 5*time.Second) + require.NoError(t, <-errCh) }() require.True(t, tc.fn(t, feed)) }) @@ -419,11 +475,15 @@ func testRecoverAccount(t *testing.T, feed *event.Feed) bool { //nolint: gocyclo t.Error("recover chat account details failed to pull the correct details (for non-cached account)") } + errC := make(chan error, 1) + go func() { + errC <- waitSignal(feed, signal.EventLoggedIn, 5*time.Second) + }() + rawResponse = SaveAccountAndLogin(buildAccountData("test", walletAddressCheck), C.CString(TestConfig.Account1.Password), buildAccountSettings("test"), C.CString(nodeConfigJSON), buildSubAccountData(walletAddressCheck)) loginResponse := APIResponse{} - rawResponse = SaveAccountAndLogin(buildAccountData("test", walletAddressCheck), C.CString(TestConfig.Account1.Password), C.CString(nodeConfigJSON), buildSubAccountData(walletAddressCheck)) require.NoError(t, json.Unmarshal([]byte(C.GoString(rawResponse)), &loginResponse)) require.Empty(t, loginResponse.Error) - require.NoError(t, waitSignal(feed, signal.EventLoggedIn, 5*time.Second)) + require.NoError(t, <-errC) // time to login with recovered data whisperService, err := statusBackend.StatusNode().WhisperService() @@ -457,6 +517,7 @@ func testLoginWithKeycard(t *testing.T, feed *event.Feed) bool { //nolint: gocyc whisperService, err := statusBackend.StatusNode().WhisperService() if err != nil { t.Errorf("whisper service not running: %v", err) + return false } chatPubKeyHex := types.EncodeHex(crypto.FromECDSAPub(&chatPrivKey.PublicKey)) @@ -527,11 +588,7 @@ type jsonrpcAnyResponse struct { } func testSendTransactionWithLogin(t *testing.T, feed *event.Feed) bool { - loginResponse := APIResponse{} - rawResponse := SaveAccountAndLogin(buildAccountData("test", TestConfig.Account1.WalletAddress), C.CString(TestConfig.Account1.Password), C.CString(nodeConfigJSON), buildSubAccountData(TestConfig.Account1.WalletAddress)) - require.NoError(t, json.Unmarshal([]byte(C.GoString(rawResponse)), &loginResponse)) - require.Empty(t, loginResponse.Error) - require.NoError(t, waitSignal(feed, signal.EventLoggedIn, 5*time.Second)) + loginUsingAccount(t, feed, TestConfig.Account1.WalletAddress) EnsureNodeSync(statusBackend.StatusNode().EnsureSync) args, err := json.Marshal(transactions.SendTxArgs{ diff --git a/mailserver/migrations/bindata.go b/mailserver/migrations/bindata.go index 125a7d7a8..a49d84606 100644 --- a/mailserver/migrations/bindata.go +++ b/mailserver/migrations/bindata.go @@ -86,7 +86,7 @@ func _1557732988_initialize_dbDownSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "1557732988_initialize_db.down.sql", size: 72, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "1557732988_initialize_db.down.sql", size: 72, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x77, 0x40, 0x78, 0xb7, 0x71, 0x3c, 0x20, 0x3b, 0xc9, 0xb, 0x2f, 0x49, 0xe4, 0xff, 0x1c, 0x84, 0x54, 0xa1, 0x30, 0xe3, 0x90, 0xf8, 0x73, 0xda, 0xb0, 0x2a, 0xea, 0x8e, 0xf1, 0x82, 0xe7, 0xd2}} return a, nil } @@ -106,7 +106,7 @@ func _1557732988_initialize_dbUpSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "1557732988_initialize_db.up.sql", size: 234, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "1557732988_initialize_db.up.sql", size: 234, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x8f, 0xa, 0x31, 0xf, 0x94, 0xe, 0xd7, 0xd6, 0xaa, 0x22, 0xd6, 0x6c, 0x7a, 0xbc, 0xad, 0x6a, 0xed, 0x2e, 0x7a, 0xf0, 0x24, 0x81, 0x87, 0x14, 0xe, 0x1c, 0x8a, 0xf1, 0x45, 0xaf, 0x9e, 0x85}} return a, nil } @@ -126,7 +126,7 @@ func staticGo() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "static.go", size: 178, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "static.go", size: 178, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xab, 0x8a, 0xf4, 0x27, 0x24, 0x9d, 0x2a, 0x1, 0x7b, 0x54, 0xea, 0xae, 0x4a, 0x35, 0x40, 0x92, 0xb5, 0xf9, 0xb3, 0x54, 0x3e, 0x3a, 0x1a, 0x2b, 0xae, 0xfb, 0x9e, 0x82, 0xeb, 0x4c, 0xf, 0x6}} return a, nil } diff --git a/mobile/status.go b/mobile/status.go index aab2e613e..839274d58 100644 --- a/mobile/status.go +++ b/mobile/status.go @@ -340,12 +340,17 @@ func Login(accountData, password string) string { } // SaveAccountAndLogin saves account in status-go database.. -func SaveAccountAndLogin(accountData, password, configJSON, subaccountData string) string { +func SaveAccountAndLogin(accountData, password, settingsJSON, configJSON, subaccountData string) string { var account multiaccounts.Account err := json.Unmarshal([]byte(accountData), &account) if err != nil { return makeJSONResponse(err) } + var settings accounts.Settings + err = json.Unmarshal([]byte(settingsJSON), &settings) + if err != nil { + return makeJSONResponse(err) + } var conf params.NodeConfig err = json.Unmarshal([]byte(configJSON), &conf) if err != nil { @@ -358,7 +363,7 @@ func SaveAccountAndLogin(accountData, password, configJSON, subaccountData strin } api.RunAsync(func() error { log.Debug("starting a node, and saving account with configuration", "key-uid", account.KeyUID) - err := statusBackend.StartNodeWithAccountAndConfig(account, password, &conf, subaccs) + err := statusBackend.StartNodeWithAccountAndConfig(account, password, settings, &conf, subaccs) if err != nil { log.Error("failed to start node and save account", "key-uid", account.KeyUID, "error", err) return err @@ -376,12 +381,17 @@ func InitKeystore(keydir string) string { } // SaveAccountAndLoginWithKeycard saves account in status-go database.. -func SaveAccountAndLoginWithKeycard(accountData, password, configJSON, subaccountData string, keyHex string) string { +func SaveAccountAndLoginWithKeycard(accountData, password, settingsJSON, configJSON, subaccountData string, keyHex string) string { var account multiaccounts.Account err := json.Unmarshal([]byte(accountData), &account) if err != nil { return makeJSONResponse(err) } + var settings accounts.Settings + err = json.Unmarshal([]byte(settingsJSON), &settings) + if err != nil { + return makeJSONResponse(err) + } var conf params.NodeConfig err = json.Unmarshal([]byte(configJSON), &conf) if err != nil { @@ -394,7 +404,7 @@ func SaveAccountAndLoginWithKeycard(accountData, password, configJSON, subaccoun } api.RunAsync(func() error { log.Debug("starting a node, and saving account with configuration", "key-uid", account.KeyUID) - err := statusBackend.SaveAccountAndStartNodeWithKey(account, password, &conf, subaccs, keyHex) + err := statusBackend.SaveAccountAndStartNodeWithKey(account, password, settings, &conf, subaccs, keyHex) if err != nil { log.Error("failed to start node and save account", "key-uid", account.KeyUID, "error", err) return err diff --git a/multiaccounts/accounts/database.go b/multiaccounts/accounts/database.go index 63b68ebce..b1a4d908a 100644 --- a/multiaccounts/accounts/database.go +++ b/multiaccounts/accounts/database.go @@ -4,10 +4,9 @@ import ( "database/sql" "encoding/json" "errors" - "fmt" - "strings" "github.com/status-im/status-go/eth-node/types" + "github.com/status-im/status-go/params" "github.com/status-im/status-go/sqlite" ) @@ -21,6 +20,8 @@ var ( ErrWalletNotUnique = errors.New("another account is set to be default wallet. disable it before using new") // ErrChatNotUnique returned if another account has `chat` field set to true. ErrChatNotUnique = errors.New("another account is set to be default chat. disable it before using new") + // ErrInvalidConfig returned if config isn't allowed + ErrInvalidConfig = errors.New("configuration value not allowed") ) type Account struct { @@ -35,6 +36,47 @@ type Account struct { Color string `json:"color"` } +type Settings struct { + // required + Address types.Address `json:"address"` + ChaosMode bool `json:"chaos-mode?,omitempty"` + Currency string `json:"currency,omitempty"` + CurrentNetwork string `json:"networks/current-network"` + CustomBootnodes *json.RawMessage `json:"custom-boot-nodes,omitempty"` + CustomBootnodesEnabled *json.RawMessage `json:"custom-boot-nodes-enabled,omitempty"` + DappsAddress types.Address `json:"dapps-address"` + EIP1581Address types.Address `json:"eip1581-address"` + Fleet *string `json:"fleet,omitempty"` + HideHomeTooltip bool `json:"hide-home-tooltip?,omitempty"` + InstallationID string `json:"installation-id"` + KeyUID string `json:"key-uid"` + KeycardInstanceUID string `json:"keycard-instance-uid,omitempty"` + KeycardPAiredOn int64 `json:"keycard-paired-on,omitempty"` + KeycardPairing string `json:"keycard-pairing,omitempty"` + LastUpdated *int64 `json:"last-updated,omitempty"` + LatestDerivedPath uint `json:"last-derived-path"` + LogLevel *string `json:"log-level,omitempty"` + Mnemonic string `json:"mnemonic,omitempty"` + Name string `json:"name,omitempty"` + Networks *json.RawMessage `json:"networks/networks"` + NotificationsEnabled bool `json:"notifications-enabled?,omitempty"` + PhotoPath string `json:"photo-path"` + PinnedMailserver *json.RawMessage `json:"pinned-mailservers,omitempty"` + PreferredName *string `json:"preferred-name,omitempty"` + PreviewPrivacy bool `json:"preview-privacy?"` + PublicKey string `json:"public-key"` + RememberSyncingChoice bool `json:"remember-syncing-choice?,omitempty"` + ShowName *bool `json:"show-name?,omitempty"` + 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"` + WalletRootAddress types.Address `json:"wallet-root-address,omitempty"` + WalletSetupPassed bool `json:"wallet-setup-passed?,omitempty"` + WalletVisibleTokens *json.RawMessage `json:"wallet/visible-tokens,omitempty"` +} + func NewDB(db *sql.DB) *Database { return &Database{db: db} } @@ -49,44 +91,196 @@ func (db Database) Close() error { return db.db.Close() } -func (db *Database) SaveConfig(typ string, value interface{}) error { - _, err := db.db.Exec("INSERT OR REPLACE INTO settings (type, value) VALUES (?, ?)", typ, &sqlite.JSONBlob{value}) +func (db *Database) CreateSettings(s Settings, nodecfg params.NodeConfig) error { + _, err := db.db.Exec(` +INSERT INTO settings ( + address, + currency, + current_network, + dapps_address, + eip1581_address, + installation_id, + key_uid, + keycard_instance_uid, + keycard_paired_on, + keycard_pairing, + latest_derived_path, + mnemonic, + name, + networks, + node_config, + photo_path, + preview_privacy, + public_key, + signing_phrase, + wallet_root_address, + synthetic_id +) VALUES ( +?,?,?,?,?,?,?,?,?,?, +?,?,?,?,?,?,?,?,?,?, +'id')`, + s.Address, + s.Currency, + s.CurrentNetwork, + s.DappsAddress, + s.EIP1581Address, + s.InstallationID, + s.KeyUID, + s.KeycardInstanceUID, + s.KeycardPAiredOn, + s.KeycardPairing, + s.LatestDerivedPath, + s.Mnemonic, + s.Name, + s.Networks, + &sqlite.JSONBlob{nodecfg}, + s.PhotoPath, + s.PreviewPrivacy, + s.PublicKey, + s.SigningPhrase, + s.WalletRootAddress) + return err } -func (db *Database) GetConfig(typ string, value interface{}) error { - return db.db.QueryRow("SELECT value FROM settings WHERE type = ?", typ).Scan(&sqlite.JSONBlob{value}) -} +// nolint: gocyclo +func (db *Database) SaveSetting(setting string, value interface{}) error { + var ( + update *sql.Stmt + err error + ) -func (db *Database) GetConfigBlob(typ string) (rst json.RawMessage, err error) { - return rst, db.db.QueryRow("SELECT value FROM settings WHERE type = ?", typ).Scan(&rst) -} - -func (db *Database) GetConfigBlobs(types []string) (map[string]json.RawMessage, error) { - // it expands number of bind vars to the number of types. sql interface doesn't allow to bypass it without modifying driver. - // expansion can be hidden in a function that modifies string but better to make it explicitly. - query := fmt.Sprintf("SELECT type, value FROM settings WHERE type IN (?%s)", strings.Repeat(",?", len(types)-1)) // nolint: gosec - args := make([]interface{}, len(types)) - for i := range types { - args[i] = types[i] + switch setting { + case "chaos-mode?": + update, err = db.db.Prepare("UPDATE settings SET chaos_mode = ? WHERE synthetic_id = 'id'") + case "currency": + update, err = db.db.Prepare("UPDATE settings SET currency = ? WHERE synthetic_id = 'id'") + case "custom-bootnodes": + value = &sqlite.JSONBlob{value} + update, err = db.db.Prepare("UPDATE settings SET custom_bootnodes = ? WHERE synthetic_id = 'id'") + case "custom-bootnodes-enabled": + value = &sqlite.JSONBlob{value} + update, err = db.db.Prepare("UPDATE settings SET custom_bootnodes_enabled = ? WHERE synthetic_id = 'id'") + case "dapps-address": + update, err = db.db.Prepare("UPDATE settings SET dapps_address = ? WHERE synthetic_id = 'id'") + case "eip1581-address": + update, err = db.db.Prepare("UPDATE settings SET eip1581_address = ? WHERE synthetic_id = 'id'") + case "fleet": + update, err = db.db.Prepare("UPDATE settings SET fleet = ? WHERE synthetic_id = 'id'") + case "hide-home-tooltip?": + update, err = db.db.Prepare("UPDATE settings SET hide_home_tooltip = ? WHERE synthetic_id = 'id'") + case "keycard-instance_uid": + update, err = db.db.Prepare("UPDATE settings SET keycard_instance_uid = ? WHERE synthetic_id = 'id'") + case "keycard-paired_on": + update, err = db.db.Prepare("UPDATE settings SET keycard_paired_on = ? WHERE synthetic_id = 'id'") + case "keycard-pairing": + update, err = db.db.Prepare("UPDATE settings SET keycard_pairing = ? WHERE synthetic_id = 'id'") + case "last-updated": + update, err = db.db.Prepare("UPDATE settings SET last_updated = ? WHERE synthetic_id = 'id'") + case "latest-derived-path": + update, err = db.db.Prepare("UPDATE settings SET latest_derived_path = ? WHERE synthetic_id = 'id'") + case "log-level": + update, err = db.db.Prepare("UPDATE settings SET log_level = ? WHERE synthetic_id = 'id'") + case "mnemonic": + update, err = db.db.Prepare("UPDATE settings SET mnemonic = ? WHERE synthetic_id = 'id'") + case "name": + update, err = db.db.Prepare("UPDATE settings SET name = ? WHERE synthetic_id = 'id'") + case "networks/current-network": + update, err = db.db.Prepare("UPDATE settings SET current_network = ? WHERE synthetic_id = 'id'") + case "networks/networks": + value = &sqlite.JSONBlob{value} + update, err = db.db.Prepare("UPDATE settings SET networks = ? WHERE synthetic_id = 'id'") + case "node-config": + value = &sqlite.JSONBlob{value} + update, err = db.db.Prepare("UPDATE settings SET node_config = ? WHERE synthetic_id = 'id'") + case "notifications-enabled?": + update, err = db.db.Prepare("UPDATE settings SET notifications_enabled = ? WHERE synthetic_id = 'id'") + case "photo-path": + update, err = db.db.Prepare("UPDATE settings SET photo_path = ? WHERE synthetic_id = 'id'") + case "pinned-mailservers": + value = &sqlite.JSONBlob{value} + update, err = db.db.Prepare("UPDATE settings SET pinned_mailservers = ? WHERE synthetic_id = 'id'") + case "preferred-name": + update, err = db.db.Prepare("UPDATE settings SET preferred_name = ? WHERE synthetic_id = 'id'") + case "preview-privacy?": + update, err = db.db.Prepare("UPDATE settings SET preview_privacy = ? WHERE synthetic_id = 'id'") + case "public-key": + update, err = db.db.Prepare("UPDATE settings SET public_key = ? WHERE synthetic_id = 'id'") + case "remember-syncing-choice?": + update, err = db.db.Prepare("UPDATE settings SET remember_syncing_choice = ? WHERE synthetic_id = 'id'") + case "show-name?": + update, err = db.db.Prepare("UPDATE settings SET show_name = ? WHERE synthetic_id = 'id'") + case "stickers-packs-installed": + value = &sqlite.JSONBlob{value} + update, err = db.db.Prepare("UPDATE settings SET stickers_packs_installed = ? WHERE synthetic_id = 'id'") + case "stickers-recent-stickers": + value = &sqlite.JSONBlob{value} + update, err = db.db.Prepare("UPDATE settings SET stickers_recent_stickers = ? WHERE synthetic_id = 'id'") + case "syncing-on-mobile-network?": + update, err = db.db.Prepare("UPDATE settings SET syncing_on_mobile_network = ? WHERE synthetic_id = 'id'") + case "usernames": + value = &sqlite.JSONBlob{value} + update, err = db.db.Prepare("UPDATE settings SET usernames = ? WHERE synthetic_id = 'id'") + case "wallet-set-up-passed?": + update, err = db.db.Prepare("UPDATE settings SET wallet_set_up_passed = ? WHERE synthetic_id = 'id'") + case "wallet/visible-tokens": + value = &sqlite.JSONBlob{value} + update, err = db.db.Prepare("UPDATE settings SET wallet_visible_tokens = ? WHERE synthetic_id = 'id'") + default: + return ErrInvalidConfig } - rows, err := db.db.Query(query, args...) if err != nil { - return nil, err + return err } - rst := make(map[string]json.RawMessage, len(types)) - for rows.Next() { - var ( - buf = json.RawMessage{} - typ string - ) - err = rows.Scan(&typ, &buf) - if err != nil { - return nil, err - } - rst[typ] = buf - } - return rst, nil + _, err = update.Exec(value) + return err +} + +func (db *Database) GetNodeConfig(nodecfg interface{}) error { + return db.db.QueryRow("SELECT node_config FROM settings WHERE synthetic_id = 'id'").Scan(&sqlite.JSONBlob{nodecfg}) +} + +func (db *Database) GetSettings() (Settings, error) { + var s Settings + err := db.db.QueryRow("SELECT address, chaos_mode, currency, current_network, 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, last_updated, latest_derived_path, log_level, mnemonic, name, networks, notifications_enabled, photo_path, pinned_mailservers, 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, + &s.CurrentNetwork, + &s.CustomBootnodes, + &s.CustomBootnodesEnabled, + &s.DappsAddress, + &s.EIP1581Address, + &s.Fleet, + &s.HideHomeTooltip, + &s.InstallationID, + &s.KeyUID, + &s.KeycardInstanceUID, + &s.KeycardPAiredOn, + &s.KeycardPairing, + &s.LastUpdated, + &s.LatestDerivedPath, + &s.LogLevel, + &s.Mnemonic, + &s.Name, + &s.Networks, + &s.NotificationsEnabled, + &s.PhotoPath, + &s.PinnedMailserver, + &s.PreferredName, + &s.PreviewPrivacy, + &s.PublicKey, + &s.RememberSyncingChoice, + &s.ShowName, + &s.SigningPhrase, + &s.StickerPacksInstalled, + &s.StickersRecentStickers, + &s.SyncingOnMobileNetwork, + &s.Usernames, + &s.WalletRootAddress, + &s.WalletSetupPassed, + &s.WalletVisibleTokens) + return s, err } func (db *Database) GetAccounts() ([]Account, error) { diff --git a/multiaccounts/accounts/database_test.go b/multiaccounts/accounts/database_test.go index 8be6e513a..a3107e11c 100644 --- a/multiaccounts/accounts/database_test.go +++ b/multiaccounts/accounts/database_test.go @@ -13,60 +13,72 @@ import ( "github.com/stretchr/testify/require" ) +var ( + config = params.NodeConfig{ + NetworkID: 10, + DataDir: "test", + } + + networks = json.RawMessage("{}") + settings = Settings{ + Address: types.HexToAddress("0xdC540f3745Ff2964AFC1171a5A0DD726d1F6B472"), + CurrentNetwork: "mainnet_rpc", + DappsAddress: types.HexToAddress("0xD1300f99fDF7346986CbC766903245087394ecd0"), + EIP1581Address: types.HexToAddress("0xB1DDDE9235a541d1344550d969715CF43982de9f"), + InstallationID: "d3efcff6-cffa-560e-a547-21d3858cbc51", + KeyUID: "0x4e8129f3edfc004875be17bf468a784098a9f69b53c095be1f52deff286935ab", + LatestDerivedPath: 0, + Name: "Jittery Cornflowerblue Kingbird", + Networks: &networks, + PhotoPath: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAAjklEQVR4nOzXwQmFMBAAUZXUYh32ZB32ZB02sxYQQSZGsod55/91WFgSS0RM+SyjA56ZRZhFmEWYRRT6h+M6G16zrxv6fdJpmUWYRbxsYr13dKfanpN0WmYRZhGzXz6AWYRZRIfbaX26fT9Jk07LLMIsosPt9I/dTDotswizCG+nhFmEWYRZhFnEHQAA///z1CFkYamgfQAAAABJRU5ErkJggg==", + PreviewPrivacy: false, + PublicKey: "0x04211fe0f69772ecf7eb0b5bfc7678672508a9fb01f2d699096f0d59ef7fe1a0cb1e648a80190db1c0f5f088872444d846f2956d0bd84069f3f9f69335af852ac0", + SigningPhrase: "yurt joey vibe", + WalletRootAddress: types.HexToAddress("0x3B591fd819F86D0A6a2EF2Bcb94f77807a7De1a6")} +) + func setupTestDB(t *testing.T) (*Database, func()) { tmpfile, err := ioutil.TempFile("", "settings-tests-") require.NoError(t, err) db, err := appdatabase.InitializeDB(tmpfile.Name(), "settings-tests") require.NoError(t, err) + return NewDB(db), func() { require.NoError(t, db.Close()) require.NoError(t, os.Remove(tmpfile.Name())) } } -func TestConfig(t *testing.T) { +func TestCreateSettings(t *testing.T) { db, stop := setupTestDB(t) defer stop() - conf := params.NodeConfig{ - NetworkID: 10, - DataDir: "test", - } - require.NoError(t, db.SaveConfig("node-config", conf)) - var rst params.NodeConfig - require.NoError(t, db.GetConfig("node-config", &rst)) - require.Equal(t, conf, rst) + require.NoError(t, db.CreateSettings(settings, config)) + + s, err := db.GetSettings() + require.NoError(t, err) + require.Equal(t, settings, s) } -func TestConfigBlob(t *testing.T) { +func TestSaveSetting(t *testing.T) { db, stop := setupTestDB(t) defer stop() - tag := "random-param" - param := 10 - require.NoError(t, db.SaveConfig(tag, param)) - expected, err := json.Marshal(param) + + require.NoError(t, db.CreateSettings(settings, config)) + require.NoError(t, db.SaveSetting("currency", "usd")) + + _, err := db.GetSettings() require.NoError(t, err) - rst, err := db.GetConfigBlob(tag) - require.NoError(t, err) - require.Equal(t, json.RawMessage(expected), rst) } -func TestGetConfigBlobs(t *testing.T) { +func TestGetNodeConfig(t *testing.T) { db, stop := setupTestDB(t) defer stop() - expected := map[string]json.RawMessage{ - "tag1": json.RawMessage("1"), - "tag2": json.RawMessage("2"), - "tag3": json.RawMessage("3"), - } - types := make([]string, 0, len(expected)) - for k, v := range expected { - require.NoError(t, db.SaveConfig(k, v)) - types = append(types, k) - } - rst, err := db.GetConfigBlobs(types) + + require.NoError(t, db.CreateSettings(settings, config)) + + _, err := db.GetSettings() require.NoError(t, err) - require.Equal(t, expected, rst) } func TestSaveAccounts(t *testing.T) { diff --git a/multiaccounts/accounts/doc.go b/multiaccounts/accounts/doc.go index 29ac65e9b..b4a310c25 100644 --- a/multiaccounts/accounts/doc.go +++ b/multiaccounts/accounts/doc.go @@ -2,5 +2,5 @@ package accounts const ( // NodeConfigTag tag for a node configuration. - NodeConfigTag = "node-config" + NodeConfigTag = "node_config" ) diff --git a/multiaccounts/migrations/bindata.go b/multiaccounts/migrations/bindata.go index 5c0e6e3da..eaa9d20d2 100644 --- a/multiaccounts/migrations/bindata.go +++ b/multiaccounts/migrations/bindata.go @@ -86,7 +86,7 @@ func _0001_accountsDownSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "0001_accounts.down.sql", size: 21, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "0001_accounts.down.sql", size: 21, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xd2, 0x61, 0x4c, 0x18, 0xfc, 0xc, 0xdf, 0x5c, 0x1f, 0x5e, 0xd3, 0xbd, 0xfa, 0x12, 0x5e, 0x8d, 0x8d, 0x8b, 0xb9, 0x5f, 0x99, 0x46, 0x63, 0xa5, 0xe3, 0xa6, 0x8a, 0x4, 0xf1, 0x73, 0x8a, 0xe9}} return a, nil } @@ -106,7 +106,7 @@ func _0001_accountsUpSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "0001_accounts.up.sql", size: 163, mode: os.FileMode(0644), modTime: time.Unix(1575989917, 0)} + info := bindataFileInfo{name: "0001_accounts.up.sql", size: 163, mode: os.FileMode(0644), modTime: time.Unix(1576607640, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xf2, 0xfa, 0x99, 0x8e, 0x96, 0xb3, 0x13, 0x6c, 0x1f, 0x6, 0x27, 0xc5, 0xd2, 0xd4, 0xe0, 0xa5, 0x26, 0x82, 0xa7, 0x26, 0xf2, 0x68, 0x9d, 0xed, 0x9c, 0x3d, 0xbb, 0xdc, 0x37, 0x28, 0xbc, 0x1}} return a, nil } @@ -126,7 +126,7 @@ func docGo() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "doc.go", size: 74, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "doc.go", size: 74, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xde, 0x7c, 0x28, 0xcd, 0x47, 0xf2, 0xfa, 0x7c, 0x51, 0x2d, 0xd8, 0x38, 0xb, 0xb0, 0x34, 0x9d, 0x4c, 0x62, 0xa, 0x9e, 0x28, 0xc3, 0x31, 0x23, 0xd9, 0xbb, 0x89, 0x9f, 0xa0, 0x89, 0x1f, 0xe8}} return a, nil } diff --git a/services/accounts/settings.go b/services/accounts/settings.go index 1e7f89420..92a5a2e66 100644 --- a/services/accounts/settings.go +++ b/services/accounts/settings.go @@ -2,10 +2,8 @@ package accounts import ( "context" - "encoding/json" "github.com/status-im/status-go/multiaccounts/accounts" - "github.com/status-im/status-go/params" ) func NewSettingsAPI(db *accounts.Database) *SettingsAPI { @@ -17,18 +15,10 @@ type SettingsAPI struct { db *accounts.Database } -func (api *SettingsAPI) SaveConfig(ctx context.Context, typ string, conf json.RawMessage) error { - return api.db.SaveConfig(typ, conf) +func (api *SettingsAPI) SaveSetting(ctx context.Context, typ string, val interface{}) error { + return api.db.SaveSetting(typ, val) } -func (api *SettingsAPI) GetConfig(ctx context.Context, typ string) (json.RawMessage, error) { - return api.db.GetConfigBlob(typ) -} - -func (api *SettingsAPI) GetConfigs(ctx context.Context, types []string) (map[string]json.RawMessage, error) { - return api.db.GetConfigBlobs(types) -} - -func (api *SettingsAPI) SaveNodeConfig(ctx context.Context, conf *params.NodeConfig) error { - return api.db.SaveConfig(accounts.NodeConfigTag, conf) +func (api *SettingsAPI) GetSettings(ctx context.Context) (accounts.Settings, error) { + return api.db.GetSettings() } diff --git a/signal/signals.go b/signal/signals.go index 534e5f137..8073a6331 100644 --- a/signal/signals.go +++ b/signal/signals.go @@ -10,7 +10,6 @@ extern void SetEventCallback(void *cb); import "C" import ( "encoding/json" - "unsafe" "sync" diff --git a/static/bindata.go b/static/bindata.go index ca12ceefc..fe190dd6d 100644 --- a/static/bindata.go +++ b/static/bindata.go @@ -97,7 +97,7 @@ func ConfigReadmeMd() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/README.md", size: 3330, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "../config/README.md", size: 3330, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x65, 0xb9, 0xf5, 0x6, 0xbe, 0x7d, 0x85, 0x3b, 0x8, 0xbc, 0x5c, 0x71, 0x85, 0x19, 0xd1, 0xde, 0x38, 0xb5, 0xe9, 0x90, 0x5c, 0x45, 0xb2, 0xa5, 0x8a, 0x91, 0xee, 0xeb, 0x1e, 0xb4, 0xa9, 0x8f}} return a, nil } @@ -117,7 +117,7 @@ func ConfigCliFleetEthBetaJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/cli/fleet-eth.beta.json", size: 3261, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "../config/cli/fleet-eth.beta.json", size: 3261, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x2b, 0xae, 0x42, 0x4b, 0xa4, 0xd9, 0x2, 0x69, 0x99, 0x29, 0x7e, 0x1, 0x4e, 0xd9, 0x58, 0x84, 0x28, 0x3a, 0x81, 0xc4, 0xde, 0x1d, 0xea, 0x51, 0xc8, 0x21, 0xff, 0x7b, 0xff, 0x23, 0x1c, 0x16}} return a, nil } @@ -137,7 +137,7 @@ func ConfigCliFleetEthStagingJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/cli/fleet-eth.staging.json", size: 1862, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "../config/cli/fleet-eth.staging.json", size: 1862, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xae, 0x85, 0xa1, 0x10, 0x16, 0x87, 0x10, 0x1c, 0xc3, 0xf4, 0xc7, 0xc, 0x2e, 0x51, 0xb7, 0x3, 0x61, 0x16, 0x99, 0x84, 0x3d, 0x5d, 0x82, 0x62, 0xfb, 0xf4, 0x5e, 0x19, 0xda, 0xb9, 0xaa, 0xc4}} return a, nil } @@ -157,7 +157,7 @@ func ConfigCliFleetEthTestJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/cli/fleet-eth.test.json", size: 1543, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "../config/cli/fleet-eth.test.json", size: 1543, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x68, 0xef, 0x71, 0xa1, 0x38, 0x37, 0xf0, 0x0, 0xbb, 0x95, 0x26, 0x2a, 0x2a, 0x65, 0x98, 0xfe, 0xe5, 0x3f, 0xbf, 0xb, 0x68, 0xa6, 0xb5, 0xa4, 0x10, 0xc1, 0x4b, 0x67, 0xb4, 0x4e, 0x32, 0xc0}} return a, nil } @@ -177,7 +177,7 @@ func ConfigCliLesEnabledJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/cli/les-enabled.json", size: 58, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "../config/cli/les-enabled.json", size: 58, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x7e, 0xee, 0x27, 0xa7, 0x74, 0xa0, 0x46, 0xa1, 0x41, 0xed, 0x4d, 0x16, 0x5b, 0xf3, 0xf0, 0x7c, 0xc8, 0x2f, 0x6f, 0x47, 0xa4, 0xbb, 0x5f, 0x43, 0x33, 0xd, 0x9, 0x9d, 0xea, 0x9e, 0x15, 0xee}} return a, nil } @@ -197,7 +197,7 @@ func ConfigCliMailserverEnabledJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/cli/mailserver-enabled.json", size: 176, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "../config/cli/mailserver-enabled.json", size: 176, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x34, 0xec, 0x81, 0x8b, 0x99, 0xb6, 0xdb, 0xc0, 0x8b, 0x46, 0x97, 0x96, 0xc7, 0x58, 0x30, 0x33, 0xef, 0x54, 0x25, 0x87, 0x7b, 0xb9, 0x94, 0x6b, 0x18, 0xa4, 0x5b, 0x58, 0x67, 0x7c, 0x44, 0xa6}} return a, nil } @@ -217,7 +217,7 @@ func ConfigStatusChainGenesisJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/status-chain-genesis.json", size: 612, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "../config/status-chain-genesis.json", size: 612, mode: os.FileMode(0644), modTime: time.Unix(1575624282, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xb, 0xf0, 0xc, 0x1, 0x95, 0x65, 0x6, 0x55, 0x48, 0x8f, 0x83, 0xa0, 0xb4, 0x81, 0xda, 0xad, 0x30, 0x6d, 0xb2, 0x78, 0x1b, 0x26, 0x4, 0x13, 0x12, 0x9, 0x6, 0xae, 0x3a, 0x2c, 0x1, 0x71}} return a, nil } @@ -237,7 +237,7 @@ func keysBootnodeKey() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/bootnode.key", size: 65, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "keys/bootnode.key", size: 65, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x31, 0xcf, 0x27, 0xd4, 0x96, 0x2e, 0x32, 0xcd, 0x58, 0x96, 0x2a, 0xe5, 0x8c, 0xa0, 0xf1, 0x73, 0x1f, 0xd6, 0xd6, 0x8b, 0xb, 0x73, 0xd3, 0x2c, 0x84, 0x1a, 0x56, 0xa4, 0x74, 0xb6, 0x95, 0x20}} return a, nil } @@ -257,7 +257,7 @@ func keysFirebaseauthkey() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/firebaseauthkey", size: 153, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "keys/firebaseauthkey", size: 153, mode: os.FileMode(0644), modTime: time.Unix(1560062905, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe, 0x69, 0x23, 0x64, 0x7d, 0xf9, 0x14, 0x37, 0x6f, 0x2b, 0x1, 0xf0, 0xb0, 0xa4, 0xb2, 0xd0, 0x18, 0xcd, 0xf9, 0xeb, 0x57, 0xa3, 0xfd, 0x79, 0x25, 0xa7, 0x9c, 0x3, 0xce, 0x26, 0xec, 0xe1}} return a, nil } @@ -277,7 +277,7 @@ func keysTestAccount1StatusChainPk() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/test-account1-status-chain.pk", size: 489, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "keys/test-account1-status-chain.pk", size: 489, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x8f, 0xba, 0x35, 0x1, 0x2b, 0x9d, 0xad, 0xf0, 0x2d, 0x3c, 0x4d, 0x6, 0xb5, 0x22, 0x2, 0x47, 0xd4, 0x1c, 0xf4, 0x31, 0x2f, 0xb, 0x5b, 0x27, 0x5d, 0x43, 0x97, 0x58, 0x2d, 0xf0, 0xe1, 0xbe}} return a, nil } @@ -297,7 +297,7 @@ func keysTestAccount1Pk() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/test-account1.pk", size: 491, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "keys/test-account1.pk", size: 491, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x9, 0x43, 0xc2, 0xf4, 0x8c, 0xc6, 0x64, 0x25, 0x8c, 0x7, 0x8c, 0xa8, 0x89, 0x2b, 0x7b, 0x9b, 0x4f, 0x81, 0xcb, 0xce, 0x3d, 0xef, 0x82, 0x9c, 0x27, 0x27, 0xa9, 0xc5, 0x46, 0x70, 0x30, 0x38}} return a, nil } @@ -317,7 +317,7 @@ func keysTestAccount2StatusChainPk() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/test-account2-status-chain.pk", size: 489, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "keys/test-account2-status-chain.pk", size: 489, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x9, 0xf8, 0x5c, 0xe9, 0x92, 0x96, 0x2d, 0x88, 0x2b, 0x8e, 0x42, 0x3f, 0xa4, 0x93, 0x6c, 0xad, 0xe9, 0xc0, 0x1b, 0x8a, 0x8, 0x8c, 0x5e, 0x7a, 0x84, 0xa2, 0xf, 0x9f, 0x77, 0x58, 0x2c, 0x2c}} return a, nil } @@ -337,7 +337,7 @@ func keysTestAccount2Pk() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/test-account2.pk", size: 491, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "keys/test-account2.pk", size: 491, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x9f, 0x72, 0xd5, 0x95, 0x5c, 0x5a, 0x99, 0x9d, 0x2f, 0x21, 0x83, 0xd7, 0x10, 0x17, 0x4a, 0x3d, 0x65, 0xc9, 0x26, 0x1a, 0x2c, 0x9d, 0x65, 0x63, 0xd2, 0xa0, 0xfc, 0x7c, 0x0, 0x87, 0x38, 0x9f}} return a, nil } @@ -357,7 +357,7 @@ func keysTestAccount3BeforeEip55Pk() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/test-account3-before-eip55.pk", size: 489, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "keys/test-account3-before-eip55.pk", size: 489, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x81, 0x40, 0x56, 0xc1, 0x5e, 0x10, 0x6e, 0x28, 0x15, 0x3, 0x4e, 0xc4, 0xc4, 0x71, 0x4d, 0x16, 0x99, 0xcc, 0x1b, 0x63, 0xee, 0x10, 0x20, 0xe4, 0x59, 0x52, 0x3f, 0xc0, 0xad, 0x15, 0x13, 0x72}} return a, nil } diff --git a/t/bindata.go b/t/bindata.go index 8f6900468..661464e97 100644 --- a/t/bindata.go +++ b/t/bindata.go @@ -86,7 +86,7 @@ func configPublicChainAccountsJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "config/public-chain-accounts.json", size: 307, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "config/public-chain-accounts.json", size: 307, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x76, 0x5d, 0xc0, 0xfe, 0x57, 0x50, 0x18, 0xec, 0x2d, 0x61, 0x1b, 0xa9, 0x81, 0x11, 0x5f, 0x77, 0xf7, 0xb6, 0x67, 0x82, 0x1, 0x40, 0x68, 0x9d, 0xc5, 0x41, 0xaf, 0xce, 0x43, 0x81, 0x92, 0x96}} return a, nil } @@ -106,7 +106,7 @@ func configStatusChainAccountsJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "config/status-chain-accounts.json", size: 543, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "config/status-chain-accounts.json", size: 543, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x8e, 0xb3, 0x61, 0x51, 0x70, 0x3c, 0x12, 0x3e, 0xf1, 0x1c, 0x81, 0xfb, 0x9a, 0x7c, 0xe3, 0x63, 0xd0, 0x8f, 0x12, 0xc5, 0x2d, 0xf4, 0xea, 0x27, 0x33, 0xef, 0xca, 0xf9, 0x3f, 0x72, 0x44, 0xbf}} return a, nil } @@ -126,7 +126,7 @@ func configTestDataJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "config/test-data.json", size: 84, mode: os.FileMode(0644), modTime: time.Unix(1574780240, 0)} + info := bindataFileInfo{name: "config/test-data.json", size: 84, mode: os.FileMode(0644), modTime: time.Unix(1575624283, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xce, 0x9d, 0x80, 0xf5, 0x87, 0xfa, 0x57, 0x1d, 0xa1, 0xd5, 0x7a, 0x10, 0x3, 0xac, 0xd7, 0xf4, 0x64, 0x32, 0x96, 0x2b, 0xb7, 0x21, 0xb7, 0xa6, 0x80, 0x40, 0xe9, 0x65, 0xe3, 0xd6, 0xbd, 0x40}} return a, nil } diff --git a/t/devtests/devnode.go b/t/devtests/devnode.go index 5388afadb..3c7bc6d82 100644 --- a/t/devtests/devnode.go +++ b/t/devtests/devnode.go @@ -3,6 +3,7 @@ package devtests import ( "crypto/ecdsa" "crypto/sha256" + "encoding/json" "io/ioutil" "os" @@ -52,6 +53,8 @@ func (s *DevNodeSuite) SetupTest() { s.dir, 1337, ) + networks := json.RawMessage("{}") + settings := accounts.Settings{Networks: &networks} s.Require().NoError(err) config.WhisperConfig.Enabled = false config.LightEthConfig.Enabled = false @@ -69,7 +72,7 @@ func (s *DevNodeSuite) SetupTest() { s.Require().NoError(s.backend.StartNodeWithAccountAndConfig(multiaccounts.Account{ Name: "main", KeyUID: keyUID, - }, "test", config, []accounts.Account{{Address: s.DevAccountAddress, Wallet: true, Chat: true}})) + }, "test", settings, config, []accounts.Account{{Address: s.DevAccountAddress, Wallet: true, Chat: true}})) s.Remote, err = s.miner.Attach() s.Require().NoError(err) s.Eth = ethclient.NewClient(s.Remote) diff --git a/t/e2e/suites.go b/t/e2e/suites.go index b66dd154d..5bcc40c54 100644 --- a/t/e2e/suites.go +++ b/t/e2e/suites.go @@ -1,18 +1,20 @@ package e2e import ( - "github.com/ethereum/go-ethereum/log" + "encoding/json" - "github.com/status-im/status-go/whisper/v6" + "github.com/ethereum/go-ethereum/log" + "github.com/stretchr/testify/suite" "github.com/status-im/status-go/api" + "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/multiaccounts" "github.com/status-im/status-go/multiaccounts/accounts" "github.com/status-im/status-go/node" "github.com/status-im/status-go/signal" "github.com/status-im/status-go/t/utils" "github.com/status-im/status-go/transactions" - "github.com/stretchr/testify/suite" + "github.com/status-im/status-go/whisper/v6" ) // StatusNodeTestSuite defines a test suite with StatusNode. @@ -21,8 +23,28 @@ type StatusNodeTestSuite struct { StatusNode *node.StatusNode } -// All general log messages in this package should be routed through this logger. -var logger = log.New("package", "status-go/t/e2e") +var ( + // All general log messages in this package should be routed through this logger. + logger = log.New("package", "status-go/t/e2e") + + // Settings for testing + networks = json.RawMessage("{}") + settings = accounts.Settings{ + Address: types.HexToAddress("0xaC540f3745Ff2964AFC1171a5A0DD726d1F6B472"), + CurrentNetwork: "mainnet_rpc", + DappsAddress: types.HexToAddress("0xa1300f99fDF7346986CbC766903245087394ecd0"), + EIP1581Address: types.HexToAddress("0xa1DDDE9235a541d1344550d969715CF43982de9f"), + InstallationID: "d3efcff6-cffa-560e-a547-21d3858cbc51", + KeyUID: "0x4e8129f3edfc004875be17bf468a784098a9f69b53c095be1f52deff286935ab", + LatestDerivedPath: 0, + Name: "Jittery Cornflowerblue Kingbird", + Networks: &networks, + PhotoPath: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAAjklEQVR4nOzXwQmFMBAAUZXUYh32ZB32ZB02sxYQQSZGsod55/91WFgSS0RM+SyjA56ZRZhFmEWYRRT6h+M6G16zrxv6fdJpmUWYRbxsYr13dKfanpN0WmYRZhGzXz6AWYRZRIfbaX26fT9Jk07LLMIsosPt9I/dTDotswizCG+nhFmEWYRZhFnEHQAA///z1CFkYamgfQAAAABJRU5ErkJggg==", + PreviewPrivacy: false, + PublicKey: "0x04211fe0f69772ecf7eb0b5bfc7678672508a9fb01f2d699096f0d59ef7fe1a0cb1e648a80190db1c0f5f088872444d846f2956d0bd84069f3f9f69335af852ac0", + SigningPhrase: "yurt joey vibe", + WalletRootAddress: types.HexToAddress("0xaB591fd819F86D0A6a2EF2Bcb94f77807a7De1a6")} +) func Init() { utils.Init() @@ -117,7 +139,7 @@ func (s *BackendTestSuite) StartTestBackendWithAccount(account multiaccounts.Acc s.NoError(s.Backend.OpenAccounts()) s.NoError(s.Backend.AccountManager().InitKeystore(nodeConfig.KeyStoreDir)) - s.Require().NoError(s.Backend.StartNodeWithAccountAndConfig(account, password, nodeConfig, subaccs)) + s.Require().NoError(s.Backend.StartNodeWithAccountAndConfig(account, password, settings, nodeConfig, subaccs)) } func (s *BackendTestSuite) LogoutAndStop() {