Skip to content

Conversation

bznein
Copy link
Collaborator

@bznein bznein commented Aug 20, 2025

The only eth-balance specific code that remains in the backend is updateETHAccounts (which is passed to the updater as a callback) which I think needs to stay there as it needs access to both the accounts and keystore lock, and the slice of accounts.

Before asking for reviews, here is a check list of the most common things you might need to consider:

  • updating the Changelog
  • writing unit tests
  • checking if your changes affect other coins or tokens in unintended ways
  • testing on multiple environments (Qt, Android, ...)
  • having an AI review your changes

@bznein bznein requested a review from benma August 20, 2025 10:10
@bznein bznein force-pushed the extractETHUpdater branch 2 times, most recently from f71685d to 895101e Compare August 20, 2025 11:07
@bznein bznein changed the title backend: move eth update logic into its own package. [WIP - missing tests] backend: move eth update logic into its own package. Aug 20, 2025
@bznein bznein force-pushed the extractETHUpdater branch 3 times, most recently from 5a784e5 to 87f08e2 Compare August 20, 2025 13:30
@bznein bznein removed the request for review from benma August 20, 2025 13:38
@bznein bznein force-pushed the extractETHUpdater branch 5 times, most recently from 5a6c73b to 4d139a6 Compare August 21, 2025 11:16
@bznein bznein changed the title [WIP - missing tests] backend: move eth update logic into its own package. backend: move eth update logic into its own package. Aug 21, 2025
@bznein bznein requested a review from benma August 21, 2025 11:29
@@ -310,6 +302,7 @@ func NewBackend(arguments *arguments.Arguments, environment Environment) (*Backe
backend.socksProxy = backendProxy
backend.httpClient = hclient
backend.etherScanHTTPClient = hclient
backend.ethupdater = eth.NewUpdater(accountUpdate, backend.etherScanHTTPClient, backend.etherScanRateLimiter, backend.updateETHAccounts)
Copy link
Contributor

Choose a reason for hiding this comment

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

I could swear we removed etherScanHTTPClient in a recent PR 🤔 I think I commented somewhere that we can remove it as it's the same as backend.httpClient, now that the rate limiter is separate from the http client.

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 could swear we removed etherScanHTTPClient in a recent PR 🤔

Now that you mention, I think I remember it too :D maybe it was in a staging branch for blockbook? Anyway, will do :)

Comment on lines 61 to 62
close(u.enqueueUpdateForAccount)
close(u.updateETHAccountsCh)
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to close these explicitly afaik. They will be garbage collected, and no risk in making the poll loop handle these events (even though it should not happen with the double nesting on the quit channel).

updateETHAccountsCh should especially not be closed here as it was not created here either.

switch {
case IsERC20(account):
var err error
balance, err = account.ERC20Balance()
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think it's worth introducing a new function for it, as it's only used once, it's short and can just be inlined here as before.

quit chan struct{}

// enqueueUpdateForAccount is used to enqueue an update for a specific ETH account.
enqueueUpdateForAccount chan *Account
Copy link
Contributor

Choose a reason for hiding this comment

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

Change the type to <- chan *Account to indicate it can only receive, not send/close.

}

// NewUpdater creates a new Updater instance.
func NewUpdater(accountUpdate chan *Account, etherscanClient *http.Client, etherscanRateLimiter *rate.Limiter, updateETHAccounts func() error) *Updater {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please split into multiple lines (one per argument). Best to try keep lines <100 chars.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Please split into multiple lines (one per argument). Best to try keep lines <100 chars.

Will do, but just for reference I didn't initially as I usually try to follow what I remember from Google's style guide (https://google.github.io/styleguide/go/guide.html#line-length)

Copy link
Contributor

@benma benma Aug 28, 2025

Choose a reason for hiding this comment

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

"if it feels too long", very clear 😂

In my experience 100 chars is pretty good and fits on split screens in vim/emacs on most displays.

}()
case <-u.updateETHAccountsCh:
go updateAll()
timer = time.After(PollInterval)
Copy link
Contributor

Choose a reason for hiding this comment

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

move the Pollnterval variable to this file and unexport it - it's not used outside this file anymore.

@bznein bznein force-pushed the extractETHUpdater branch from 4d139a6 to 8bd5bc4 Compare August 28, 2025 10:42
@bznein bznein requested a review from benma August 28, 2025 10:42
@bznein
Copy link
Collaborator Author

bznein commented Aug 28, 2025

Ready for another review, thanks @benma !

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.

looks nice, thanks!

utACK

@bznein bznein merged commit 3848629 into BitBoxSwiss:master Aug 29, 2025
10 checks passed
@bznein bznein deleted the extractETHUpdater branch August 29, 2025 13:35
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