Skip to content

Comments

feat(cli): use either Repository or JSON-RPC API to read data#738

Open
renatomaia wants to merge 5 commits intofeatures/cli-read-prt-datafrom
features/cli-read-jsonrpc
Open

feat(cli): use either Repository or JSON-RPC API to read data#738
renatomaia wants to merge 5 commits intofeatures/cli-read-prt-datafrom
features/cli-read-jsonrpc

Conversation

@renatomaia
Copy link

closes #723

@renatomaia renatomaia requested a review from vfusco February 19, 2026 19:02
@renatomaia renatomaia self-assigned this Feb 19, 2026
@renatomaia renatomaia force-pushed the features/cli-read-prt-data branch from efdc751 to 305b9fd Compare February 19, 2026 19:42
@renatomaia renatomaia force-pushed the features/cli-read-jsonrpc branch from 01145bf to 5ded42b Compare February 19, 2026 19:51
@vfusco vfusco requested a review from Copilot February 20, 2026 15:20
@vfusco vfusco added this to the 2.0.0 milestone Feb 20, 2026
@vfusco vfusco added this to Node Unit Feb 20, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a ReadService abstraction for the CLI read subcommands so they can fetch data either from the local DB (via repository) or from a remote JSON-RPC endpoint, aligning CLI “read” outputs with the JSON-RPC API shapes.

Changes:

  • Added internal/read.ReadService interface plus DB-backed (RepositoryReadService) and JSON-RPC-backed (JsonrpcReadService) implementations.
  • Updated multiple CLI read subcommands to use the new datasource abstraction.
  • Added a new config/env var/flag for selecting a remote JSON-RPC endpoint (CARTESI_JSONRPC_ENDPOINT, --jsonrpc-endpoint).

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 30 comments.

Show a summary per file
File Description
internal/read/types.go Introduces ReadService interface for read operations.
internal/read/repository.go Implements DB-backed read service using repository and marshals JSON-RPC-shaped responses.
internal/read/jsonrpc.go Implements JSON-RPC-backed read service using the JSON-RPC client.
internal/config/generated.go Adds CARTESI_JSONRPC_ENDPOINT to generated config and loads it into node/jsonrpc configs.
internal/config/generate/Config.toml Declares CARTESI_JSONRPC_ENDPOINT in the config generator inputs.
cmd/cartesi-rollups-cli/root/root.go Adds --jsonrpc-endpoint flag (bound to config).
cmd/cartesi-rollups-cli/root/read//.go Switches subcommands to use ReadService and JSON-RPC params types.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +49 to +52
Cmd.PersistentFlags().StringVar(&databaseConnection, "jsonrpc-endpoint", "",
"JSON-RPC endpoint string in the URL format\n(eg.: 'https://localhost:10011/rpc')")
cobra.CheckErr(viper.BindPFlag(config.JSONRPC_ENDPOINT, Cmd.PersistentFlags().Lookup("jsonrpc-endpoint")))
cobra.CheckErr(Cmd.PersistentFlags().MarkHidden("jsonrpc-endpoint"))
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--jsonrpc-endpoint is marked hidden, but issue #723/PR intent is to expose and document this flag/env var for selecting the datasource. Consider not hiding it (or at least unhide it in read help output) so it shows up in --help as required.

Copilot uses AI. Check for mistakes.
Comment on lines 109 to 112
// Add epoch index filter if provided
if cmd.Flags().Changed("epoch-index") {
filter.EpochIndex = &epochIndex
params.EpochIndex = &epochIndex
}
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--epoch-index / --input-index are described as "decimal or hex encoded", but the JSON-RPC API expects 0x... hex strings (see internal/jsonrpc.ParseIndex). If decimals should remain supported, normalize these flag values to hex before setting params.EpochIndex/params.InputIndex.

Copilot uses AI. Check for mistakes.
Comment on lines 80 to 85
addr, err := config.GetJsonrpcEndpoint()
cobra.CheckErr(err)

repo, err := factory.NewRepositoryFromConnectionString(ctx, dsn.String())
if addr != "" {
readServ, err = read.NewJsonrpcReadService(ctx, addr)
} else {
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.GetJsonrpcEndpoint() returns ErrNotDefined when unset, so cobra.CheckErr(err) prevents falling back to the DB datasource. Treat ErrNotDefined as "endpoint not provided" (addr="") instead of a fatal error.

Copilot uses AI. Check for mistakes.
Comment on lines 80 to 85
addr, err := config.GetJsonrpcEndpoint()
cobra.CheckErr(err)

repo, err := factory.NewRepositoryFromConnectionString(ctx, dsn.String())
if addr != "" {
readServ, err = read.NewJsonrpcReadService(ctx, addr)
} else {
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.GetJsonrpcEndpoint() returns ErrNotDefined when unset, so cobra.CheckErr(err) prevents falling back to the DB datasource. Treat ErrNotDefined as "endpoint not provided" (addr="") instead of a fatal error.

Copilot uses AI. Check for mistakes.
Comment on lines +49 to +51
Cmd.PersistentFlags().StringVar(&databaseConnection, "jsonrpc-endpoint", "",
"JSON-RPC endpoint string in the URL format\n(eg.: 'https://localhost:10011/rpc')")
cobra.CheckErr(viper.BindPFlag(config.JSONRPC_ENDPOINT, Cmd.PersistentFlags().Lookup("jsonrpc-endpoint")))
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue #723 proposes --jsonrpc-endpoint with env var CARTESI_JSONRPC_API_ADDRESS, but the implementation introduces a new env var CARTESI_JSONRPC_ENDPOINT. If the issue text is the source of truth, consider reusing CARTESI_JSONRPC_API_ADDRESS (or clearly documenting why a new variable is needed and how it relates to the existing one).

Copilot uses AI. Check for mistakes.
Comment on lines 104 to 108
// Create argumment variables
params.Application = args[0]
params.OutputIndex = args[1]

response = map[string]any{
"data": dataVal,
}
result, err = readServ.GetOutput(ctx, params)
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params.OutputIndex = args[1] passes the user-provided index through unchanged, but the JSON-RPC API requires 0x... hex strings for indices. This also makes the example ... outputs echo-dapp 10 invalid. Normalize decimal-or-hex input into a 0x... string before calling the datasource.

Copilot uses AI. Check for mistakes.
Comment on lines 98 to 102
// Create argumment variables
params.Application = args[0]
params.EpochIndex = args[1]
params.TournamentAddress = args[2]
params.Commitment = args[3]
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params.EpochIndex = args[1] passes the user-provided epoch index through unchanged, but the JSON-RPC API requires 0x... hex strings for indices. This also makes the example ... commitments echo-dapp 10 ... invalid. Normalize decimal-or-hex input into a 0x... string before calling the datasource.

Copilot uses AI. Check for mistakes.
Comment on lines 98 to 102
// Create argumment variables
params.Application = args[0]
params.InputIndex = args[1]

response = map[string]any{
"data": dataVal,
}
result, err = readServ.GetInput(ctx, params)
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params.InputIndex = args[1] passes user input through unchanged, but the JSON-RPC API requires 0x... hex strings for indices. This also makes the example ... inputs echo-dapp 10 invalid. Consider parsing decimal-or-hex input and normalizing it to a 0x... string before calling the datasource.

Copilot uses AI. Check for mistakes.
Comment on lines 71 to 76
addr, err := config.GetJsonrpcEndpoint()
cobra.CheckErr(err)

repo, err := factory.NewRepositoryFromConnectionString(ctx, dsn.String())
if addr != "" {
readServ, err = read.NewJsonrpcReadService(ctx, addr)
} else {
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.GetJsonrpcEndpoint() returns ErrNotDefined when unset, so cobra.CheckErr(err) prevents falling back to the DB datasource. Treat ErrNotDefined as "endpoint not provided" (addr="") instead of a fatal error.

Copilot uses AI. Check for mistakes.
Comment on lines 115 to 118
// Add epoch index filter if provided
if cmd.Flags().Changed("epoch-index") {
filter.EpochIndex = &epochIndex
params.EpochIndex = &epochIndex
}
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--epoch-index / --level are described as "decimal or hex encoded", but the JSON-RPC API expects 0x... hex strings for these fields (see internal/jsonrpc.ParseIndex). If decimals should remain supported, normalize these flag values to hex before setting params.EpochIndex/params.Level (and update examples accordingly).

Copilot uses AI. Check for mistakes.
@renatomaia renatomaia force-pushed the features/cli-read-jsonrpc branch from 5ded42b to 18aea27 Compare February 20, 2026 18:29
@renatomaia renatomaia force-pushed the features/cli-read-prt-data branch from e84cea7 to 1b7160a Compare February 20, 2026 19:01
@renatomaia renatomaia force-pushed the features/cli-read-jsonrpc branch from 18aea27 to a23cf08 Compare February 20, 2026 19:01
@renatomaia renatomaia force-pushed the features/cli-read-prt-data branch from 1b7160a to d93c155 Compare February 20, 2026 21:08
@renatomaia renatomaia force-pushed the features/cli-read-jsonrpc branch 2 times, most recently from 6a0c122 to 2f44070 Compare February 20, 2026 22:35
@renatomaia renatomaia force-pushed the features/cli-read-prt-data branch from d93c155 to ac88e77 Compare February 20, 2026 22:35
@renatomaia renatomaia force-pushed the features/cli-read-prt-data branch from ac88e77 to 90c3e94 Compare February 21, 2026 03:19
@renatomaia renatomaia force-pushed the features/cli-read-jsonrpc branch from 2f44070 to e7b09d6 Compare February 21, 2026 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants