server

package
v0.0.0-...-6c8d3ff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package server provides a gRPC server implementation for handling SolGo service requests. The server is capable of validating Ethereum addresses, handling metadata requests, and running a gRPC server. It provides detailed error handling and reporting, including specific error types for various failure scenarios.

Index

Constants

This section is empty.

Variables

View Source
var (
	// CodeInvalidMetadataResponse represents the error code for an invalid metadata response.
	CodeInvalidMetadataResponse = codes.Code(100)
)

Functions

func ErrFailureToGetBytecode

func ErrFailureToGetBytecode(errMsg error) *status.Status

ErrFailureToGetBytecode returns a status error when the requested address bytecode could not be discovered. The error includes a BadRequest_FieldViolation with a description of the error.

func ErrFailureToHexDecodeBytecode

func ErrFailureToHexDecodeBytecode(errMsg error) *status.Status

ErrFailureToHexDecodeBytecode returns a status error when the request bytecode could not be parsed into hex format. The error includes a BadRequest_FieldViolation with a description of the error.

func ErrInvalidAddress

func ErrInvalidAddress() *status.Status

ErrInvalidAddress returns a status error for an invalid address. The error includes a BadRequest_FieldViolation with a description of the error.

func ErrInvalidChainId

func ErrInvalidChainId() *status.Status

ErrInvalidChainId returns a status error for an invalid chain id. The error includes a BadRequest_FieldViolation with a description of the error.

func ErrInvalidMetadataRequest

func ErrInvalidMetadataRequest() *status.Status

ErrInvalidMetadataRequest returns a status error for an invalid metadata request. The error includes a BadRequest_FieldViolation with a description of the error.

func ErrInvalidMetadataResponse

func ErrInvalidMetadataResponse(errMsg error) *status.Status

ErrInvalidMetadataResponse returns a status error when the metadata for the requested contract could not be discovered. The error includes a BadRequest_FieldViolation with a description of the error.

func ErrNoBytecode

func ErrNoBytecode() *status.Status

ErrNoBytecode returns a status error when no bytecode could be discovered for the requested address. The error includes a BadRequest_FieldViolation with a description of the error.

Types

type Server

type Server struct {
	solgo_pb.UnimplementedSolGoServiceServer
	// contains filtered or unexported fields
}

Server represents a server that can handle SolGo service requests. It embeds the UnimplementedSolGoServiceServer to have forward-compatible implementations.

func NewServer

func NewServer(ctx context.Context, opts *options.Options) (*Server, error)

NewServer creates a new Server with the given context and options.

func (*Server) GetAst

func (s *Server) GetAst(ctx context.Context, req *ast_pb.AstRequest) (*ast_pb.AstResponse, error)

func (*Server) GetMetadata

GetMetadata handles a MetadataRequest and returns a MetadataResponse. It first checks if the chain ID is valid. If not, it returns an error. If an address is provided in the request, it validates the address, retrieves the bytecode associated with the address, and uses this bytecode for further processing. If the address is invalid or there is no bytecode associated with the address, it returns an error. If bytecode is provided in the request, it decodes the bytecode and uses it for further processing. If the bytecode is invalid, it returns an error. If neither an address nor bytecode is provided in the request, it returns an error. Finally, it decodes the contract metadata from the bytecode. If the metadata is invalid, it returns an error. If everything is successful, it returns a MetadataResponse with the decoded metadata and a status code of 1.

func (*Server) Run

func (s *Server) Run() error

Run starts the server and listens for requests on the configured address. It registers the server with the SolGo service and enables automatic service reflection. It initializes the Ethereum client and starts serving requests. When the server's context is done, it gracefully stops the server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL