-
Notifications
You must be signed in to change notification settings - Fork 387
fix(api): allow GET /wallet when swap or chequebook is disabled #5468
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -393,6 +393,10 @@ func NewBee( | |
|
|
||
| chainEnabled := isChainEnabled(o, o.BlockchainRpcEndpoint, logger) | ||
|
|
||
| if o.SwapEnable && !chainEnabled { | ||
| return nil, errors.New("swap is enabled but the chain backend is not; provide --blockchain-rpc-endpoint or disable swap") | ||
| } | ||
|
|
||
| var batchStore postage.Storer = new(postage.NoOpBatchStore) | ||
| var evictFn func([]byte) error | ||
|
|
||
|
|
@@ -535,46 +539,56 @@ func NewBee( | |
| } | ||
| } | ||
|
|
||
| if o.SwapEnable { | ||
| chequebookFactory, err := InitChequebookFactory(logger, chainBackend, chainID, transactionService, o.SwapFactoryAddress) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("init chequebook factory: %w", err) | ||
| if chainEnabled { | ||
| chequebookFactory, ferr := InitChequebookFactory(logger, chainBackend, chainID, transactionService, o.SwapFactoryAddress) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
| if o.SwapEnable && ferr != nil { | ||
| return nil, fmt.Errorf("init chequebook factory: %w", ferr) | ||
| } | ||
|
|
||
| erc20Address, err := chequebookFactory.ERC20Address(ctx) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("factory fail: %w", err) | ||
| if ferr == nil { | ||
| erc20Address, err := chequebookFactory.ERC20Address(ctx) | ||
| if err != nil { | ||
| if o.SwapEnable { | ||
| return nil, fmt.Errorf("factory fail: %w", err) | ||
| } | ||
| logger.Warning("unable to resolve ERC20 token address; BZZ balance will be unavailable via /wallet", "error", err) | ||
| } else { | ||
| erc20Service = erc20.New(transactionService, erc20Address) | ||
| } | ||
| } else { | ||
| logger.Warning("unable to init chequebook factory; BZZ balance will be unavailable via /wallet", "error", ferr) | ||
| } | ||
|
|
||
| erc20Service = erc20.New(transactionService, erc20Address) | ||
| if o.SwapEnable { | ||
| if o.ChequebookEnable { | ||
| var err error | ||
| chequebookService, err = InitChequebookService( | ||
| ctx, | ||
| logger, | ||
| stateStore, | ||
| signer, | ||
| chainID, | ||
| chainBackend, | ||
| overlayEthAddress, | ||
| transactionService, | ||
| chequebookFactory, | ||
| o.SwapInitialDeposit, | ||
| erc20Service, | ||
| ) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("init chequebook service: %w", err) | ||
| } | ||
| } | ||
|
|
||
| if o.ChequebookEnable && chainEnabled { | ||
| chequebookService, err = InitChequebookService( | ||
| ctx, | ||
| logger, | ||
| chequeStore, cashoutService = initChequeStoreCashout( | ||
| stateStore, | ||
| signer, | ||
| chainID, | ||
| chainBackend, | ||
| chequebookFactory, | ||
| chainID, | ||
| overlayEthAddress, | ||
| transactionService, | ||
| chequebookFactory, | ||
| o.SwapInitialDeposit, | ||
| erc20Service, | ||
| ) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("init chequebook service: %w", err) | ||
| } | ||
| } | ||
|
|
||
| chequeStore, cashoutService = initChequeStoreCashout( | ||
| stateStore, | ||
| chainBackend, | ||
| chequebookFactory, | ||
| chainID, | ||
| overlayEthAddress, | ||
| transactionService, | ||
| ) | ||
| } | ||
|
|
||
| lightNodes := lightnode.NewContainer(swarmAddress) | ||
|
|
||
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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