Skip to content

Commit

Permalink
add grpc server
Browse files Browse the repository at this point in the history
  • Loading branch information
gupadhyaya committed Jul 19, 2024
1 parent 09befcf commit 13bb70f
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions proxy/grpc/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package grpc

import (
"context"

"github.com/rollkit/go-sequencing"

Check failure on line 6 in proxy/grpc/server.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

File is not `goimports`-ed with -local github.com/rollkit (goimports)
"google.golang.org/grpc"

pbseq "github.com/rollkit/go-sequencing/types/pb/sequencing"
)

func NewServer(

Check warning on line 12 in proxy/grpc/server.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

exported: exported function NewServer should have comment or be unexported (revive)
input sequencing.SequencerInput,
output sequencing.SequencerOutput,
verifier sequencing.BatchVerifier,
opts ...grpc.ServerOption,
) *grpc.Server {
srv := grpc.NewServer(opts...)

proxyInputSrv := &proxyInputSrv{SequencerInput: input}
proxyOutputSrv := &proxyOutputSrv{SequencerOutput: output}
proxyVerificationSrv := &proxyVerificationSrv{BatchVerifier: verifier}

pbseq.RegisterSequencerInputServer(srv, proxyInputSrv)
pbseq.RegisterSequencerOutputServer(srv, proxyOutputSrv)
pbseq.RegisterBatchVerifierServer(srv, proxyVerificationSrv)

return srv
}

type proxyInputSrv struct {
sequencing.SequencerInput
}

type proxyOutputSrv struct {
sequencing.SequencerOutput
}

type proxyVerificationSrv struct {
sequencing.BatchVerifier
}

func (s *proxyInputSrv) SubmitRollupTransaction(ctx context.Context, req *pbseq.SubmitRollupTransactionRequest) (*pbseq.SubmitRollupTransactionResponse, error) {
err := s.SequencerInput.SubmitRollupTransaction(ctx, req.RollupId, req.Data)
if err != nil {
return nil, err
}
return &pbseq.SubmitRollupTransactionResponse{}, nil
}

func (s *proxyOutputSrv) GetNextBatch(ctx context.Context, req *pbseq.BatchRequest) (*pbseq.BatchResponse, error) {
batch, err := s.SequencerOutput.GetNextBatch(ctx, req.Transactions)
if err != nil {
return nil, err
}
return &pbseq.BatchResponse{Transactions: batch}, nil
}

func (s *proxyVerificationSrv) VerifyBatch(ctx context.Context, req *pbseq.BatchRequest) (*pbseq.VerificationResponse, error) {
ok, err := s.BatchVerifier.VerifyBatch(ctx, req.Transactions)
if err != nil {
return nil, err
}
return &pbseq.VerificationResponse{Success: ok}, nil
}

0 comments on commit 13bb70f

Please sign in to comment.