OSDN Git Service

update
authorChengcheng Zhang <943420582@qq.com>
Sat, 29 Jun 2019 06:38:37 +0000 (14:38 +0800)
committerChengcheng Zhang <943420582@qq.com>
Sat, 29 Jun 2019 06:38:37 +0000 (14:38 +0800)
account/store.go
database/account_store.go

index 48084c5..9ebec3d 100644 (file)
@@ -10,31 +10,31 @@ import (
 type AccountStorer interface {
        InitBatch() error
        CommitBatch() error
-       SetAccount(*Account) error
-       SetAccountIndex(*Account) error
-       GetAccountIDByAlias(string) string
-       GetAccountByID(string) (*Account, error)
-       GetAccountIndex([]chainkd.XPub) uint64
-       DeleteAccountByAlias(string)
        DeleteAccount(*Account)
-       DeleteControlProgram(common.Hash)
+       DeleteAccountByAlias(string)
+       DeleteAccountUTXOs(string) error
        DeleteBip44ContractIndex(string)
        DeleteContractIndex(string)
-       GetContractIndex(string) uint64
-       DeleteAccountUTXOs(string) error
+       DeleteControlProgram(common.Hash)
        DeleteStandardUTXO(bc.Hash)
-       GetCoinbaseArbitrary() []byte
-       SetCoinbaseArbitrary([]byte)
-       GetMiningAddress() (*CtrlProgram, error)
-       SetMiningAddress(*CtrlProgram) error
+       GetAccountByID(string) (*Account, error)
+       GetAccountIDByAlias(string) string
+       GetAccountIndex([]chainkd.XPub) uint64
        GetBip44ContractIndex(string, bool) uint64
+       GetCoinbaseArbitrary() []byte
+       GetContractIndex(string) uint64
        GetControlProgram(common.Hash) (*CtrlProgram, error)
+       GetMiningAddress() (*CtrlProgram, error)
+       GetUTXO(bc.Hash) (*UTXO, error)
        ListAccounts(string) ([]*Account, error)
        ListControlPrograms() ([]*CtrlProgram, error)
-       SetControlProgram(common.Hash, *CtrlProgram) error
-       SetContractIndex(string, uint64)
-       SetBip44ContractIndex(string, bool, uint64)
        ListUTXOs() []*UTXO
-       GetUTXO(bc.Hash) (*UTXO, error)
+       SetAccount(*Account) error
+       SetAccountIndex(*Account) error
+       SetBip44ContractIndex(string, bool, uint64)
+       SetCoinbaseArbitrary([]byte)
+       SetContractIndex(string, uint64)
+       SetControlProgram(common.Hash, *CtrlProgram) error
+       SetMiningAddress(*CtrlProgram) error
        SetStandardUTXO(bc.Hash, *UTXO) error
 }
index 9c1365d..c43c94a 100644 (file)
@@ -46,6 +46,37 @@ func (store *AccountStore) CommitBatch() error {
        return nil
 }
 
+// DeleteAccountByAlias delete account by account alias
+func (store *AccountStore) DeleteAccountByAlias(accountAlias string) {
+       if store.batch == nil {
+               store.accountDB.Delete(accountAliasKey(accountAlias))
+       } else {
+               store.batch.Delete(accountAliasKey(accountAlias))
+       }
+}
+
+// DeleteAccount set account account ID, account alias and raw account.
+func (store *AccountStore) DeleteAccount(account *acc.Account) {
+       batch := store.accountDB.NewBatch()
+       if store.batch != nil {
+               batch = store.batch
+       }
+       batch.Delete(AccountIDKey(account.ID))
+       batch.Delete(accountAliasKey(account.Alias))
+       if store.batch == nil {
+               batch.Write()
+       }
+}
+
+// DeleteControlProgram delete raw control program by hash
+func (store *AccountStore) DeleteControlProgram(hash common.Hash) {
+       if store.batch == nil {
+               store.accountDB.Delete(ContractKey(hash))
+       } else {
+               store.batch.Delete(ContractKey(hash))
+       }
+}
+
 // SetAccount set account account ID, account alias and raw account.
 func (store *AccountStore) SetAccount(account *acc.Account) error {
        rawAccount, err := json.Marshal(account)
@@ -89,19 +120,6 @@ func (store *AccountStore) SetAccountIndex(account *acc.Account) error {
        return nil
 }
 
-// DeleteAccount set account account ID, account alias and raw account.
-func (store *AccountStore) DeleteAccount(account *acc.Account) {
-       batch := store.accountDB.NewBatch()
-       if store.batch != nil {
-               batch = store.batch
-       }
-       batch.Delete(AccountIDKey(account.ID))
-       batch.Delete(accountAliasKey(account.Alias))
-       if store.batch == nil {
-               batch.Write()
-       }
-}
-
 // GetAccountIDByAlias get account ID by account alias
 func (store *AccountStore) GetAccountIDByAlias(accountAlias string) string {
        accountID := store.accountDB.Get(accountAliasKey(accountAlias))
@@ -130,24 +148,6 @@ func (store *AccountStore) GetAccountIndex(xpubs []chainkd.XPub) uint64 {
        return currentIndex
 }
 
-// DeleteAccountByAlias delete account by account alias
-func (store *AccountStore) DeleteAccountByAlias(accountAlias string) {
-       if store.batch == nil {
-               store.accountDB.Delete(accountAliasKey(accountAlias))
-       } else {
-               store.batch.Delete(accountAliasKey(accountAlias))
-       }
-}
-
-// DeleteControlProgram delete raw control program by hash
-func (store *AccountStore) DeleteControlProgram(hash common.Hash) {
-       if store.batch == nil {
-               store.accountDB.Delete(ContractKey(hash))
-       } else {
-               store.batch.Delete(ContractKey(hash))
-       }
-}
-
 // DeleteBip44ContractIndex delete bip44 contract index by accountID
 func (store *AccountStore) DeleteBip44ContractIndex(accountID string) {
        batch := store.accountDB.NewBatch()