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

Refactoring to create a 'wallet' package #213

Merged
merged 1 commit into from
Apr 2, 2015
Merged

Refactoring to create a 'wallet' package #213

merged 1 commit into from
Apr 2, 2015

Conversation

manan19
Copy link
Contributor

@manan19 manan19 commented Mar 4, 2015

No description provided.

@jrick
Copy link
Member

jrick commented Mar 4, 2015

Please don't add a global wallet instance to the main package. You can end up with races between reading and setting the pointer. Instead, use the wallet pointers that are passed down to all of the handlers, after the wallet has been loaded and added to the server with SetWallet.

@@ -25,11 +25,13 @@ import (
"runtime"

"github.com/btcsuite/btcwallet/chain"
"github.com/mirrorx/btcwallet/wallet"
Copy link
Member

Choose a reason for hiding this comment

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

btcsuite

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll change this at the very end - right before it's ready to merge.

@manan19
Copy link
Contributor Author

manan19 commented Mar 4, 2015

This removes the global wallet ref
87c1897

@@ -263,7 +255,7 @@ func loadConfig() (*config, []string, error) {
// Pre-parse the command line options to see if an alternative config
// file or the version flag was specified.
preCfg := cfg
Copy link
Member

Choose a reason for hiding this comment

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

This has changed semantics now because cfg is a pointer, not a config, so it doesn't make a shallow copy of the struct. Is this intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed it back to how it was originally

@davecgh
Copy link
Member

davecgh commented Mar 5, 2015

In general, I'd like to see everything dealing with the creation of the wallet database and where it lives completely moved out of the new package.

It would be much cleaner to leave it up to the caller where to locate the database file, when to create a new one, etc. The wallet package, imo, should just take a walletdb.Db that has already been opened.

I think it will allow much more flexibility for direct integration into GUIs, running as a service, running as a daemon, etc.

dbPath := filepath.Join(netdir, walletDbName)
// OpenWallet opens a wallet from disk.
func OpenWallet(config *Config) (*Wallet, error) {
netdir := NetworkDir(config.DataDir, config.ChainParams)
Copy link
Member

Choose a reason for hiding this comment

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

As mentioned elsewhere, I'd prefer all of this be up to the caller and this function takes an already opened walletdb.DB to work with.

@jrick
Copy link
Member

jrick commented Mar 5, 2015

I don't think passing just an opened DB to the wallet package is enough at the moment, since txstore is outside the db.

But we could pass both in, and then when wtxmgr goes live, introduce a breaking API change which removes the txstore option.

I do find that cleaner than making the wallet package aware of the database file name. What I don't want is to have both the wallet file name and the data directory configurable, since that is madness.

@davecgh
Copy link
Member

davecgh commented Mar 5, 2015

Agreed for btcwallet. By making the caller responsible for the db, that is a choice we can make for btcwallet. On the other hand, perhaps GUIs might want to support multiple wallets in the same directory (once txstore is moved into the db, this would be trivial as it's a single file), one wallet per directory across multiple directories, or some combination thereof. Making the caller responsible for such things offers the flexibility to do all of them. Having the wallet package responsible for it like it is now doesn't.

Further, it allows the caller to create their own namespace and store data in the same database. For example, the GUI could save its state, options, etc. This type of stuff was the intent of designing walletdb with namespaces. It makes it trivial to add a new package/namespace and store whatever you like without having to worry about messing up any data stored by other packages.

@manan19
Copy link
Contributor Author

manan19 commented Mar 7, 2015

Moved out wallet files creation as well as ownership outside the wallet package. The wallet database and txStore need to be passed in as parameters to wallet.Open

@davecgh
Copy link
Member

davecgh commented Mar 11, 2015

Status Update: We're currently working to get #155 and #204 merged to master. This will need to be rebased and updated to handle those changes once they're merged. After that we'll give this another round of review.

@davecgh
Copy link
Member

davecgh commented Mar 19, 2015

Status Update: #155 has been merged to master. We're working on #204 now. Once that is one, we'll work on this one.

@@ -0,0 +1,31 @@
wallet
========
Copy link
Member

Choose a reason for hiding this comment

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

Too many =. The other READMEs make these match.

return &db, nil
}

func openWaddrmgr(db *walletdb.DB, namespaceKey []byte, pass string,
Copy link
Member

Choose a reason for hiding this comment

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

Please comment the intent, caveats, etc of this function.

@davecgh
Copy link
Member

davecgh commented Apr 1, 2015

Also, please create a doc.go file along the lines of https://github.com/btcsuite/btcwallet/blob/master/waddrmgr/doc.go.

@davecgh
Copy link
Member

davecgh commented Apr 2, 2015

All changes reviewed. As discussed in IRC, please add TODOs in doc.go and README.md for the documentation to be completed by #224, and squash/rebase this to the latest master. Then I'll be able to OK it and get it merged.

This a refactor of the btcwallet main package to create a new wallet
package.
The main feature of this package is the integration of all the other
wallet components (waddrmgr, txstore, and chain) and the Wallet type is
'runnable', so it will be continuously updating itself against changes
notified by the remote btcd instance.

It also includes several methods which provide access to information
necessary to run a wallet RPC server.
@manan19
Copy link
Contributor Author

manan19 commented Apr 2, 2015

@davecgh

  • Added 2 TODO's in wallet/doc.go and wallet/README.md.
  • Rebased, squashed into one descriptive commit and force pushed.

Travis build seems good, ready to be merged in.

@conformal-deploy conformal-deploy merged commit dfe617e into btcsuite:master Apr 2, 2015
alexlyp added a commit to alexlyp/btcwallet that referenced this pull request Jun 27, 2016
Needs dcrd commit b58d1c4bd45c3fce89318ada51dd1288b5c5c58d
Fixes btcsuite#213
alexlyp added a commit to alexlyp/btcwallet that referenced this pull request Jul 20, 2016
Needs dcrd commit b58d1c4bd45c3fce89318ada51dd1288b5c5c58d
Fixes btcsuite#213
alexlyp added a commit to alexlyp/btcwallet that referenced this pull request Jul 27, 2016
Needs dcrd commit b58d1c4bd45c3fce89318ada51dd1288b5c5c58d
Fixes btcsuite#213
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.

4 participants