hiero-ledger / hiero-ledger/hiero-sdk-cpp

Deprecate AccountBalanceQuery

Open
#1,723 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
42
Forks
108
Avg merge
11h 45m
Merged PRs (30d)
2

Description

# Deprecate `AccountBalanceQuery`

> Suggested labels: `good first issue candidate`, plus this repo's usual area label (e.g. `sdk`).
> Per Hiero's [Good First Issue Guidelines](https://github.com/hiero-ledger/governance/blob/main/rules-and-guidelines/good-first-issues.md), apply `good first issue candidate` — a maintainer will promote it to `good first issue` after review.
>
> **Depends on:** the companion Stage 1 issue (replacing the `Client::ping()` probe) should land first, since both touch related code paths and Stage 1 is more time-sensitive.

## 👾 Description of the issue

The Hedera network is retiring an old way of asking a consensus node "what is this account's balance?" (the `CryptoService/cryptoGetBalance` gRPC endpoint). Starting with consensus node release 77, this endpoint is being throttled down to zero calls, which means it stops working entirely. The estimated dates are testnet on August 13, 2026 and mainnet on September 9, 2026.

In the C++ SDK, this endpoint is used by the `AccountBalanceQuery` class, defined in [`src/sdk/main/src/AccountBalanceQuery.cc`](https://github.com/hiero-ledger/hiero-sdk-cpp/blob/main/src/sdk/main/src/AccountBalanceQuery.cc) (and its header, likely `include/AccountBalanceQuery.h`). Right now, its `buildRequest`/`submitRequest`/`mapResponse` methods (around lines 41-92) still construct and send a real gRPC request. Once the network shuts the endpoint off, this call will simply fail with a confusing network error instead of a clear message.

We want to mark `AccountBalanceQuery` as deprecated ahead of time, and make execution fail immediately with a clear, friendly error message pointing developers to the replacement (the mirror node REST API), instead of letting it fail with a confusing gRPC error later.

Background reading:
- [Full deprecation proposal](https://github.com/hiero-ledger/sdk-collaboration-hub/blob/main/proposals/account-balance-query-deprecation.md) (see "Constructor — deprecation warning" and "Execute — hard error" sections)
- [Hedera blog: Migrating from AccountBalanceQuery](https://hedera.com/blog/migrating-from-accountbalancequery-what-you-need-to-know/)

## 💡 Solution

1. Open [`include/AccountBalanceQuery.h`](https://github.com/hiero-ledger/hiero-sdk-cpp/blob/main/src/sdk/main/include/AccountBalanceQuery.h) (adjust path if the header lives elsewhere) and [`src/sdk/main/src/AccountBalanceQuery.cc`](https://github.com/hiero-ledger/hiero-sdk-cpp/blob/main/src/sdk/main/src/AccountBalanceQuery.cc) in the C++ SDK repo.
2. Mark the class deprecated using the C++14 `[[deprecated]]` attribute, with a helpful message.
3. Make sure that whichever method actually triggers the network call (`submitRequest`, or wherever `execute()` ultimately routes to) throws an exception immediately, with a clear message, and does **not** send the gRPC request.
4. Add or update tests to check that (a) the deprecation attribute is present and (b) calling `execute()` throws the new error without making a network call.

### 👩‍💻 Implementation

1. In `AccountBalanceQuery.h`, add the attribute to the class declaration, similar to:
```cpp
class [[deprecated(
"AccountBalanceQuery will stop working when the Hedera network removes the "
"CryptoGetBalance endpoint (estimated September 2026, consensus node release 77). "
"Use the mirror node REST API to retrieve account balances.")]] AccountBalanceQuery
: public Query
{
...
};
```
See [cppreference on `[[deprecated]]`](https://en.cppreference.com/w/cpp/language/attributes/deprecated) for exact syntax and placement rules.
2. In `AccountBalanceQuery.cc`, locate `submitRequest` (line 48-54, alongside `mapResponse` at line 41 and `buildRequest` at line 71) which currently calls `node->submitQuery(...)` to send the real gRPC request. Replace its body so it throws an exception immediately containing the text `"AccountBalanceQuery is no longer supported"` instead of submitting the query. Use the existing [`UnsupportedOperationException`](https://github.com/hiero-ledger/hiero-sdk-cpp/blob/main/src/sdk/main/include/exceptions/UnsupportedOperationException.h) in `include/exceptions/` — its doc comment ("Exception that encompasses trying to execute any unsupported operation") is an exact match for this case, so there's no need to introduce a new exception type.
3. Add a unit test in [`src/sdk/tests/unit/AccountBalanceQueryUnitTests.cc`](https://github.com/hiero-ledger/hiero-sdk-cpp/blob/main/src/sdk/tests/unit/AccountBalanceQueryUnitTests.cc) (the existing test file for this class) that constructs an `AccountBalanceQuery`, calls `.execute()` against a mock/test client, and asserts it throws the new exception without making a network call.
4. Since `[[deprecated]]` will trigger compiler warnings anywhere the class is used internally (including in the SDK's own tests or examples), check the build output for those warnings and address them consistently — e.g. by removing internal usages if they exist, or wrapping the specific lines with an appropriate warning-suppression pragma if the codebase already has a convention for that.
5. Build and run the existing test suite (see the repo's `README.md`/`CONTRIBUTING.md` for CMake build instructions) to confirm nothing else regresses.

## 📋 Step by step guide to do a contribution

If you have never contributed to an open source project at GitHub, the following step-by-step guide will introduce you to the workflow.
More information and concrete samples for shell commands for each step can be found in our [CONTRIBUTING.md](https://github.com/hiero-ledger/.github/blob/main/CONTRIBUTING.md) file.
A more detailed general documentation of the GitHub PR workflow can be found [here](https://github.com/firstcontributions/first-contributions/blob/master/README.md).

- [ ] **Claim this issue:** Comment below that you are interested in working on the issue
- [ ] **Wait for assignment:** A community member with the given rights will add you as an assignee of the issue
- [ ] **Meanwhile, review:** How [DCO works](https://github.com/cncf/dco2) and how to create signed commits
- [ ] **Work on the issue:** Follow the detailed description in our [CONTRIBUTING.md](https://github.com/hiero-ledger/.github/blob/main/CONTRIBUTING.md) file.
- [ ] **Track:** Test failures, comments and reviews. Make sure to rebase your change to the main branch and resolve any conflicts.
- [ ] **You did it 🎉:** If approved, we will merge the fix in the main branch. Thanks for being part of the Hiero community as an open-source contributor ❤️

***IMPORTANT*** Your pull request CANNOT BE MERGED until you add a changelog entry AND sign your commits each with `git commit -S -s -m "chore: your commit message"` and a GPG key***

## 🤔 Additional Information

If you have any questions about the topic of this issue, please ask us directly by adding a comment below.
Additionally, we invite you to join our community on our [Discord](https://discord.gg/kEnnmB9A) server or attend our [public community calls](https://zoom-lfx.platform.linuxfoundation.org/meetings/hiero?view=week).

A general manual about open-source contributions can be found [here](https://github.com/firstcontributions/first-contributions/blob/master/README.md).

Contributor guide

Open the contributing guide

Research direction

Start with include/AccountBalanceQuery.h and src/sdk/main/src/AccountBalanceQuery.cc, then trace how execute() reaches submitRequest and review UnsupportedOperationException. Add the deprecation attribute and immediate unsupported-operation failure, and update src/sdk/tests/unit/AccountBalanceQueryUnitTests.cc to verify no network call occurs. Build the SDK and run the existing tests, checking for deprecation warnings and required changelog or contribution checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
blockchain, testing
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.