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
}
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)
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))
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()