Skip to content

feat(balance): move to the batched GetBalances RPC - #764

Merged
bmc08gt merged 3 commits into
mainfrom
feat/ocp-get-balances
Sep 15, 2026
Merged

bmc08gt merged 3 commits into
mainfrom
feat/ocp-get-balances

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Blocked on code-payments/ocp-client-protocol#6. Draft until 0.4.0 is published, because the exact: requirement in FlipcashAPI/Package.swift has no tag to resolve until then. CI never sees the local override, since FLIPCASH_PROTO_LOCAL is a shell variable.

Why

ocp-protobuf-api removed GetBalance in favour of GetBalances (#66). The Balance service had exactly one RPC, so there is no way to take the new package without moving the call site.

What changed

One file, FlipcashCore/Sources/FlipcashCore/Clients/Payments API/Services/BalanceService.swift:

  • Request: Ocp_Balance_V1_GetBalanceRequest.with { $0.owner = ... }Ocp_Balance_V1_GetBalancesRequest.with { $0.owners = [owner.solanaAccountID] }
  • Call: service.getBalance(...)service.getBalances(...), still options: .unaryDefault
  • Response: response.coreMintValueresponse.balancesByOwner[owner.base58]?.coreMintValue ?? 0, since the total now lives one level down, keyed by owner address
  • ErrorGetBalance: .notFound removed, and the reportingLevel switch loses that arm

Client+Balance.swift needed no change. It does not touch the removed types, and its "no signature required" doc comment still holds — GetBalancesRequest carries no auth field either.

The rawValue mapping

ErrorGetBalance(rawValue: response.result.rawValue) maps positionally onto the proto Result enum, which is the case worth checking whenever an enum changes. The old enum was OK=0, DENIED=1, NOT_FOUND=2; the new one is OK=0, DENIED=1. The surviving cases keep their numbers, so this is a clean case removal with no silent rawValue drift.

An owner with no balances is now absent from balances_by_owner rather than reported through a result code, so a missing entry maps to a zero TokenAmount and counts as success, not an error.

@bmc08gt bmc08gt self-assigned this Sep 14, 2026
@bmc08gt
bmc08gt marked this pull request as ready for review September 14, 2026 19:06
ocp-protobuf-api removed GetBalance in favour of GetBalances, which takes a
list of owners and returns an owner -> mint -> value map instead of a flat
total. BalanceService.getBalance stays single-owner-shaped for now (nothing
in the app needs the batched or mint-filtered form yet) and reads its one
owner back out of the map.

The response's NOT_FOUND result case is gone; an owner absent from the map
now means zero balance rather than a distinct error, so ErrorGetBalance
drops .notFound and getBalance treats a missing entry as a zero TokenAmount.
@bmc08gt
bmc08gt force-pushed the feat/ocp-get-balances branch from d9bbd58 to 78b744c Compare September 15, 2026 17:24
@bmc08gt
bmc08gt merged commit 8df40b5 into main Sep 15, 2026
@bmc08gt
bmc08gt deleted the feat/ocp-get-balances branch September 15, 2026 17:48
bmc08gt added a commit that referenced this pull request Sep 15, 2026
… pins (#778)

#764 bumped ocp to 0.4.0 and #769 bumped flipcash2 to 0.6.0 without regenerating
the workspace's Package.resolved, so it still recorded 0.3.0 and 0.5.0. Xcode
Cloud archives with automatic dependency resolution disabled, which turns that
mismatch into a hard error rather than a silent re-resolve: "Deploy Flipcash"
build #542 failed with "an out-of-date resolved file was detected". The vector
gate builds the SPM schemes with resolution enabled and never opens
Code.xcodeproj, so it stayed green.

Regenerated with xcodebuild -resolvePackageDependencies. Only the two contract
entries and originHash move.
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.

1 participant