-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a51efc6
commit d523c47
Showing
10 changed files
with
1,009 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
syntax = "proto3"; | ||
|
||
package rollup.v1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "google/api/annotations.proto"; | ||
import "rollup/v1/rollup.proto"; | ||
|
||
option go_package = "github.com/polymerdao/monomer/x/rollup/types"; | ||
|
||
// Query defines all query endpoints for the rollup module. | ||
service Query { | ||
// Params returns all rollup module parameters. | ||
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { | ||
option (google.api.http).get = "/rollup/v1/params"; | ||
} | ||
|
||
// L1BlockInfo returns the block info derived from L1. | ||
rpc L1BlockInfo(QueryL1BlockInfoRequest) returns (QueryL1BlockInfoResponse) { | ||
option (google.api.http).get = "/rollup/v1/l1_block_info"; | ||
} | ||
} | ||
|
||
// QueryParamsRequest is request type for the Query/Params RPC method. | ||
message QueryParamsRequest {} | ||
|
||
// QueryParamsResponse is response type for the Query/Params RPC method. | ||
message QueryParamsResponse { | ||
// params holds all the parameters for the rollup module. | ||
Params params = 1 [(gogoproto.nullable) = false]; | ||
} | ||
|
||
// QueryL1BlockInfoRequest is the request type for the Query/L1BlockInfo RPC method. | ||
message QueryL1BlockInfoRequest {} | ||
|
||
// QueryL1BlockInfoResponse is response type for the Query/L1BlockInfo RPC method. | ||
message QueryL1BlockInfoResponse { | ||
// l1_block_info holds the block info derived from L1. | ||
L1BlockInfo l1_block_info = 1 [(gogoproto.nullable) = false]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/polymerdao/monomer/x/rollup/types" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
var _ types.QueryServer = (*Keeper)(nil) | ||
|
||
// L1BlockInfo implements the Query/L1BlockInfo gRPC method | ||
func (k *Keeper) L1BlockInfo(ctx context.Context, req *types.QueryL1BlockInfoRequest) (*types.QueryL1BlockInfoResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "invalid request") | ||
} | ||
l1BlockInfo, err := k.GetL1BlockInfo(sdk.UnwrapSDKContext(ctx)) | ||
if err != nil { | ||
return nil, fmt.Errorf("get L1 block info: %w", err) | ||
} | ||
return &types.QueryL1BlockInfoResponse{L1BlockInfo: *l1BlockInfo}, nil | ||
} | ||
|
||
// Params implements the Query/Params gRPC method | ||
func (k *Keeper) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "invalid request") | ||
} | ||
params, err := k.GetParams(sdk.UnwrapSDKContext(ctx)) | ||
if err != nil { | ||
return nil, fmt.Errorf("get params: %w", err) | ||
} | ||
return &types.QueryParamsResponse{Params: *params}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package keeper_test | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/polymerdao/monomer/x/rollup/types" | ||
) | ||
|
||
func (s *KeeperTestSuite) TestParamsQuery() { | ||
params := types.DefaultParams() | ||
err := s.rollupKeeper.SetParams(sdk.UnwrapSDKContext(s.ctx), ¶ms) | ||
s.Require().NoError(err) | ||
|
||
response, err := s.rollupKeeper.Params(s.ctx, &types.QueryParamsRequest{}) | ||
s.Require().NoError(err) | ||
s.Require().Equal(&types.QueryParamsResponse{Params: params}, response) | ||
} | ||
|
||
func (s *KeeperTestSuite) TestL1BlockInfoQuery() { | ||
l1BlockInfo := types.L1BlockInfo{ | ||
Number: 1, | ||
Time: 1, | ||
} | ||
|
||
err := s.rollupKeeper.SetL1BlockInfo(sdk.UnwrapSDKContext(s.ctx), l1BlockInfo) | ||
s.Require().NoError(err) | ||
|
||
response, err := s.rollupKeeper.L1BlockInfo(s.ctx, &types.QueryL1BlockInfoRequest{}) | ||
s.Require().NoError(err) | ||
s.Require().Equal(&types.QueryL1BlockInfoResponse{L1BlockInfo: l1BlockInfo}, response) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.