OSDN Git Service

fix rescan wallet (#1108)
authoroysheng <33340252+oysheng@users.noreply.github.com>
Mon, 2 Jul 2018 08:45:16 +0000 (16:45 +0800)
committerPaladz <yzhu101@uottawa.ca>
Mon, 2 Jul 2018 08:45:16 +0000 (16:45 +0800)
* fix rescan wallet

* optimise

api/wallet.go
cmd/bytomcli/commands/wallet.go
wallet/wallet.go

index 0ec8c67..30b34d3 100644 (file)
@@ -63,7 +63,7 @@ func (a *API) rescanWallet() Response {
        for {
                time.Sleep(50 * time.Microsecond)
                walletStatus := a.wallet.GetWalletStatusInfo()
-               if walletStatus.WorkHeight >= walletStatus.BestHeight {
+               if walletStatus.WorkHeight != walletStatus.BestHeight {
                        break
                }
        }
index b617fe0..ce14f87 100644 (file)
@@ -11,7 +11,7 @@ import (
 
 var walletInfoCmd = &cobra.Command{
        Use:   "wallet-info",
-       Short: "Print the block information for wallet",
+       Short: "Print the information of wallet",
        Args:  cobra.NoArgs,
        Run: func(cmd *cobra.Command, args []string) {
                data, exitCode := util.ClientCall("/wallet-info")
@@ -24,13 +24,13 @@ var walletInfoCmd = &cobra.Command{
 
 var rescanWalletCmd = &cobra.Command{
        Use:   "rescan-wallet",
-       Short: "Print the block information for wallet",
+       Short: "Trigger to rescan block information into related wallet",
        Args:  cobra.NoArgs,
        Run: func(cmd *cobra.Command, args []string) {
                if _, exitCode := util.ClientCall("/rescan-wallet"); exitCode != util.Success {
                        os.Exit(exitCode)
                }
 
-               jww.FEEDBACK.Println("Successfully trigger rescan wallet")
+               jww.FEEDBACK.Println("Successfully trigger rescanning wallet")
        },
 }
index 751f9f3..19bb013 100644 (file)
@@ -167,7 +167,7 @@ func (w *Wallet) walletUpdater() {
 
                block, _ := w.chain.GetBlockByHeight(w.status.WorkHeight + 1)
                if block == nil {
-                       <-w.chain.BlockWaiter(w.status.WorkHeight + 1)
+                       w.walletBlockWaiter()
                        continue
                }
 
@@ -190,14 +190,26 @@ func (w *Wallet) RescanBlocks() {
 func (w *Wallet) getRescanNotification() {
        select {
        case <-w.rescanCh:
-               block, _ := w.chain.GetBlockByHeight(0)
-               w.status.WorkHash = bc.Hash{}
-               w.AttachBlock(block)
+               w.setRescanStatus()
        default:
                return
        }
 }
 
+func (w *Wallet) setRescanStatus() {
+       block, _ := w.chain.GetBlockByHeight(0)
+       w.status.WorkHash = bc.Hash{}
+       w.AttachBlock(block)
+}
+
+func (w *Wallet) walletBlockWaiter() {
+       select {
+       case <-w.chain.BlockWaiter(w.status.WorkHeight + 1):
+       case <-w.rescanCh:
+               w.setRescanStatus()
+       }
+}
+
 // GetNewTxCh return a unconfirmed transaction feed channel
 func (w *Wallet) GetNewTxCh() chan *types.Tx {
        return w.newTxCh