m.Handle("/backup-wallet", jsonHandler(a.backupWalletImage))
m.Handle("/restore-wallet", jsonHandler(a.restoreWalletImage))
m.Handle("/rescan-wallet", jsonHandler(a.rescanWallet))
+ m.Handle("/wallet-info", jsonHandler(a.getWalletInfo))
} else {
log.Warn("Please enable wallet")
}
return info
}
-// getNetInfo return network infomation
+// getNetInfo return network information
func (a *API) getNetInfo() Response {
return NewSuccessResponse(a.GetNodeInfo())
}
a.wallet.RescanBlocks()
return NewSuccessResponse(nil)
}
+
+// WalletInfo return wallet information
+type WalletInfo struct {
+ BestBlockHeight uint64 `json:"best_block_height"`
+ WalletHeight uint64 `json:"wallet_height"`
+}
+
+func (a *API) getWalletInfo() Response {
+ bestBlockHeight := a.chain.BestBlockHeight()
+ walletStatus := a.wallet.GetWalletStatusInfo()
+
+ return NewSuccessResponse(&WalletInfo{
+ BestBlockHeight: bestBlockHeight,
+ WalletHeight: walletStatus.WorkHeight,
+ })
+}
BytomcliCmd.AddCommand(listUnspentOutputsCmd)
BytomcliCmd.AddCommand(listBalancesCmd)
+ BytomcliCmd.AddCommand(rescanWalletCmd)
+ BytomcliCmd.AddCommand(walletInfoCmd)
+
BytomcliCmd.AddCommand(buildTransactionCmd)
BytomcliCmd.AddCommand(signTransactionCmd)
BytomcliCmd.AddCommand(submitTransactionCmd)
listTransactionsCmd.Name(),
listUnspentOutputsCmd.Name(),
listBalancesCmd.Name(),
+
+ rescanWalletCmd.Name(),
+ walletInfoCmd.Name(),
}
cobra.AddTemplateFunc("WalletEnable", func(cmdName string) bool {
--- /dev/null
+package commands
+
+import (
+ "os"
+
+ "github.com/spf13/cobra"
+ jww "github.com/spf13/jwalterweatherman"
+
+ "github.com/bytom/util"
+)
+
+var walletInfoCmd = &cobra.Command{
+ Use: "wallet-info",
+ Short: "Print the block information for wallet",
+ Args: cobra.NoArgs,
+ Run: func(cmd *cobra.Command, args []string) {
+ data, exitCode := util.ClientCall("/wallet-info")
+ if exitCode != util.Success {
+ os.Exit(exitCode)
+ }
+ printJSON(data)
+ },
+}
+
+var rescanWalletCmd = &cobra.Command{
+ Use: "rescan-wallet",
+ Short: "Print the block information for 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")
+ },
+}
import (
"encoding/json"
+ "sync"
log "github.com/sirupsen/logrus"
"github.com/tendermint/tmlibs/db"
//Wallet is related to storing account unspent outputs
type Wallet struct {
DB db.DB
+ rw sync.RWMutex
status StatusInfo
AccountMgr *account.Manager
AssetReg *asset.Registry
// AttachBlock attach a new block
func (w *Wallet) AttachBlock(block *types.Block) error {
+ w.rw.Lock()
+ defer w.rw.Unlock()
+
if block.PreviousBlockHash != w.status.WorkHash {
log.Warn("wallet skip attachBlock due to status hash not equal to previous hash")
return nil
// DetachBlock detach a block and rollback state
func (w *Wallet) DetachBlock(block *types.Block) error {
+ w.rw.Lock()
+ defer w.rw.Unlock()
+
blockHash := block.Hash()
txStatus, err := w.chain.GetTransactionStatus(&blockHash)
if err != nil {
return w.newTxCh
}
+// UnconfirmedTxCollector collector unconfirmed transaction
func (w *Wallet) UnconfirmedTxCollector() {
for {
w.SaveUnconfirmedTx(<-w.newTxCh)
}
}
+// GetWalletStatusInfo return current wallet StatusInfo
+func (w *Wallet) GetWalletStatusInfo() StatusInfo {
+ w.rw.RLock()
+ defer w.rw.RUnlock()
+
+ return w.status
+}
+
func (w *Wallet) createProgram(account *account.Account, XPub *pseudohsm.XPub, index uint64) error {
for i := uint64(0); i < index; i++ {
if _, err := w.AccountMgr.CreateAddress(nil, account.ID, false); err != nil {