diff --git a/cmd/dropwtxmgr/main.go b/cmd/dropwtxmgr/main.go deleted file mode 100644 index b6b27b78a..000000000 --- a/cmd/dropwtxmgr/main.go +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (c) 2015-2016 The btcsuite developers -// Copyright (c) 2015-2016 The Decred developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -package main - -import ( - "bufio" - "fmt" - "os" - "path/filepath" - - "github.com/decred/dcrutil" - "github.com/decred/dcrwallet/walletdb" - _ "github.com/decred/dcrwallet/walletdb/bdb" - "github.com/jessevdk/go-flags" -) - -const defaultNet = "mainnet" - -var datadir = dcrutil.AppDataDir("dcrwallet", false) - -// Flags. -var opts = struct { - Force bool `short:"f" description:"Force removal without prompt"` - DbPath string `long:"db" description:"Path to wallet database"` -}{ - Force: false, - DbPath: filepath.Join(datadir, defaultNet, "wallet.db"), -} - -func init() { - _, err := flags.Parse(&opts) - if err != nil { - os.Exit(1) - } -} - -// Namespace keys. -var ( - wtxmgrNamespace = []byte("wtxmgr") -) - -func yes(s string) bool { - switch s { - case "y", "Y", "yes", "Yes": - return true - default: - return false - } -} - -func no(s string) bool { - switch s { - case "n", "N", "no", "No": - return true - default: - return false - } -} - -func main() { - os.Exit(mainInt()) -} - -func mainInt() int { - fmt.Println("Database path:", opts.DbPath) - _, err := os.Stat(opts.DbPath) - if os.IsNotExist(err) { - fmt.Println("Database file does not exist") - return 1 - } - - for !opts.Force { - fmt.Print("Drop all dcrwallet transaction history? [y/N] ") - - scanner := bufio.NewScanner(bufio.NewReader(os.Stdin)) - if !scanner.Scan() { - // Exit on EOF. - return 0 - } - err := scanner.Err() - if err != nil { - fmt.Println() - fmt.Println(err) - return 1 - } - resp := scanner.Text() - if yes(resp) { - break - } - if no(resp) || resp == "" { - return 0 - } - - fmt.Println("Enter yes or no.") - } - - db, err := walletdb.Open("bdb", opts.DbPath) - if err != nil { - fmt.Println("Failed to open database:", err) - return 1 - } - defer db.Close() - fmt.Println("Dropping wtxmgr namespace") - err = walletdb.Update(db, func(tx walletdb.ReadWriteTx) error { - return tx.DeleteTopLevelBucket(wtxmgrNamespace) - }) - if err != nil && err != walletdb.ErrBucketNotFound { - fmt.Println("Failed to drop namespace:", err) - return 1 - } - - return 0 -} diff --git a/docs/README.md b/docs/README.md index e88d2569a..464b4f279 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,5 +1,3 @@ ### Guides -[Rebuilding all transaction history with forced rescans](https://github.com/decred/dcrwallet/tree/master/docs/force_rescans.md) - [Spending funds offline using cold wallets](https://github.com/decred/dcrwallet/tree/master/docs/offline_wallets.md) \ No newline at end of file diff --git a/docs/force_rescans.md b/docs/force_rescans.md deleted file mode 100644 index 016f1a822..000000000 --- a/docs/force_rescans.md +++ /dev/null @@ -1,80 +0,0 @@ -# Rebuilding transaction history - -It is unlikely, but possible and unfortunate, that transaction history in the -wallet database may not represent reality. This may be due to a programming -mistake or the transaction database becoming corrupted. Thankfully, all -transactions are publicly recorded on the blockchain, and transactions -necessary for a fully functional wallet can be recovered. This process is -called rescanning, and the following guide will demonstrate how to force such a -rescan. - -Rescans are automatically performed each time the wallet syncs to the network. -These are used to "catch up" the wallet to the newest best block in the block -chain. For example, the following log messages at startup indicate that an -out-of-sync wallet started a rescan for all addresses and unspent outputs since -some block. - -``` -13:45:03 2015-04-13 [INF] WLLT: Started rescan from block 00000000001703b1a9dfd4865d587cd3f3cbb2f8e6ce9b44668e78ad8d4a7377 (height 205921) for 1 address -... -13:45:49 2015-04-13 [INF] WLLT: Finished rescan for 1 address (synced to block 0000000005cecab1013ecb1275a3e0c9623c4a497a57b6b6bf0fc1525aca1fbf, height 335146) -``` - -During the rescan, relevant transactions from previously unseen blocks are added -to the wallet database and spend tracking is updated accordingly. After the -rescan at startup finishes, a wallet is marked in sync with the chain. - -When wallet is started without any transaction history, a rescan is performed -for all blocks since the creation date of the wallet's first address. There are -two situations when this holds true: - -1. The wallet is newly created or was recreated from the seed -2. The transaction history is explicitly deleted - -The second case is how a forced rescan is performed. - -dcrwallet will not drop transaction history by itself, as this is something that -should not be necessary under normal wallet operation. However, a tool, -`dropwtxmgr`, is provided in the `cmd/dropwtxmgr` directory which may be used to -drop the wallet transaction manager (wtxmgr) history from a wallet database. -The tool may already be installed in your PATH, but if not, installing it is easy: - -``` -$ cd $GOPATH/src/github.com/decred/dcrwallet/cmd/dropwtxmgr -$ go get -``` - -Dropping transaction history given the default database location can be -performed by stopping wallet (to release the database) and running the tool, -answering yes to the prompt: - -``` -$ dropwtxmgr -Database path: /home/username/.dcrwallet/mainnet/wallet.db -Drop all dcrwallet transaction history? [y/N] y -Dropping wtxmgr namespace -``` - -If the wallet database is in another location or transaction history for a -different network (e.g. testnet or simnet) must be dropped, the full database -path may be specified: - -``` -$ dropwtxmgr --db ~/.dcrwallet/testnet/wallet.db -Database path: /home/username/.dcrwallet/testnet/wallet.db -Drop all dcrwallet transaction history? [y/N] y -Dropping wtxmgr namespace -``` - -After dropping transaction history, dcrwallet may be restarted and a full rescan -will be triggered to sync the wallet: - -``` -$ dcrwallet -14:05:31 2015-04-13 [INF] DCRW: No recorded transaction history -- needs full rescan -... -14:05:31 2015-04-13 [INF] WLLT: Started rescan from block 000000000000e37b0f99af2e434834123b5459e31e17937169ce81ed0cc4d61c (height 193191) for 1 address -... -14:07:06 2015-04-13 [INF] WLLT: Finished rescan for 1 address (synced to block 00000000049041b5bd7f8ac86c8f1d32065053aefbe8c31e25ed03ef015a725a, height 335482) - -```