btcwallet icon indicating copy to clipboard operation
btcwallet copied to clipboard

Add resources package for app-specific names and paths.

Open jrick opened this issue 10 years ago • 9 comments

This separates out application names ("btcwallet" and "btcd") and file paths (the application data directory, wallet database file, etc.) into a non-internal package.

There are two benefits from splitting these resources this way:

  1. Distributed tools in the cmd dir and 3rd party tools can reuse these paths for configuration defaults.

  2. Altcoins, in theory, only have to change the application names once and the changes are made visible everywhere.

The resources package also defines the active network variable (moved from the main package's params.go) and the application data directory itself. If the network is changed, or the active datadir is modified, the functions of the resource package that return paths relative to these directories will use the new values.

jrick avatar Nov 26 '15 01:11 jrick

Not sure the active network parameters should be in resources, but other than that and the missing license header, seems fine.

davecgh avatar Nov 26 '15 02:11 davecgh

@davecgh would you prefer all the resource paths that require the network name to pass in a *netparams.Params instead of using a package global?

To be consistent we'd then probably also have to pass in the appdata dir too, and the api gets even uglier then.

jrick avatar Nov 26 '15 02:11 jrick

Anyways, after we settle on an API for this, I'd like to get all the functions here tested to ensure they actually do return the expected values for default and custom datadirs/networks/etc.

jrick avatar Nov 26 '15 02:11 jrick

I'm redoing this by defining a Resources struct in this package with methods to return all of the various resources. This is more testable and allows multiple resources to be used simultaneously.

jrick avatar Jan 14 '16 01:01 jrick

This is, perhaps not so strangely, turning into another config struct without many of the other config options. hmmmmm...

jrick avatar Jan 14 '16 03:01 jrick

rebased over the grpc branch. A couple of more improvements can be done now, like passing in the resources directly to the wallet.Loader.

jrick avatar Jan 14 '16 05:01 jrick

Rebased over master.

jrick avatar Mar 17 '16 14:03 jrick

Looks good to me (and works in quick tests). I think this kind of change will be good for dcrwallet as well so I definitely want to see it in (but I hope you have to do the merge to dcr not me). OK

jcvernaleo avatar Mar 21 '16 20:03 jcvernaleo

--create panics after this change so i'll resolve that first.

jrick avatar Mar 21 '16 20:03 jrick