Skip to content

feat(opencode): scaffold Balance service for GetBalance - #1334

Merged
bmc08gt merged 3 commits into
code/cashfrom
feat/ocp-balance-rpc
Aug 26, 2026
Merged

feat(opencode): scaffold Balance service for GetBalance#1334
bmc08gt merged 3 commits into
code/cashfrom
feat/ocp-balance-rpc

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Scaffolds the OpenCode Balance service added upstream in ocp-protobuf-api@ea6418c5, and bumps the ocp-client-protocol pin to 0.2.0 to pick it up.

What the contract adds

One unary RPC, ocp.balance.v1.Balance/GetBalance. The request takes an owner account; the response carries a result enum (OK/DENIED/NOT_FOUND) and core_mint_value, a uint64 in quarks. Nothing pre-existing changed.

What this adds

The usual chain in :services:opencode, down to the controller:

BalanceApiBalanceServiceGetBalanceErrorBalanceRepository/InternalBalanceRepositoryBalanceController, plus the Hilt binding.

Nothing consumes it yet. No feature or ViewModel is wired up, because there is no balance surface asking for this today.

Two calls worth review:

  • BalanceApi.getBalance does not sign the request. GetBalanceRequest has no auth or signature field, unlike every other OpenCode endpoint here, so the Api only runs request.validate().orThrow(). That asymmetry is in the contract, not an oversight in this scaffold.
  • BalanceController.getBalance takes a bare PublicKey, not the AccountCluster its sibling controllers take. The RPC resolves any owner's balance rather than the caller's own, so there is no signing authority to thread through. If parity with the neighbours matters more than the narrower type, this is the place to say so.

core_mint_value is typed as Long on the domain model, following the AccountInfo.balance: Long precedent — Fiat needs a CurrencyCode the response does not carry. iOS wraps the same field as TokenAmount(quarks:mint:.usdf). The mint is not on the wire in either case, since core_mint_value is core-mint quarks by definition and the contract never carries a core mint address, so this is only a difference in whether the domain model spells that constant out.

Blocked on

0.2.0 does not exist yet. CI cannot resolve the pin until code-payments/ocp-client-protocol#4 merges and is published, so this stays a draft until then.

Add the app-side layering (Api, Service, Repository, Controller) for the
new Balance.GetBalance RPC now published in com.flipcash:ocp-client-protocol.
GetBalanceRequest carries no auth/signature field, unlike every other OCP
endpoint, so BalanceApi does not sign the request and BalanceController
takes a bare PublicKey rather than an AccountCluster.

No feature or ViewModel consumes this yet.
Picks up the Balance service added upstream in ea6418c5.
…type

The `Balance` data class held one field, a quark count, and the doc comment on it
argued the value could not be a `Fiat` because the response carries no currency
code. That reasoning does not hold: `core_mint_value` is always USDF, and
`Fiat.tokenBalance` already collapses to `Fiat(quarks, CurrencyCode.USD)` on the
USDF branch. USDF is 6 decimals and `Fiat.MULTIPLIER` is 1_000_000, so the quark
count transfers without conversion.

Drop the wrapper and return `Fiat` through the service, repository, and
controller. Callers get formatting and the arithmetic operators for free instead
of unwrapping a Long and constructing the same `Fiat` themselves.
@bmc08gt
bmc08gt marked this pull request as ready for review August 26, 2026 15:57
@bmc08gt
bmc08gt merged commit b3b871b into code/cash Aug 26, 2026
1 check failed
@bmc08gt
bmc08gt deleted the feat/ocp-balance-rpc branch August 27, 2026 15:41
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