Skip to content

[Intermediate]: Implement getFileContents TCK endpoint #1244

@rwalworth

Description

@rwalworth

🧩 Intermediate Friendly

This issue is a good fit for contributors who are already familiar with the Hiero C++ SDK and feel comfortable navigating the codebase.

Intermediate Issues often involve:

  • Exploring existing implementations
  • Understanding how different components work together
  • Making thoughtful changes that follow established patterns

The goal is to support deeper problem-solving while keeping the task clear, focused, and enjoyable to work on.

Important

🧭 About Intermediate Issues

Intermediate Issues are a great next step for contributors who enjoy
digging into the codebase and reasoning about how things work.

These issues often:

  • Involve multiple related files or components
  • Encourage investigation and understanding of existing behavior
  • Leave room for thoughtful implementation choices
  • Stay focused on a clearly defined goal

Other kinds of contributions — from beginner-friendly tasks to large
system-level changes — are just as valuable and use different labels.


🐞 Problem Description

The TCK (Test Compatibility Kit) server in this repository exposes JSON-RPC endpoints that the hiero-sdk-tck test suite calls to verify SDK behavior across all Hiero SDKs.

The FileService currently implements transaction endpoints (createFile, deleteFile, updateFile) but is missing the getFileContents query endpoint. The TCK test file test-file-contents-query.ts calls this method and cannot run against this C++ SDK until it is implemented.

The full TCK specification for this endpoint — including all input/output parameters, test cases, and expected behavior — is published here:

FileContentsQuery — TCK Test Specification

The SDK already has a fully implemented FileContentsQuery class in src/sdk/main/include/FileContentsQuery.h. This issue is about wiring up that existing class to the TCK server.

What makes this interesting: This endpoint introduces query payment parameters (queryPayment and maxQueryPayment) which are not present in any of the existing FileService endpoints. These map to Query::setQueryPayment(const Hbar&) and Query::setMaxQueryPayment(const Hbar&) on the base Query class. The response also requires converting a std::vector<std::byte> to a string, which is a different serialization pattern from existing endpoints.


💡 Expected Outcome

The TCK server should respond to a new getFileContents JSON-RPC method. The full input/output parameter specification is defined in the TCK docs. In summary:

Inputs:

Parameter Type Required Description
fileId string required The ID of the file to query
queryPayment string optional Explicit payment amount in tinybars
maxQueryPayment string optional Maximum payment amount in tinybars

Output: { "contents": "..." } — the file contents as a string

The implementation should:

  • Follow the query pattern established by getAccountInfo / getAccountBalance in AccountService.cc
  • Use FileContentsQuery from the SDK
  • Support optional queryPayment and maxQueryPayment via the Query base class methods
  • Convert the FileContents (std::vector<std::byte>) result to a string for the JSON response
  • Not modify any existing endpoints or SDK behavior

🧠 Implementation Notes

Architecture

Each TCK endpoint has four parts:

  1. Params struct — a header in src/tck/include/file/params/ that defines the JSON-RPC parameters and their deserialization
  2. Service header — a function declaration in src/tck/include/file/FileService.h
  3. Service implementation — the function body in src/tck/src/file/FileService.cc
  4. Server registration — wiring in src/tck/src/TckServer.cc (include, addMethod call, template instantiation)

Reference implementations

What you're building Closest existing reference
GetFileContentsParams struct src/tck/include/account/params/GetAccountInfoParams.h — similar query params pattern, but add mQueryPayment and mMaxQueryPayment fields
getFileContents function getAccountBalance in src/tck/src/account/AccountService.cc — simpler query pattern
Query payment methods src/sdk/main/include/Query.hsetQueryPayment(const Hbar&) (line 129) and setMaxQueryPayment(const Hbar&) (line 139)

Things to think about

  • Byte-to-string conversion: FileContentsQuery::execute() returns FileContents, which is a type alias for std::vector<std::byte> (defined in FileContentsQuery.h line 21). To convert this to a string for the JSON response, use Hiero::internal::Utilities::byteVectorToString() from <impl/Utilities.h> (this header is already included in FileService.cc).

  • Query payment parameters: The queryPayment and maxQueryPayment values arrive as strings representing tinybars. Parse them and pass to the query using Hbar::fromTinybars(). Look at how CommonTransactionParams handles mMaxTransactionFee for a similar pattern.

  • No commonTransactionParams: This is a query, not a transaction. The params struct should not include CommonTransactionParams.

Files to create and modify

File Action
src/tck/include/file/params/GetFileContentsParams.h Create — params struct with mFileId, mQueryPayment, mMaxQueryPayment
src/tck/include/file/FileService.h Edit — add forward declaration and function declaration
src/tck/src/file/FileService.cc Edit — add includes (FileContentsQuery.h, Hbar.h) and getFileContents implementation
src/tck/src/TckServer.cc Edit — add include, register method, add template instantiation

Key SDK headers to study

File What to learn
src/sdk/main/include/FileContentsQuery.h setFileId, returns FileContents (std::vector<std::byte>) via execute()
src/sdk/main/include/Query.h setQueryPayment(const Hbar&), setMaxQueryPayment(const Hbar&)
src/sdk/main/include/Hbar.h Hbar::fromTinybars(int64_t) — for parsing payment amounts
src/sdk/main/include/impl/Utilities.h byteVectorToString(const std::vector<std::byte>&) — for converting file contents to string

✅ Acceptance Criteria

To help get this change merged smoothly:

  • Endpoint: getFileContents is registered in TckServer and responds to JSON-RPC calls
  • Parameters: Correctly deserializes fileId, queryPayment, and maxQueryPayment from JSON
  • Query payments: queryPayment and maxQueryPayment are correctly applied via Query base class methods when provided
  • Response: Returns { "contents": "..." } with the file contents as a string, as specified in the TCK docs
  • Pattern: Implementation follows the same query structure as existing AccountService query endpoints
  • Behavior: No changes to existing endpoints or SDK behavior
  • Build: Project compiles successfully
  • Tests: Existing CI checks pass
  • Review: All code review feedback addressed

📋 Contribution Guide

To help your contribution go as smoothly as possible, we recommend following these steps:

  • Comment /assign to request the issue
  • Wait for assignment
  • Fork the repository and create a branch
  • Set up the project using the instructions in README.md
  • Make the requested changes
  • Sign each commit using -s -S
  • Push your branch and open a pull request

Read Workflow Guide for step-by-step workflow guidance.
Read README.md for setup instructions.

❗ Pull requests cannot be merged without S and s signed commits.
See the Signing Guide.


📚 Additional Context or Resources

If you have questions, the community is happy to help:

Hiero-SDK-C++ Discord

Metadata

Metadata

Assignees

Labels

priority: mediumNormal priority; to be addressed in the standard development cycleskill: intermediateRequires familiarity with the codebase structure and SDK concepts
No fields configured for Feature.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions