Skip to content

Commit a0d7e0a

Browse files
committed
refactor(jsonrpc): rename cartesi_getMatchAdvanced as cartesi_getMatchAdvance
- Renamed handler to handleGetMatchAdvance. - Renamed params struct to GetMatchAdvanceParams across node and CLI. - Updated OpenRPC discovery and JSON-RPC tests. - Normalized the parsed parent hash before repository lookup. - Added a mixed-case parent-hash regression test.
1 parent c662250 commit a0d7e0a

8 files changed

Lines changed: 24 additions & 22 deletions

File tree

cmd/cartesi-rollups-cli/root/read/matchadvances/matchadvances.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func run(cmd *cobra.Command, args []string) {
9090

9191
var result json.RawMessage
9292
if len(args) >= 5 {
93-
var params api.GetMatchAdvancedParams
93+
var params api.GetMatchAdvanceParams
9494
params.Application = args[0]
9595
params.EpochIndex, err = config.AsHexString(args[1])
9696
cobra.CheckErr(err)

cmd/cartesi-rollups-cli/root/read/service/jsonrpc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ func (s *JsonrpcReadService) ListMatches(ctx context.Context, params api.ListMat
342342
return resp, err
343343
}
344344

345-
func (s *JsonrpcReadService) GetMatchAdvanced(ctx context.Context, params api.GetMatchAdvancedParams) (json.RawMessage, error) {
345+
func (s *JsonrpcReadService) GetMatchAdvanced(ctx context.Context, params api.GetMatchAdvanceParams) (json.RawMessage, error) {
346346
if _, err := config.ToApplicationNameOrAddressFromString(params.Application); err != nil {
347347
return nil, fmt.Errorf("invalid application: %w", err)
348348
}
@@ -360,7 +360,7 @@ func (s *JsonrpcReadService) GetMatchAdvanced(ctx context.Context, params api.Ge
360360
}
361361

362362
var resp json.RawMessage
363-
err := s.Client.Call(ctx, "cartesi_getMatchAdvanced", params, &resp)
363+
err := s.Client.Call(ctx, "cartesi_getMatchAdvance", params, &resp)
364364
return resp, err
365365
}
366366

cmd/cartesi-rollups-cli/root/read/service/repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ func (s *RepositoryReadService) ListMatches(ctx context.Context, params api.List
790790
return json.RawMessage(result), err
791791
}
792792

793-
func (s *RepositoryReadService) GetMatchAdvanced(ctx context.Context, params api.GetMatchAdvancedParams) (json.RawMessage, error) {
793+
func (s *RepositoryReadService) GetMatchAdvanced(ctx context.Context, params api.GetMatchAdvanceParams) (json.RawMessage, error) {
794794
repo := s.Repository
795795
application, err := config.ToApplicationNameOrAddressFromString(params.Application)
796796
if err != nil {

cmd/cartesi-rollups-cli/root/read/service/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type ReadService interface {
3535
ListCommitments(ctx context.Context, params api.ListCommitmentsParams) (json.RawMessage, error)
3636
GetMatch(ctx context.Context, params api.GetMatchParams) (json.RawMessage, error)
3737
ListMatches(ctx context.Context, params api.ListMatchesParams) (json.RawMessage, error)
38-
GetMatchAdvanced(ctx context.Context, params api.GetMatchAdvancedParams) (json.RawMessage, error)
38+
GetMatchAdvanced(ctx context.Context, params api.GetMatchAdvanceParams) (json.RawMessage, error)
3939
ListMatchAdvances(ctx context.Context, params api.ListMatchAdvancesParams) (json.RawMessage, error)
4040
Close()
4141
}

internal/jsonrpc/api/params.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ type ListMatchAdvancesParams struct {
198198
Descending bool `json:"descending,omitempty"`
199199
}
200200

201-
// GetMatchAdvancedParams aligns with the OpenRPC specification
202-
type GetMatchAdvancedParams struct {
201+
// GetMatchAdvanceParams aligns with the OpenRPC specification
202+
type GetMatchAdvanceParams struct {
203203
Application string `json:"application"`
204204
EpochIndex string `json:"epoch_index"`
205205
TournamentAddress string `json:"tournament_address"`

internal/jsonrpc/jsonrpc-discover.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@
14571457
]
14581458
},
14591459
{
1460-
"name": "cartesi_getMatchAdvanced",
1460+
"name": "cartesi_getMatchAdvance",
14611461
"summary": "Get a specific match advance",
14621462
"description": "Fetches a single match advance by application, epoch index, tournament address, ID hash and parent.",
14631463
"params": [

internal/jsonrpc/jsonrpc.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ var jsonrpcHandlers = dispatchTable{
8282
"cartesi_listMatches": handleListMatches,
8383
"cartesi_getMatch": handleGetMatch,
8484
"cartesi_listMatchAdvances": handleListMatchAdvances,
85-
"cartesi_getMatchAdvanced": handleGetMatchAdvanced,
85+
"cartesi_getMatchAdvance": handleGetMatchAdvance,
8686
"cartesi_getNodeInfo": handleGetNodeInfo,
8787
"cartesi_getChainId": handleGetChainID,
8888
"cartesi_getNodeVersion": handleGetNodeVersion,
@@ -1399,8 +1399,8 @@ func handleListMatchAdvances(s *Service, r *http.Request, req RPCRequest) (any,
13991399
}, nil
14001400
}
14011401

1402-
func handleGetMatchAdvanced(s *Service, r *http.Request, req RPCRequest) (any, error) {
1403-
var params api.GetMatchAdvancedParams
1402+
func handleGetMatchAdvance(s *Service, r *http.Request, req RPCRequest) (any, error) {
1403+
var params api.GetMatchAdvanceParams
14041404
if err := UnmarshalParams(req.Params, &params); err != nil {
14051405
s.Logger.Debug("Invalid parameters", "err", err)
14061406
return nil, newRPCError(JSONRPC_INVALID_PARAMS, "Invalid parameters")
@@ -1424,12 +1424,13 @@ func handleGetMatchAdvanced(s *Service, r *http.Request, req RPCRequest) (any, e
14241424
return nil, newRPCError(JSONRPC_INVALID_PARAMS, fmt.Sprintf("Invalid ID hash: %v", err))
14251425
}
14261426

1427-
if _, err := config.ToHashFromString(params.Parent); err != nil {
1427+
parent, err := config.ToHashFromString(params.Parent)
1428+
if err != nil {
14281429
return nil, newRPCError(JSONRPC_INVALID_PARAMS, fmt.Sprintf("Invalid parent hash: %v", err))
14291430
}
14301431

14311432
matchAdvanced, err := s.repository.GetMatchAdvanced(r.Context(), params.Application, epochIndex,
1432-
params.TournamentAddress, params.IDHash, params.Parent[2:]) // TODO: use parsed value
1433+
params.TournamentAddress, params.IDHash, parent.Hex()[2:])
14331434
if err != nil {
14341435
s.Logger.Error("Unable to retrieve match advanced from repository", "err", err)
14351436
return nil, newRPCError(JSONRPC_INTERNAL_ERROR, "Internal server error")

internal/jsonrpc/jsonrpc_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,9 +2743,9 @@ func TestMethod(t *testing.T) {
27432743
})
27442744

27452745
////////////////////////////////////////////////////////////////////////
2746-
// getMatchAdvanced
2746+
// getMatchAdvance
27472747
////////////////////////////////////////////////////////////////////////
2748-
t.Run("cartesi_getMatchAdvanced", func(t *testing.T) {
2748+
t.Run("cartesi_getMatchAdvance", func(t *testing.T) {
27492749
method := getName(t.Name())
27502750

27512751
// failure: epoch_index not hex encoded -> invalid param
@@ -2758,7 +2758,7 @@ func TestMethod(t *testing.T) {
27582758

27592759
body := s.doRequest(t, 0, fmt.Appendf([]byte{}, `{
27602760
"jsonrpc": "2.0",
2761-
"method": "cartesi_getMatchAdvanced",
2761+
"method": "cartesi_getMatchAdvance",
27622762
"params": {
27632763
"application": "%v",
27642764
"epoch_index": "%v"
@@ -2790,7 +2790,7 @@ func TestMethod(t *testing.T) {
27902790

27912791
body := s.doRequest(t, 0, fmt.Appendf([]byte{}, `{
27922792
"jsonrpc": "2.0",
2793-
"method": "cartesi_getMatchAdvanced",
2793+
"method": "cartesi_getMatchAdvance",
27942794
"params": {
27952795
"application": "%v",
27962796
"epoch_index": "0x%020x",
@@ -2815,7 +2815,7 @@ func TestMethod(t *testing.T) {
28152815
nr := uint64(0xdeadbeef)
28162816
body := s.doRequest(t, 0, fmt.Appendf([]byte{}, `{
28172817
"jsonrpc": "2.0",
2818-
"method": "cartesi_getMatchAdvanced",
2818+
"method": "cartesi_getMatchAdvance",
28192819
"params": {
28202820
"application": "%v",
28212821
"epoch_index": "0x%020x",
@@ -2842,7 +2842,8 @@ func TestMethod(t *testing.T) {
28422842
nr := uint64(2)
28432843
address := common.HexToAddress("0x03")
28442844
idHash := common.HexToHash("0x04")
2845-
parent := common.HexToHash("0x05")
2845+
parentHex := "0xAbCdEf0123456789aBcDeF0123456789AbCdEf0123456789aBcDeF0123456789"
2846+
parent := common.HexToHash(parentHex)
28462847

28472848
appID := s.newTestApplication(ctx, t, app)
28482849
s.createTestEpoch(ctx, t, numberToName(app),
@@ -2888,16 +2889,16 @@ func TestMethod(t *testing.T) {
28882889

28892890
body := s.doRequest(t, 0, fmt.Appendf([]byte{}, `{
28902891
"jsonrpc": "2.0",
2891-
"method": "cartesi_getMatchAdvanced",
2892+
"method": "cartesi_getMatchAdvance",
28922893
"params": {
28932894
"application": "%v",
28942895
"epoch_index": "0x%020x",
28952896
"tournament_address": "0x%020x",
28962897
"id_hash": "0x%064x",
2897-
"parent": "0x%064x"
2898+
"parent": "%s"
28982899
},
28992900
"id": 0
2900-
}`, numberToName(app), nr, address, idHash, parent))
2901+
}`, numberToName(app), nr, address, idHash, parentHex))
29012902

29022903
resp := testRPCResponse[getMatchAdvancedResult]{}
29032904
assert.Nil(t, json.Unmarshal(body, &resp))

0 commit comments

Comments
 (0)