Skip to content

platform-wallet: make Rust the single source of Core transaction accounting (drop Swift re-derivation) #5226

Description

@lklimek

Summary

Make Rust the single source of Core transaction accounting (net_amount, direction, ownership). Remove the independent re-derivation in the Swift SDK.

Problem

Two implementations compute the same values with different rules:

  • SwiftData: reconcileTransactionAccounting in PlatformWalletPersistenceHandler.swift, run on load and at the end of each persistence round.
  • Rust: the SQLite repair core_history::repair_record and the live wallet projection.

Where they differ:

The same wallet can therefore show different history on DET (SQLite) and iOS (SwiftData), and every checker or contact-ownership change must be made twice. packages/swift-sdk/CLAUDE.md already states that Rust owns this logic.

Plan

  1. fix(platform-wallet)!: replay recorded transaction history on load for every persister #5220 (stacked on fix(platform-wallet)!: restore Core spending state and repair persisted accounting #5150) hands the stored history to Rust on load, including the stored net_amount and direction.
  2. Follow-up: after the load-time replay, fold per-account slices into wallet-level records, diff them against the stored values, and emit only corrected records through the normal persist callbacks. Never downgrade a stored spend when prevout history is missing.
  3. Delete the Swift re-derivation: reconcileTransactionAccounting, accountingDirty, reconciledAccounting, the preserveLockAccounting special case, and the related tests.
  4. Add a parity test between the fold and SQLite repair_record.

Open decisions

  • Cross-wallet rows: a SwiftData PersistentTransaction is keyed by txid across all local wallets, while Rust emits per-wallet values. Proposal: add a spends_wallet_funds flag to TransactionRecordFFI and keep one precedence rule in Swift.
  • Live gap: if a spender is already chain-locked and pruned when its funding transaction is discovered later in the same session, Rust corrects the record only at the next load.

References

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions