OSDN Git Service

update loadWalletInfo
authorChengcheng Zhang <943420582@qq.com>
Thu, 4 Jul 2019 08:04:34 +0000 (16:04 +0800)
committerChengcheng Zhang <943420582@qq.com>
Thu, 4 Jul 2019 08:04:34 +0000 (16:04 +0800)
database/wallet_store.go
wallet/wallet.go

index c974bff..442ebfb 100644 (file)
@@ -319,7 +319,7 @@ func (store *WalletStore) GetRecoveryStatus(recoveryKey []byte) []byte {
 func (store *WalletStore) GetWalletInfo() (*wallet.StatusInfo, error) {
        rawStatus := store.walletDB.Get([]byte(dbm.WalletKey))
        if rawStatus == nil {
-               return nil, fmt.Errorf("failed get wallet info")
+               return nil, wallet.ErrGetWalletStatusInfo
        }
        status := new(wallet.StatusInfo)
        if err := json.Unmarshal(rawStatus, status); err != nil {
index fedd51e..930fe15 100644 (file)
@@ -26,6 +26,7 @@ var (
 
        errBestBlockNotFoundInCore = errors.New("best block not found in core")
        errWalletVersionMismatch   = errors.New("wallet version mismatch")
+       ErrGetWalletStatusInfo     = errors.New("failed get wallet info")
 )
 
 //StatusInfo is base valid block info to handle orphan block rollback
@@ -144,19 +145,20 @@ func (w *Wallet) loadWalletInfo() error {
        //      w.store.DeleteWalletUTXOs()
        // }
        walletStatus, err := w.store.GetWalletInfo()
-       if err != nil {
+       if walletStatus == nil && err != ErrGetWalletStatusInfo {
                return err
        }
-       w.status = *walletStatus
-       err = w.checkWalletInfo()
-       if err == nil {
-               return nil
+       if walletStatus != nil {
+               w.status = *walletStatus
+               err = w.checkWalletInfo()
+               if err == nil {
+                       return nil
+               }
+               log.WithFields(log.Fields{"module": logModule}).Warn(err.Error())
+               w.store.DeleteWalletTransactions()
+               w.store.DeleteWalletUTXOs()
        }
 
-       log.WithFields(log.Fields{"module": logModule}).Warn(err.Error())
-       w.store.DeleteWalletTransactions()
-       w.store.DeleteWalletUTXOs()
-
        w.status.Version = currentVersion
        w.status.WorkHash = bc.Hash{}
        block, err := w.chain.GetBlockByHeight(0)