mirror of
https://github.com/status-im/status-go.git
synced 2025-02-23 20:28:27 +00:00
* WIP accounts implementation * Accounts datasore and changes to status mobile API * Add library changes and method to update config * Handle error after account selection * Add two methods to start account to backend * Use encrypted database for settings and add a service for them * Resolve linter warning * Bring back StartNode StopNode for tests * Add sub accounts and get/save api * Changes to accounts structure * Login use root address and fetch necessary info from database * Cover accounts store with tests * Refactor in progress * Initialize status keystore instance before starting ethereum node * Rework library tests * Resolve failures in private api test and send transaction test * Pass pointer to initialized config to unmarshal * Use multiaccounts/accounts naming consistently Multiaccount is used as a login identifier Account references an address and a key, if account is not watch-only. * Add login timestamp stored in the database to accounts.Account object * Add photo-path field for multiaccount struct * Add multiaccoutns rpc with updateAccount method Update to any other account that wasn't used for login will return an error * Fix linter in services/accounts * Select account before starting a node * Save list of accounts on first login * Pass account manager to accounts service to avoid selecting account before starting a node * Add logs to login with save and regualr login
35 lines
943 B
Go
35 lines
943 B
Go
package accounts
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/status-im/status-go/account"
|
|
"github.com/status-im/status-go/multiaccounts"
|
|
)
|
|
|
|
var (
|
|
// ErrUpdatingWrongAccount raised if caller tries to update any other account except one used for login.
|
|
ErrUpdatingWrongAccount = errors.New("failed to updating wrong account. please login with that account first")
|
|
)
|
|
|
|
func NewMultiAccountsAPI(db *multiaccounts.Database, manager *account.Manager) *MultiAccountsAPI {
|
|
return &MultiAccountsAPI{db: db, manager: manager}
|
|
}
|
|
|
|
// MultiAccountsAPI is class with methods available over RPC.
|
|
type MultiAccountsAPI struct {
|
|
db *multiaccounts.Database
|
|
manager *account.Manager
|
|
}
|
|
|
|
func (api *MultiAccountsAPI) UpdateAccount(account multiaccounts.Account) error {
|
|
expected, err := api.manager.MainAccountAddress()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if account.Address != expected {
|
|
return ErrUpdatingWrongAccount
|
|
}
|
|
return api.db.UpdateAccount(account)
|
|
}
|