Skip to content
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

wallet: allow manually setting the wallet birthday #885

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
defaultRPCKeyFile = filepath.Join(defaultAppDataDir, "rpc.key")
defaultRPCCertFile = filepath.Join(defaultAppDataDir, "rpc.cert")
defaultLogDir = filepath.Join(defaultAppDataDir, defaultLogDirname)
defaultBirthday = time.Now().Unix()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the default be a very early timestamp instead? Otherwise a user might fear their coins are gone if they don't know to set this parameter and are trying to restore from an old seed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the current time as the default because that was what was previously used whenever a new wallet was created:

fmt.Println("Creating the wallet...")
w, err := loader.CreateNewWallet(pubPass, privPass, seed, time.Now())
if err != nil {
    return err
}

--->

fmt.Println("Creating the wallet...")
w, err := loader.CreateNewWallet(pubPass, privPass, seed, time.Unix(cfg.Birthday, 0))
if err != nil {
    return err
}

)

type config struct {
Expand All @@ -65,6 +66,7 @@ type config struct {

// Wallet options
WalletPass string `long:"walletpass" default-mask:"-" description:"The public wallet password -- Only required if the wallet was created with one"`
Birthday int64 `long:"birthday" default-mask:"-" description:"Specify a unix timestamp to be the wallet birthday -- Will be used as the approximate starting time for wallet rescans"`

// RPC client options
RPCConnect string `short:"c" long:"rpcconnect" description:"Hostname/IP and port of btcd RPC server to connect to (default localhost:8334, testnet: localhost:18334, simnet: localhost:18556)"`
Expand Down Expand Up @@ -278,6 +280,7 @@ func loadConfig() (*config, []string, error) {
BanDuration: neutrino.BanDuration,
BanThreshold: neutrino.BanThreshold,
DBTimeout: wallet.DefaultDBTimeout,
Birthday: defaultBirthday,
}

// Pre-parse the command line options to see if an alternative config
Expand Down
1 change: 1 addition & 0 deletions rpc/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ message CreateWalletRequest {
bytes public_passphrase = 1;
bytes private_passphrase = 2;
bytes seed = 3;
int64 birthday = 4;
}
message CreateWalletResponse {}

Expand Down
8 changes: 7 additions & 1 deletion rpc/rpcserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,14 @@ func (s *loaderServer) CreateWallet(ctx context.Context, req *pb.CreateWalletReq
pubPassphrase = []byte(wallet.InsecurePubPassphrase)
}

// Use the current time for the birthday when the request's is empty.
bday := time.Now()
if req.Birthday != 0 {
bday = time.Unix(req.Birthday, 0)
}

wallet, err := s.loader.CreateNewWallet(
pubPassphrase, req.PrivatePassphrase, req.Seed, time.Now(),
pubPassphrase, req.PrivatePassphrase, req.Seed, bday,
)
if err != nil {
return nil, translateError(err)
Expand Down
1 change: 1 addition & 0 deletions rpc/walletrpc/api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions sample-btcwallet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
; directory for mainnet and testnet wallets, respectively.
; appdata=~/.btcwallet

; Unix timestamp representing when the wallet was created, and therefore
; the earliest time the wallet could have participated in any transactions.
; This timestamp will be used to estimate a block height that is an appropriate
; starting place to scan for transactions related to this wallet. The default
; birthday will be the current time at the moment the wallet is created, if this
; parameter is not set.
; birthday=1231006505
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should mention the default value/default behavior here.



; ------------------------------------------------------------------------------
; RPC client settings
Expand Down
4 changes: 2 additions & 2 deletions walletsetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func createWallet(cfg *config) error {
}

fmt.Println("Creating the wallet...")
w, err := loader.CreateNewWallet(pubPass, privPass, seed, time.Now())
w, err := loader.CreateNewWallet(pubPass, privPass, seed, time.Unix(cfg.Birthday, 0))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I'm not familiar with btcwallet as a standalone wallet. When is this code run vs. the CreateWallet RPC call?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When being used as a standalone tool, you can create a wallet from the command line with btcwallet --create, which will run that code in that snippet

if err != nil {
return err
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func createSimulationWallet(cfg *config) error {
defer db.Close()

// Create the wallet.
err = wallet.Create(db, pubPass, privPass, nil, activeNet.Params, time.Now())
err = wallet.Create(db, pubPass, privPass, nil, activeNet.Params, time.Unix(cfg.Birthday, 0))
if err != nil {
return err
}
Expand Down