}
if updateIndex {
- if err := m.store.SetAccountIndex(account); err != nil {
- return err
- }
- } else {
- if err := m.store.SetAccount(account); err != nil {
- return err
- }
+ m.store.SetAccountIndex(account)
+ }
+ if err := m.store.SetAccount(account); err != nil {
+ return err
}
if err := m.store.CommitBatch(); err != nil {
ListControlPrograms() ([]*CtrlProgram, error)
ListUTXOs() []*UTXO
SetAccount(*Account) error
- SetAccountIndex(*Account) error
+ SetAccountIndex(*Account)
SetBip44ContractIndex(string, bool, uint64)
SetCoinbaseArbitrary([]byte)
SetContractIndex(string, uint64)
func (store *mockAccountStore) ListAccounts(string) ([]*Account, error) { return nil, nil }
func (store *mockAccountStore) ListControlPrograms() ([]*CtrlProgram, error) { return nil, nil }
func (store *mockAccountStore) SetAccount(*Account) error { return nil }
-func (store *mockAccountStore) SetAccountIndex(*Account) error { return nil }
+func (store *mockAccountStore) SetAccountIndex(*Account) { return }
func (store *mockAccountStore) SetBip44ContractIndex(string, bool, uint64) { return }
func (store *mockAccountStore) SetCoinbaseArbitrary([]byte) { return }
func (store *mockAccountStore) SetContractIndex(string, uint64) { return }
}
// SetAccountIndex set account account ID, account alias and raw account.
-func (store *AccountStore) SetAccountIndex(account *acc.Account) error {
- rawAccount, err := json.Marshal(account)
- if err != nil {
- return acc.ErrMarshalAccount
- }
-
- batch := store.accountDB.NewBatch()
- if store.batch != nil {
- batch = store.batch
- }
-
- batch.Set(AccountIDKey(account.ID), rawAccount)
- batch.Set(accountAliasKey(account.Alias), []byte(account.ID))
- batch.Set(accountIndexKey(account.XPubs), common.Unit64ToBytes(account.KeyIndex))
-
+func (store *AccountStore) SetAccountIndex(account *acc.Account) {
if store.batch == nil {
- batch.Write()
+ store.accountDB.Set(accountIndexKey(account.XPubs), common.Unit64ToBytes(account.KeyIndex))
+ } else {
+ store.batch.Set(accountIndexKey(account.XPubs), common.Unit64ToBytes(account.KeyIndex))
}
- return nil
}
// SetBip44ContractIndex set contract index