OSDN Git Service

update GetContractIndex
authorChengcheng Zhang <943420582@qq.com>
Thu, 27 Jun 2019 15:36:42 +0000 (23:36 +0800)
committerChengcheng Zhang <943420582@qq.com>
Thu, 27 Jun 2019 15:36:42 +0000 (23:36 +0800)
account/accounts.go
account/image.go
account/store.go
database/account_store.go

index 43e340e..f054863 100644 (file)
@@ -451,15 +451,6 @@ func (m *Manager) GetCoinbaseCtrlProgram() (*CtrlProgram, error) {
        return program, nil
 }
 
-// GetContractIndex return the current index
-func (m *Manager) GetContractIndex(accountID string) uint64 {
-       index := uint64(0)
-       if rawIndexBytes := m.store.GetContractIndex(accountID); rawIndexBytes != nil {
-               index = common.BytesToUnit64(rawIndexBytes)
-       }
-       return index
-}
-
 // GetBip44ContractIndex return the current bip44 contract index
 func (m *Manager) GetBip44ContractIndex(accountID string, change bool) uint64 {
        index := uint64(0)
@@ -646,10 +637,14 @@ func createP2SH(account *Account, path [][]byte) (*CtrlProgram, error) {
        }, nil
 }
 
+func (m *Manager) GetContractIndex(accountID string) uint64 {
+       return m.store.GetContractIndex(accountID)
+}
+
 func (m *Manager) getCurrentContractIndex(account *Account, change bool) (uint64, error) {
        switch account.DeriveRule {
        case signers.BIP0032:
-               return m.GetContractIndex(account.ID), nil
+               return m.store.GetContractIndex(account.ID), nil
        case signers.BIP0044:
                return m.GetBip44ContractIndex(account.ID, change), nil
        }
index 4bf9bb7..bcd2ed2 100644 (file)
@@ -37,7 +37,7 @@ func (m *Manager) Backup() (*Image, error) {
                }
                image.Slice = append(image.Slice, &ImageSlice{
                        Account:       account,
-                       ContractIndex: m.GetContractIndex(account.ID),
+                       ContractIndex: m.store.GetContractIndex(account.ID),
                })
        }
        return image, nil
index 28e2b54..c965731 100644 (file)
@@ -19,7 +19,7 @@ type AccountStorer interface {
        DeleteRawProgram(common.Hash)
        DeleteBip44ContractIndex(string)
        DeleteContractIndex(string)
-       GetContractIndex(string) []byte
+       GetContractIndex(string) uint64
        GetAccountUTXOs(string) [][]byte
        DeleteStandardUTXO(bc.Hash)
        GetCoinbaseArbitrary() []byte
index 9b1e78a..78c85d4 100644 (file)
@@ -154,8 +154,12 @@ func (store *AccountStore) DeleteContractIndex(accountID string) {
 }
 
 // GetContractIndex get contract index
-func (store *AccountStore) GetContractIndex(accountID string) []byte {
-       return store.accountDB.Get(contractIndexKey(accountID))
+func (store *AccountStore) GetContractIndex(accountID string) uint64 {
+       index := uint64(0)
+       if rawIndexBytes := store.accountDB.Get(contractIndexKey(accountID)); rawIndexBytes != nil {
+               index = common.BytesToUnit64(rawIndexBytes)
+       }
+       return index
 }
 
 // GetAccountUTXOs get account utxos by account id