Skip to content

fix(api): allow GET /wallet when swap or chequebook is disabled#5468

Open
martinconic wants to merge 1 commit into
masterfrom
fix/wallet-endpoint-5233
Open

fix(api): allow GET /wallet when swap or chequebook is disabled#5468
martinconic wants to merge 1 commit into
masterfrom
fix/wallet-endpoint-5233

Conversation

@martinconic
Copy link
Copy Markdown
Contributor

@martinconic martinconic commented May 20, 2026

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

The /wallet endpoint was gated behind both swap and chequebook
availability, and erc20Service was only initialized when swap was
enabled. As a result, node operators could not read their xDAI/xBZZ
balances with swap-enable=false or chequebook-enable=false.

Initialize the chequebook factory and erc20Service whenever the chain
backend is enabled, independently of swap/chequebook. The lookup stays
fail-hard when swap is enabled (preserving existing startup behaviour)
and is best-effort when swap is off, so nodes on custom chains without a
known factory address still start. Gate /wallet and /wallet/withdraw on
chain availability instead of swap/chequebook, and make the handler
tolerate a nil erc20Service.

Add an explicit startup guard rejecting swap-enable=true with the chain
backend disabled, which previously failed deep in the chequebook factory
call; without it the new flow would leave swap nil and panic on
/settlements and related endpoints.

Closes #5233

Open API Spec Version Changes (if applicable)

Motivation and Context (Optional)

Related Issue (Optional)

Screenshots (if appropriate):

AI Disclosure

  • This PR contains code that has been generated by an LLM.
  • I have reviewed the AI generated code thoroughly.
  • I possess the technical expertise to responsibly review the code generated in this PR.

@martinconic martinconic self-assigned this May 20, 2026
@martinconic martinconic added this to the 2026 milestone May 20, 2026
Copy link
Copy Markdown
Member

@gacevicljubisa gacevicljubisa left a comment

Choose a reason for hiding this comment

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

Nice fix.

We can consider addressing one TODO to add BzzAddress to ChainConfig and drop LookupERC20Address entirely. The BZZ token address is deterministic per chain, and no reason to lok it up at runtime. It is maybe out of scope here, but maybe we can make an additional PR? Or maybe even in this one? Wdyt @acud @janos ?

Comment thread pkg/node/node.go
if err != nil {
return nil, fmt.Errorf("init chequebook factory: %w", err)
if chainEnabled {
chequebookFactory, ferr := InitChequebookFactory(logger, chainBackend, chainID, transactionService, o.SwapFactoryAddress)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When swap is disabled, the factory is only being initialized so we can read the BZZ token address. Could we use postagecontract.LookupERC20Address above this instead?
LookupERC20Address resolves the same token from the postage stamp contract, and would let us skip InitChequebookFactory entirely on the swap disabled path?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — postagecontract.LookupERC20Address is in fact already called below in the postage setup (node.go:726) to resolve bzzTokenAddress, so the factory's ERC20Address here is redundant on the swap-disabled path. Reusing it would let us drop the factory init entirely when swap is off. The wrinkle is ordering: erc20Service is built here, while bzzTokenAddress only resolves ~180 lines lower, so switching cleanly means reordering the erc20 init relative to the postage block. I'd rather keep this PR scoped to the /wallet gating fix and do the lookup reuse as a follow-up so the reordering gets its own review. WDYT?

Comment thread pkg/node/node.go
chequebookFactory, err := InitChequebookFactory(logger, chainBackend, chainID, transactionService, o.SwapFactoryAddress)
if err != nil {
return nil, fmt.Errorf("init chequebook factory: %w", err)
if chainEnabled {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider extracting this whole chainEnabled block into a private helper, there are to many conditionals, it is hard to follow...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree, and we would need some refactoring in general not only for chainEnabled here, chainEnabled and other options are hard to follow in multiple areas. This should be a different PR and some effort is already ongoing in #5471

@martinconic
Copy link
Copy Markdown
Contributor Author

martinconic commented May 21, 2026

Nice fix.

We can consider addressing one TODO to add BzzAddress to ChainConfig and drop LookupERC20Address entirely. The BZZ token address is deterministic per chain, and no reason to lok it up at runtime. It is maybe out of scope here, but maybe we can make an additional PR? Or maybe even in this one? Wdyt @acud @janos ?

This is a good suggestion and task , I would make this separately and keep this PR light, covering only the scope of the reported issue.

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.

Cannot get node wallet balance when chequebook is disabled

2 participants