Skip to content

fix(walletapi): persist network setting and reset Connected on connectivity failure#12

Open
moralpriest wants to merge 3 commits into
DEROFDN:community-devfrom
moralpriest:fix/wallet-network-persistence
Open

fix(walletapi): persist network setting and reset Connected on connectivity failure#12
moralpriest wants to merge 3 commits into
DEROFDN:community-devfrom
moralpriest:fix/wallet-network-persistence

Conversation

@moralpriest
Copy link
Copy Markdown

fix(walletapi): persist wallet network setting in JSON

Problem:
The mainnet field in the Account struct was lowercase (unexported),
which caused json.Marshal() to skip it during wallet serialization.
When wallets were saved and reopened, the network setting defaulted to
false (testnet) regardless of what the wallet was originally created
with.
Impact:

  • Wallets created as mainnet showed testnet addresses (deto1...)
    after reopening
  • Simulator wallets failed with "Mainnet/TestNet mismatch" because
    the wallet reverted to testnet format
  • Tools like TELA and Engram had to implement workarounds calling
    SetNetwork() after every wallet open
  • Address formatting was inconsistent across sessions
    Root Cause:
    Go's encoding/json only serializes exported (uppercase) fields.
    The field mainnet bool was lowercase, so it was invisible to JSON.
    Fix:
    Changed mainnet to Mainnet with json:"mainnet" tag so the
    network setting is properly persisted across save/load cycles.
    Files Changed:
  • walletapi/wallet.go:
    • Account.Mainnet field (exported with JSON tag)
    • GetAddress() reference updated
    • SetNetwork() reference updated
    • GetNetwork() reference updated
      Backward Compatibility:
  • Old wallets without "mainnet" in JSON: default to false (testnet)
    • This preserves existing behavior for old wallets
    • Tools can call SetNetwork() to upgrade if needed
  • New wallets: correctly persist mainnet=true/false
    Testing:
  • Created wallet with mainnet simulator setting
  • Saved wallet to disk
  • Reopened wallet: address correctly shows dero1... (mainnet)
  • Without this fix: address would show deto1... (testnet)
    Related Issues:
  • Fixes simulator wallet connection failures
  • Removes need for TELA workaround (SetNetwork override)

Note: Pre-existing test failures (Test_Payload_TX, Test_Creation_TX_morecheck) are unrelated to this change and present on base branch community-dev.

Simulator daemon returns Testnet=false but is not mainnet.

This caused wallet connections to fail with Mainnet/TestNet mismatch.

Check for simulator network before mainnet/testnet validation.
The mainnet field in Account struct was lowercase, so json.Marshal

skipped it during wallet serialization. When wallets were reopened,

mainnet defaulted to false (testnet) regardless of original setting.

Changed mainnet to Mainnet with json tag so network setting

persists correctly across wallet save/load cycles.
@8lecramm 8lecramm self-assigned this May 6, 2026
The Connect() function sets Connected=true after a successful WebSocket
dial, but returns directly from test_connectivity() without resetting
it on failure.

This causes consumers to observe Connected==true even when the daemon
connection is invalid (e.g., mainnet/testnet mismatch). Downstream code
then incorrectly proceeds with background tasks against a broken connection.

Reset Connected=false explicitly before returning the error.
@moralpriest moralpriest changed the title fix(walletapi): persist wallet network setting in JSON fix(walletapi): persist network setting and reset Connected on connectivity failure May 7, 2026
@moralpriest
Copy link
Copy Markdown
Author

Updated this PR with an additional fix:

Problem: `walletapi.Connect()` sets `Connected=true` immediately after a successful WebSocket dial, but then returns directly from `test_connectivity()` without resetting it if that subsequent check fails.

This causes consumers (e.g., Engram) to observe `walletapi.Connected == true` even when the daemon connection is actually invalid — such as when a mainnet/testnet network mismatch is detected, or when `DERO.Echo`/`DERO.GetInfo` RPC calls fail. Downstream code then incorrectly proceeds with wallet registration PoW and other background tasks against a broken connection, wasting CPU and producing confusing UI state.

Fix: In `daemon_connectivity.go`, reset `Connected = false` explicitly before returning from `Connect()` when `test_connectivity()` returns an error.

This change is minimal, defensive, and preserves the existing happy path. Both fixes are in `walletapi/daemon_connectivity.go` and are ready for review.

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