-
Notifications
You must be signed in to change notification settings - Fork 600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate wtxmgr #234
Merged
Merged
Integrate wtxmgr #234
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// Copyright (c) 2015 Conformal Systems LLC <info@conformal.com> | ||
// | ||
// Permission to use, copy, modify, and distribute this software for any | ||
// purpose with or without fee is hereby granted, provided that the above | ||
// copyright notice and this permission notice appear in all copies. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
|
||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/btcsuite/btcutil" | ||
"github.com/btcsuite/btcwallet/walletdb" | ||
_ "github.com/btcsuite/btcwallet/walletdb/bdb" | ||
"github.com/btcsuite/go-flags" | ||
) | ||
|
||
const defaultNet = "mainnet" | ||
|
||
var datadir = btcutil.AppDataDir("btcwallet", 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 btcwallet 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 = db.DeleteNamespace(wtxmgrNamespace) | ||
if err != nil && err != walletdb.ErrBucketNotFound { | ||
fmt.Println("Failed to drop namespace:", err) | ||
return 1 | ||
} | ||
|
||
return 0 | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Guides | ||
|
||
[Rebuilding all transaction history with forced rescans](https://github.com/btcsuite/btcwallet/tree/master/docs/force_rescans.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# 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. | ||
|
||
btcwallet 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/btcsuite/btcwallet/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/.btcwallet/mainnet/wallet.db | ||
Drop all btcwallet 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 ~/.btcwallet/testnet/wallet.db | ||
Database path: /home/username/.btcwallet/testnet/wallet.db | ||
Drop all btcwallet transaction history? [y/N] y | ||
Dropping wtxmgr namespace | ||
``` | ||
|
||
After dropping transaction history, btcwallet may be restarted and a full rescan | ||
will be triggered to sync the wallet: | ||
|
||
``` | ||
$ btcwallet | ||
14:05:31 2015-04-13 [INF] BTCW: 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) | ||
|
||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go install
? I know go get will install it too, but it also tries to do more.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not without
-u
.