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

wallet: allow manually setting the wallet birthday #885

wants to merge 2 commits into from

Conversation

josephawallace
Copy link

@josephawallace josephawallace commented Aug 5, 2023

Adds a flag that allows for the wallet's birthday to be specified when being created. This gives the user control over where rescans begin for a BTC wallet that is recovered with a seed. This is meant to resolve #883.

@josephawallace josephawallace marked this pull request as ready for review August 5, 2023 19:36
@josephawallace josephawallace changed the title wallet: include wallet birthday as configurable parameter on wallet c… wallet: allow manually setting the wallet birthday Aug 6, 2023
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Just some thoughts, nothing blocking IMO.

@@ -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 := req.Birthday
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about:

bday := time.Now()
if req.Birthday != 0 {
    bday := time.Unix(req.Birthday, 0)
}

That then shortens the call below.

@@ -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
}

; 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.
; 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.

@@ -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

@josephawallace josephawallace closed this by deleting the head repository Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow setting the start block for address rescans
2 participants