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

backend/frontend: add option to restart in testnet #3157

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

bznein
Copy link
Collaborator

@bznein bznein commented Feb 4, 2025

Adds a button in the advanced settings that enables the app to start in testnet automatically on the next start. The setting is only valid for the next start, and it gets reset after that.

image

(note: the "enabled" text near the option has been removed, this is a slightly older screenshot)

Note that this PR does not automatically restart the application. This would require a lot more investigation on how to do it properly on all platforms.

@@ -1196,7 +1196,7 @@ outer:
// a user-facing setting. Now we simply use it for migration to decide which coins to add by
// default.
func (backend *Backend) persistDefaultAccountConfigs(keystore keystore.Keystore, accountsConfig *config.AccountsConfig) error {
if backend.arguments.Testing() {
if backend.Testing() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I replaced all occurrences of backend.arguments.Testing() with backend.Testing. Prior to this PR the two calls are the same (backend.Testing() calls backend.arguments.Testing()) but with this new PR there is more logic in backend.Testing() - The alternative would have be to change the field arguments.testing but since everything in arguments is unexported I prefer not to

}

// NewBackend creates a new backend with the given arguments.
func NewBackend(arguments *arguments.Arguments, environment Environment) (*Backend, error) {
log := logging.Get().WithGroup("backend")
config, err := config.NewConfig(arguments.AppConfigFilename(), arguments.AccountsConfigFilename())
backendConfig, err := config.NewConfig(arguments.AppConfigFilename(), arguments.AccountsConfigFilename())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

renaming because I later need to use config as an import name

@@ -1318,6 +1318,9 @@
"customFees": {
"description": "Lets you enter your own fee when sending."
},
"restartInTestnet": {
"description": "Use testnet instead of mainnet."
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not good with words :P I'm open to suggestions!

@bznein bznein requested a review from Beerosagos February 4, 2025 13:16
@bznein bznein marked this pull request as ready for review February 4, 2025 13:19
@benma benma self-requested a review February 4, 2025 17:27
@@ -0,0 +1,69 @@

/**
* Copyright 2023-2024 Shift Crypto AG
Copy link
Contributor

Choose a reason for hiding this comment

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

2025

@@ -232,30 +232,34 @@ type Backend struct {
tstCheckAccountUsed func(accounts.Interface) bool
// For unit tests, called when `backend.maybeAddHiddenUnusedAccounts()` has run.
tstMaybeAddHiddenUnusedAccounts func()

restartingInTestnet bool
Copy link
Contributor

Choose a reason for hiding this comment

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

This is redundant with backend.config.AppConfig().Backend.RestartInTestnet, so I would remove this here to improve clarity. Otherwise I am inclined to think that this value is somehow special or different to what's in the config.

Copy link
Collaborator Author

@bznein bznein Feb 5, 2025

Choose a reason for hiding this comment

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

of course! I completely missed that I could just use that! Thanks.

Edit: I'm not sure that would work though? Because when we start we also want to reset the appConfig flag to false so that it doesn't start in testnet again on the next start, so we need somewhere to store this value, wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, my bad. For clarity, would this maybe help?

  • rename it to testing bool
  • set it to backend.config.AppConfig().Backend.Testing || backend.arguments.Testing() followed by modifying the config to set it back to false
  • func (backend *Backend) Testing() bool { return backend.testing }

then the logic would be concentrated and easier to follow I think.

@@ -102,6 +102,9 @@ type Backend struct {

// BtcUnit is the unit used to represent Bitcoin amounts. See `coin.BtcUnit` for details.
BtcUnit coin.BtcUnit `json:"btcUnit"`

// RestartInTestnet represents whether the app should launch in testnet on the next start.
RestartInTestnet bool `json:"restartInTestnet"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a better name is StartInTestnet or just Testnet? The flag is used to turn into testnet when starting, not before. This way it sounds like it would trigger a restart or something like that.

// Only override if set in settings. If not, let the existing
// value (that could come from the --testnet flag) untouched.
if testnet {
backend.restartingInTestnet = true
if err := backendConfig.ModifyAppConfig(func(c *config.AppConfig) error { c.Backend.RestartInTestnet = false; return nil }); err != nil {
return nil, err
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

This might be better in the Start() method instead of the constructor?

@@ -102,6 +102,9 @@ type Backend struct {

// BtcUnit is the unit used to represent Bitcoin amounts. See `coin.BtcUnit` for details.
BtcUnit coin.BtcUnit `json:"btcUnit"`

// RestartInTestnet represents whether the app should launch in testnet on the next start.
Copy link
Contributor

Choose a reason for hiding this comment

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

Mention that it resets to false on app launch?

@bznein bznein force-pushed the testnetRestart branch 2 times, most recently from b1f5d21 to d9168e9 Compare February 5, 2025 13:05
@bznein bznein requested a review from benma February 5, 2025 13:06
@@ -638,6 +644,12 @@ func (backend *Backend) Start() <-chan interface{} {
backend.configureHistoryExchangeRates()

backend.environment.OnAuthSettingChanged(backend.config.AppConfig().Backend.Authentication)

if backend.testing {
Copy link
Contributor

Choose a reason for hiding this comment

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

tiny nit, but shouldn't this be backendConfig.AppConfig().Backend.StartInTestnet? The config does not need to be touched if testing is true due to the -testnet flag.

Copy link
Contributor

@benma benma left a comment

Choose a reason for hiding this comment

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

Please add an entry to CHANGELOG.md 😄
changelog

@bznein bznein force-pushed the testnetRestart branch 2 times, most recently from 7a5ff0e to b4337cd Compare February 5, 2025 15:43
@bznein bznein requested a review from benma February 5, 2025 15:53
@bznein bznein force-pushed the testnetRestart branch 2 times, most recently from cff6100 to 68deb0d Compare February 5, 2025 16:45
Adds a button in the advanced settings that enables the app
to start in testnet automatically on the next start.
The setting is only valid for the next start, and it gets
reset after that.
Copy link
Contributor

@benma benma left a comment

Choose a reason for hiding this comment

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

LGTM

@bznein bznein merged commit 5de8e17 into BitBoxSwiss:master Feb 6, 2025
9 checks passed
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.

2 participants