Skip to content

Commit db6f165

Browse files
committed
refactor(jsonrpc): remove stale client wrappers
1 parent b8ab926 commit db6f165

1 file changed

Lines changed: 5 additions & 331 deletions

File tree

pkg/jsonrpc/client/client.go

Lines changed: 5 additions & 331 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// (c) Cartesi and individual authors (see AUTHORS)
22
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)
33

4-
// Package client provides a JSON‑RPC client that can be used as a library
5-
// by other services or commands.
4+
// Package client provides a minimal JSON-RPC 2.0 transport for the rollups
5+
// node API. Callers invoke methods through the generic Call and decode the
6+
// result themselves; the response envelope and parameter shapes are defined
7+
// by the server's OpenRPC specification (served via rpc.discover).
68
package client
79

810
import (
@@ -13,29 +15,9 @@ import (
1315
"io"
1416
"net/http"
1517
"sync/atomic"
16-
17-
"github.com/cartesi/rollups-node/internal/model"
1818
)
1919

20-
// JsonRpcClient defines the interface for our client so it can be mocked.
21-
type JsonRpcClient interface {
22-
Discover(ctx context.Context) (any, error)
23-
ListApplications(ctx context.Context, limit, offset int64) ([]*model.Application, error)
24-
GetApplication(ctx context.Context, application string) (*model.Application, error)
25-
GetApplicationAddress(ctx context.Context, name string) (string, error)
26-
ListEpochs(ctx context.Context, application string, status *string, limit, offset int64) ([]*model.Epoch, error)
27-
GetEpoch(ctx context.Context, application string, index uint64) (*model.Epoch, error)
28-
GetLastAcceptedEpochIndex(ctx context.Context, application string) (uint64, error)
29-
ListInputs(ctx context.Context, application string, epochIndex *string, sender *string, decode bool, limit, offset int64) ([]interface{}, error)
30-
GetInput(ctx context.Context, application string, inputIndex string, decode bool) (any, error)
31-
GetProcessedInputCount(ctx context.Context, application string) (int64, error)
32-
ListOutputs(ctx context.Context, application string, epochIndex, inputIndex, rawDataPrefix, outputType, voucherAddress *string, decode bool, limit, offset int64) ([]interface{}, error)
33-
GetOutput(ctx context.Context, application string, outputIndex string, decode bool) (any, error)
34-
ListReports(ctx context.Context, application string, epochIndex, inputIndex *string, limit, offset int64) ([]*model.Report, error)
35-
GetReport(ctx context.Context, application string, reportIndex string) (*model.Report, error)
36-
}
37-
38-
// Client is the concrete implementation of JsonRpcClient.
20+
// Client is a JSON-RPC 2.0 client over HTTP.
3921
type Client struct {
4022
// URL is the endpoint of the JSON‑RPC service.
4123
URL string
@@ -127,311 +109,3 @@ func (c *Client) Call(ctx context.Context, method string, params any, result any
127109
}
128110
return nil
129111
}
130-
131-
// -----------------------------------------------------------------------------
132-
// Wrapper Types for Responses
133-
// -----------------------------------------------------------------------------
134-
135-
type ApplicationListResult struct {
136-
Applications []*model.Application `json:"applications"`
137-
}
138-
139-
type ApplicationGetResult struct {
140-
Application *model.Application `json:"application"`
141-
}
142-
143-
type GetApplicationAddressResult struct {
144-
Address string `json:"address"`
145-
}
146-
147-
type EpochListResult struct {
148-
Epochs []*model.Epoch `json:"epochs"`
149-
}
150-
151-
type EpochGetResult struct {
152-
Epoch *model.Epoch `json:"epoch"`
153-
}
154-
155-
type InputListResult struct {
156-
Inputs []any `json:"inputs"`
157-
}
158-
159-
type InputGetResult struct {
160-
Input any `json:"input"`
161-
}
162-
163-
type OutputListResult struct {
164-
Outputs []any `json:"outputs"`
165-
}
166-
167-
type OutputGetResult struct {
168-
Output any `json:"output"`
169-
}
170-
171-
type ReportListResult struct {
172-
Reports []*model.Report `json:"reports"`
173-
}
174-
175-
type ReportGetResult struct {
176-
Report *model.Report `json:"report"`
177-
}
178-
179-
// -----------------------------------------------------------------------------
180-
// Wrapper Methods
181-
// -----------------------------------------------------------------------------
182-
183-
// Discover calls the "rpc.discover" method and returns the service specification.
184-
func (c *Client) Discover(ctx context.Context) (any, error) {
185-
var spec any
186-
if err := c.Call(ctx, "rpc.discover", []any{}, &spec); err != nil {
187-
return nil, err
188-
}
189-
return spec, nil
190-
}
191-
192-
// ListApplications calls "cartesi_ListApplications".
193-
func (c *Client) ListApplications(ctx context.Context, limit, offset int64) ([]*model.Application, error) {
194-
// Cap limit at 10,000.
195-
if limit > 10000 {
196-
limit = 10000
197-
}
198-
params := struct {
199-
Limit int64 `json:"limit"`
200-
Offset int64 `json:"offset"`
201-
}{Limit: limit, Offset: offset}
202-
var result ApplicationListResult
203-
if err := c.Call(ctx, "cartesi_listApplications", params, &result); err != nil {
204-
return nil, err
205-
}
206-
return result.Applications, nil
207-
}
208-
209-
// GetApplication calls "cartesi_getApplication".
210-
func (c *Client) GetApplication(ctx context.Context, application string) (*model.Application, error) {
211-
params := struct {
212-
Application string `json:"application"`
213-
}{Application: application}
214-
var result ApplicationGetResult
215-
if err := c.Call(ctx, "cartesi_getApplication", params, &result); err != nil {
216-
return nil, err
217-
}
218-
return result.Application, nil
219-
}
220-
221-
// GetApplicationAddress calls "cartesi_getApplicationAddress".
222-
func (c *Client) GetApplicationAddress(ctx context.Context, name string) (string, error) {
223-
params := struct {
224-
Name string `json:"name"`
225-
}{Name: name}
226-
var result GetApplicationAddressResult
227-
if err := c.Call(ctx, "cartesi_getApplicationAddress", params, &result); err != nil {
228-
return "", err
229-
}
230-
return result.Address, nil
231-
}
232-
233-
// ListEpochs calls "cartesi_ListEpochs".
234-
func (c *Client) ListEpochs(ctx context.Context, application string, status *string, limit, offset int64) ([]*model.Epoch, error) {
235-
if limit > 10000 {
236-
limit = 10000
237-
}
238-
params := struct {
239-
Application string `json:"application"`
240-
Status *string `json:"status,omitempty"`
241-
Limit int64 `json:"limit"`
242-
Offset int64 `json:"offset"`
243-
}{
244-
Application: application,
245-
Status: status,
246-
Limit: limit,
247-
Offset: offset,
248-
}
249-
var result EpochListResult
250-
if err := c.Call(ctx, "cartesi_listEpochs", params, &result); err != nil {
251-
return nil, err
252-
}
253-
return result.Epochs, nil
254-
}
255-
256-
// GetEpoch calls "cartesi_getEpoch".
257-
func (c *Client) GetEpoch(ctx context.Context, application string, index uint64) (*model.Epoch, error) {
258-
params := struct {
259-
Application string `json:"application"`
260-
Index string `json:"index"`
261-
}{
262-
Application: application,
263-
Index: fmt.Sprintf("%d", index),
264-
}
265-
var result EpochGetResult
266-
if err := c.Call(ctx, "cartesi_getEpoch", params, &result); err != nil {
267-
return nil, err
268-
}
269-
return result.Epoch, nil
270-
}
271-
272-
// GetLastAcceptedEpochIndex calls "cartesi_getLastAcceptedEpochIndex".
273-
func (c *Client) GetLastAcceptedEpochIndex(ctx context.Context, application string) (uint64, error) {
274-
params := struct {
275-
Application string `json:"application"`
276-
}{Application: application}
277-
var result struct {
278-
LastAcceptedEpochIndex uint64 `json:"data"`
279-
}
280-
if err := c.Call(ctx, "cartesi_getLastAcceptedEpochIndex", params, &result); err != nil {
281-
return 0, err
282-
}
283-
return result.LastAcceptedEpochIndex, nil
284-
}
285-
286-
// ListInputs calls "cartesi_ListInputs".
287-
func (c *Client) ListInputs(ctx context.Context, application string, epochIndex *string, sender *string, decode bool, limit, offset int64) ([]interface{}, error) {
288-
if limit > 10000 {
289-
limit = 10000
290-
}
291-
params := struct {
292-
Application string `json:"application"`
293-
EpochIndex *string `json:"epoch_index,omitempty"`
294-
Sender *string `json:"sender,omitempty"`
295-
Decode bool `json:"decode,omitempty"`
296-
Limit int64 `json:"limit"`
297-
Offset int64 `json:"offset"`
298-
}{
299-
Application: application,
300-
EpochIndex: epochIndex,
301-
Sender: sender,
302-
Decode: decode,
303-
Limit: limit,
304-
Offset: offset,
305-
}
306-
var result InputListResult
307-
if err := c.Call(ctx, "cartesi_listInputs", params, &result); err != nil {
308-
return nil, err
309-
}
310-
return result.Inputs, nil
311-
}
312-
313-
// GetInput calls "cartesi_getInput".
314-
func (c *Client) GetInput(ctx context.Context, application string, inputIndex string, decode bool) (any, error) {
315-
params := struct {
316-
Application string `json:"application"`
317-
InputIndex string `json:"input_index"`
318-
Decode bool `json:"decode,omitempty"`
319-
}{
320-
Application: application,
321-
InputIndex: inputIndex,
322-
Decode: decode,
323-
}
324-
var result InputGetResult
325-
if err := c.Call(ctx, "cartesi_getInput", params, &result); err != nil {
326-
return nil, err
327-
}
328-
return result.Input, nil
329-
}
330-
331-
// GetProcessedInputCount calls "cartesi_getProcessedInputCount".
332-
func (c *Client) GetProcessedInputCount(ctx context.Context, application string) (int64, error) {
333-
params := struct {
334-
Application string `json:"application"`
335-
}{
336-
Application: application,
337-
}
338-
var result struct {
339-
ProcessedInputs int64 `json:"processed_inputs"`
340-
}
341-
if err := c.Call(ctx, "cartesi_getProcessedInputCount", params, &result); err != nil {
342-
return 0, err
343-
}
344-
return result.ProcessedInputs, nil
345-
}
346-
347-
// ListOutputs calls "cartesi_ListOutputs".
348-
func (c *Client) ListOutputs(ctx context.Context, application string, epochIndex, inputIndex, rawDataPrefix, outputType, voucherAddress *string, decode bool, limit, offset int64) ([]interface{}, error) {
349-
if limit > 10000 {
350-
limit = 10000
351-
}
352-
params := struct {
353-
Application string `json:"application"`
354-
EpochIndex *string `json:"epoch_index,omitempty"`
355-
InputIndex *string `json:"input_index,omitempty"`
356-
RawDataPrefix *string `json:"raw_data_prefix,omitempty"`
357-
OutputType *string `json:"output_type,omitempty"`
358-
VoucherAddress *string `json:"voucher_address,omitempty"`
359-
Decode bool `json:"decode,omitempty"`
360-
Limit int64 `json:"limit"`
361-
Offset int64 `json:"offset"`
362-
}{
363-
Application: application,
364-
EpochIndex: epochIndex,
365-
InputIndex: inputIndex,
366-
RawDataPrefix: rawDataPrefix,
367-
OutputType: outputType,
368-
VoucherAddress: voucherAddress,
369-
Decode: decode,
370-
Limit: limit,
371-
Offset: offset,
372-
}
373-
var result OutputListResult
374-
if err := c.Call(ctx, "cartesi_listOutputs", params, &result); err != nil {
375-
return nil, err
376-
}
377-
return result.Outputs, nil
378-
}
379-
380-
// GetOutput calls "cartesi_getOutput".
381-
func (c *Client) GetOutput(ctx context.Context, application string, outputIndex string, decode bool) (any, error) {
382-
params := struct {
383-
Application string `json:"application"`
384-
OutputIndex string `json:"output_index"`
385-
Decode bool `json:"decode,omitempty"`
386-
}{
387-
Application: application,
388-
OutputIndex: outputIndex,
389-
Decode: decode,
390-
}
391-
var result OutputGetResult
392-
if err := c.Call(ctx, "cartesi_getOutput", params, &result); err != nil {
393-
return nil, err
394-
}
395-
return result.Output, nil
396-
}
397-
398-
// ListReports calls "cartesi_ListReports".
399-
func (c *Client) ListReports(ctx context.Context, application string, epochIndex, inputIndex *string, limit, offset int64) ([]*model.Report, error) {
400-
if limit > 10000 {
401-
limit = 10000
402-
}
403-
params := struct {
404-
Application string `json:"application"`
405-
EpochIndex *string `json:"epoch_index,omitempty"`
406-
InputIndex *string `json:"input_index,omitempty"`
407-
Limit int64 `json:"limit"`
408-
Offset int64 `json:"offset"`
409-
}{
410-
Application: application,
411-
EpochIndex: epochIndex,
412-
InputIndex: inputIndex,
413-
Limit: limit,
414-
Offset: offset,
415-
}
416-
var result ReportListResult
417-
if err := c.Call(ctx, "cartesi_listReports", params, &result); err != nil {
418-
return nil, err
419-
}
420-
return result.Reports, nil
421-
}
422-
423-
// GetReport calls "cartesi_getReport".
424-
func (c *Client) GetReport(ctx context.Context, application string, reportIndex string) (*model.Report, error) {
425-
params := struct {
426-
Application string `json:"application"`
427-
ReportIndex string `json:"report_index"`
428-
}{
429-
Application: application,
430-
ReportIndex: reportIndex,
431-
}
432-
var result ReportGetResult
433-
if err := c.Call(ctx, "cartesi_getReport", params, &result); err != nil {
434-
return nil, err
435-
}
436-
return result.Report, nil
437-
}

0 commit comments

Comments
 (0)