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 ¶
- Variables
- func ErrFailureToGetBytecode(errMsg error) *status.Status
- func ErrFailureToHexDecodeBytecode(errMsg error) *status.Status
- func ErrInvalidAddress() *status.Status
- func ErrInvalidChainId() *status.Status
- func ErrInvalidMetadataRequest() *status.Status
- func ErrInvalidMetadataResponse(errMsg error) *status.Status
- func ErrNoBytecode() *status.Status
- type Server
- func (s *Server) GetAst(ctx context.Context, req *ast_pb.AstRequest) (*ast_pb.AstResponse, error)
- func (s *Server) GetHealth(context.Context, *health_pb.HealthRequest) (*health_pb.HealthResponse, error)
- func (s *Server) GetMetadata(ctx context.Context, req *metadata_pb.MetadataRequest) (*metadata_pb.MetadataResponse, error)
- func (s *Server) Run() error
Constants ¶
This section is empty.
Variables ¶
var ( // CodeInvalidMetadataResponse represents the error code for an invalid metadata response. CodeInvalidMetadataResponse = codes.Code(100) )
Functions ¶
func ErrFailureToGetBytecode ¶
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 ¶
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 ¶
ErrInvalidAddress returns a status error for an invalid address. The error includes a BadRequest_FieldViolation with a description of the error.
func ErrInvalidChainId ¶
ErrInvalidChainId returns a status error for an invalid chain id. The error includes a BadRequest_FieldViolation with a description of the error.
func ErrInvalidMetadataRequest ¶
ErrInvalidMetadataRequest returns a status error for an invalid metadata request. The error includes a BadRequest_FieldViolation with a description of the error.
func ErrInvalidMetadataResponse ¶
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 ¶
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 (*Server) GetAst ¶
func (s *Server) GetAst(ctx context.Context, req *ast_pb.AstRequest) (*ast_pb.AstResponse, error)
func (*Server) GetHealth ¶
func (s *Server) GetHealth(context.Context, *health_pb.HealthRequest) (*health_pb.HealthResponse, error)
func (*Server) GetMetadata ¶
func (s *Server) GetMetadata(ctx context.Context, req *metadata_pb.MetadataRequest) (*metadata_pb.MetadataResponse, error)
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 ¶
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.