Skip to content

feat(opencode): move to the batched GetBalances RPC - #1458

Merged
bmc08gt merged 2 commits into
code/cashfrom
feat/ocp-get-balances
Sep 14, 2026
Merged

bmc08gt merged 2 commits into
code/cashfrom
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 this pins a version that does not exist yet — Gradle resolution reports com.flipcash:ocp-client-protocol:0.4.0 FAILED until then. CI never sees the local override, since protoLocalRoot lives in untracked local.properties.

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 sites.

The request goes from a single owner to repeated owners (1-1024) plus an optional mints filter. The response goes from a flat core_mint_value to map<string, OwnerBalance> balances_by_owner, where each entry keeps a core_mint_value total and adds a balances_by_mint breakdown.

What changed

All under services/opencode/src/main/kotlin/com/getcode/opencode/:

File Change
internal/network/api/BalanceApi.kt getBalance(owner)getBalances(owners, mints = emptyList()), built with addAllOwners/addAllMints
internal/network/services/BalanceService.kt maps the new Result enum, returns Result<List<OwnerBalance>> from balancesByOwnerMap.values
model/financial/OwnerBalance.kt new domain type mirroring the proto's two-level shape
internal/domain/mapping/OwnerBalanceMapper.kt new mapper, reusing the existing SolanaAccountId.toPublicKey()/.toMint() extensions
repositories/BalanceRepository.kt, internal/domain/repositories/InternalBalanceRepository.kt plural signature
controllers/BalanceController.kt plural signature; still takes bare PublicKeys, as the RPC stays unauthenticated
model/core/errors/Errors.kt GetBalanceErrorGetBalancesError per the repo's Get<Rpc>Error convention, NotFound case removed

NOT_FOUND is gone from the proto Result enum. OK and DENIED keep 0 and 1, so nothing renumbered, but an owner with no balances is now absent from the map rather than signalled by a result code. InternalBalanceRepository now only special-cases Denied before reporting.

ocp-protobuf-api replaced Balance.GetBalance with GetBalances (owners list,
optional mint filter, owner -> mint -> quarks map). Update BalanceApi,
BalanceService, BalanceRepository, and BalanceController through the same
chain, add an OwnerBalance domain type plus mapper to carry the two-level
result, and drop the now-impossible NOT_FOUND handling in favor of the
absent-map-entry path. Compiles against the local ocp-client-protocol
checkout via protoLocalRoot.

No feature currently calls BalanceController, so this is scaffolding only.
@bmc08gt bmc08gt self-assigned this Sep 14, 2026
@github-actions github-actions Bot added area: network gRPC, connectivity, API, exchange rates area: build-system Gradle, convention plugins, build-logic type: feature New functionality labels Sep 14, 2026
@bmc08gt
bmc08gt marked this pull request as ready for review September 14, 2026 19:05
@bmc08gt
bmc08gt merged commit f07170d into code/cash Sep 14, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: build-system Gradle, convention plugins, build-logic area: network gRPC, connectivity, API, exchange rates type: feature New functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant