OSDN Git Service

improve importing key progress calculation
authorYongfeng LI <wliyongfeng@gmail.com>
Mon, 16 Apr 2018 07:22:39 +0000 (15:22 +0800)
committerYongfeng LI <wliyongfeng@gmail.com>
Tue, 17 Apr 2018 05:33:44 +0000 (13:33 +0800)
wallet/wallet.go

index 44e03b2..117476e 100644 (file)
@@ -335,30 +335,20 @@ func (w *Wallet) GetRescanStatus() ([]KeyInfo, error) {
                }
        }
 
-       var status StatusInfo
-       if rawWallet := w.DB.Get(walletKey); rawWallet != nil {
-               if err := json.Unmarshal(rawWallet, &status); err != nil {
-                       return nil, err
-               }
-       }
-
-       for i := range keysInfo {
-               if keysInfo[i].Complete == true || status.BestHeight == 0 {
-                       keysInfo[i].Percent = 100
-                       continue
-               }
-
-               keysInfo[i].Percent = uint8(status.WorkHeight * 100 / status.BestHeight)
-               if keysInfo[i].Percent == 100 {
-                       keysInfo[i].Complete = true
-               }
-       }
        return keysInfo, nil
 }
 
 //updateRescanStatus mark private key import process `Complete` if rescan finished
 func updateRescanStatus(w *Wallet) {
-       if !w.ImportingPrivateKey || w.status.WorkHeight < w.status.BestHeight {
+       if !w.ImportingPrivateKey {
+               return
+       }
+
+       if w.status.WorkHeight < w.status.BestHeight {
+               percent := uint8(w.status.WorkHeight * 100 / w.status.BestHeight)
+               for _, keyInfo := range w.importingKeysInfo {
+                       keyInfo.Percent = percent
+               }
                return
        }
 
@@ -368,4 +358,5 @@ func updateRescanStatus(w *Wallet) {
                keyInfo.Complete = true
        }
        w.commitkeysInfo()
+       // TODO: delete the generated but not used addresses
 }