feat: endpoint `MakePartiallyOperableAccoutsFullyOperable` added
This commit is contained in:
parent
13931817dd
commit
1f8a3d3f5a
|
@ -1181,6 +1181,21 @@ func (db *Database) GetWalletAddress() (rst types.Address, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db *Database) GetProfileKeypair() (*Keypair, error) {
|
||||||
|
keypairs, err := db.getKeypairs(nil, "", false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, kp := range keypairs {
|
||||||
|
if kp.Type == KeypairTypeProfile {
|
||||||
|
return kp, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
panic("no profile keypair among known keypairs")
|
||||||
|
}
|
||||||
|
|
||||||
func (db *Database) GetWalletAddresses() (rst []types.Address, err error) {
|
func (db *Database) GetWalletAddresses() (rst []types.Address, err error) {
|
||||||
rows, err := db.db.Query("SELECT address FROM keypairs_accounts WHERE chat = 0 AND removed = 0 ORDER BY created_at")
|
rows, err := db.db.Query("SELECT address FROM keypairs_accounts WHERE chat = 0 AND removed = 0 ORDER BY created_at")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1303,6 +1318,11 @@ func (db *Database) MarkKeypairFullyOperable(keyUID string, clock uint64) (err e
|
||||||
return db.updateKeypairClock(tx, keyUID, clock)
|
return db.updateKeypairClock(tx, keyUID, clock)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db *Database) MarkAccountFullyOperable(address types.Address) (err error) {
|
||||||
|
_, err = db.db.Exec(`UPDATE keypairs_accounts SET operable = ? WHERE address = ?`, AccountFullyOperable, address)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// This function should not update the clock, cause it marks a keypair locally.
|
// This function should not update the clock, cause it marks a keypair locally.
|
||||||
func (db *Database) SetKeypairSyncedFrom(address types.Address, operable AccountOperable) (err error) {
|
func (db *Database) SetKeypairSyncedFrom(address types.Address, operable AccountOperable) (err error) {
|
||||||
tx, err := db.db.Begin()
|
tx, err := db.db.Begin()
|
||||||
|
|
|
@ -340,6 +340,41 @@ func (api *API) MakePrivateKeyKeypairFullyOperable(ctx context.Context, privateK
|
||||||
return (*api.messenger).MarkKeypairFullyOperable(info.KeyUID)
|
return (*api.messenger).MarkKeypairFullyOperable(info.KeyUID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *API) MakePartiallyOperableAccoutsFullyOperable(ctx context.Context, password string) (addresses []types.Address, err error) {
|
||||||
|
profileKeypair, err := api.db.GetProfileKeypair()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(profileKeypair.Keycards) == 0 && !api.VerifyPassword(password) {
|
||||||
|
err = errors.New("wrong password provided")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
keypairs, err := api.db.GetActiveKeypairs()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, kp := range keypairs {
|
||||||
|
for _, acc := range kp.Accounts {
|
||||||
|
if acc.Operable != accounts.AccountPartiallyOperable {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
err = api.createKeystoreFileForAccount(kp.DerivedFrom, password, acc)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = api.db.MarkAccountFullyOperable(acc.Address)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
addresses = append(addresses, acc.Address)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Imports a new mnemonic and creates local keystore file.
|
// Imports a new mnemonic and creates local keystore file.
|
||||||
func (api *API) ImportMnemonic(ctx context.Context, mnemonic string, password string) error {
|
func (api *API) ImportMnemonic(ctx context.Context, mnemonic string, password string) error {
|
||||||
mnemonicNoExtraSpaces := strings.Join(strings.Fields(mnemonic), " ")
|
mnemonicNoExtraSpaces := strings.Join(strings.Fields(mnemonic), " ")
|
||||||
|
|
Loading…
Reference in New Issue