Documentation ¶
Index ¶
- Constants
- func GetOptionalStringFromVars(name string, args url.Values, result_Out *string) bool
- func GetStringFromVars(name string, args url.Values, result_Out *string) error
- func HandleAddressNotPresent(logger *slog.Logger, w http.ResponseWriter, err error) error
- func HandleClientNotSynced(logger *slog.Logger, w http.ResponseWriter, err error) error
- func HandleFailedResponse(logger *slog.Logger, w http.ResponseWriter, status types.ResponseStatus, ...) error
- func HandleInputError(logger *slog.Logger, w http.ResponseWriter, err error) error
- func HandleInvalidChainState(logger *slog.Logger, w http.ResponseWriter, err error) error
- func HandleInvalidMethod(logger *slog.Logger, w http.ResponseWriter) error
- func HandleResourceConflict(logger *slog.Logger, w http.ResponseWriter, err error) error
- func HandleResourceNotFound(logger *slog.Logger, w http.ResponseWriter, err error) error
- func HandleResponse(logger *slog.Logger, w http.ResponseWriter, status types.ResponseStatus, ...) error
- func HandleServerError(logger *slog.Logger, w http.ResponseWriter, err error) error
- func HandleSuccess(logger *slog.Logger, w http.ResponseWriter, response any) error
- func HandleWalletNotReady(logger *slog.Logger, w http.ResponseWriter, err error) error
- func RegisterQuerylessGet[ContextType IQuerylessCallContext[DataType], DataType any](router *mux.Router, functionName string, ...)
- func RegisterQuerylessPost[ContextType IQuerylessCallContext[DataType], BodyType any, DataType any](router *mux.Router, functionName string, ...)
- func RegisterSingleStagePost[ContextType ISingleStageCallContext[DataType], BodyType any, DataType any](router *mux.Router, functionName string, ...)
- func RegisterSingleStageRoute[ContextType ISingleStageCallContext[DataType], DataType any](router *mux.Router, functionName string, ...)
- func ValidateArg[ArgType any](name string, args url.Values, impl ArgValidator[ArgType], result_Out *ArgType) error
- func ValidateArgBatch[ArgType any](name string, args url.Values, batchLimit int, impl ArgValidator[ArgType], ...) error
- func ValidateOptionalArg[ArgType any](name string, args url.Values, impl ArgValidator[ArgType], result_Out *ArgType, ...) error
- func ValidateOptionalArgBatch[ArgType any](name string, args url.Values, batchLimit int, impl ArgValidator[ArgType], ...) error
- type ArgValidator
- type IContextFactory
- type IHandler
- type IQuerylessCallContext
- type IQuerylessGetContextFactory
- type IQuerylessPostContextFactory
- type ISingleStageCallContext
- type ISingleStageGetContextFactory
- type ISingleStagePostContextFactory
- type NetworkSocketApiServer
- type UnixSocketApiServer
Constants ¶
const (
ApiLogColor color.Attribute = color.FgHiBlue
)
Variables ¶
This section is empty.
Functions ¶
func GetOptionalStringFromVars ¶
Gets an optional string argument from the provided vars list
func GetStringFromVars ¶
Gets a string argument, ensuring that it exists in the provided vars list
func HandleAddressNotPresent ¶ added in v0.2.0
The request couldn't complete because the node requires an address but one wasn't present
func HandleClientNotSynced ¶ added in v0.2.0
The request couldn't complete because the clients aren't synced yet
func HandleFailedResponse ¶ added in v0.2.0
func HandleFailedResponse(logger *slog.Logger, w http.ResponseWriter, status types.ResponseStatus, err error) error
Handles an API response for a request that could not be completed
func HandleInputError ¶
Handles an error related to parsing the input parameters of a request
func HandleInvalidChainState ¶ added in v0.2.0
The request couldn't complete because the chain state is preventing the request (it will revert if submitted)
func HandleInvalidMethod ¶
func HandleInvalidMethod(logger *slog.Logger, w http.ResponseWriter) error
Handle routes called with an invalid method
func HandleResourceConflict ¶ added in v0.2.0
The request couldn't complete because it's trying to create a resource that already exists, or use a resource that conflicts with what's requested
func HandleResourceNotFound ¶ added in v0.2.0
The request couldn't complete because it's trying to access a resource that didn't exist or couldn't be found
func HandleResponse ¶
func HandleResponse(logger *slog.Logger, w http.ResponseWriter, status types.ResponseStatus, response any, err error) error
Handles an API response
func HandleServerError ¶ added in v0.2.0
The request couldn't complete because of a server error
func HandleSuccess ¶ added in v0.2.0
The request completed successfully
func HandleWalletNotReady ¶ added in v0.2.0
The request couldn't complete because the node requires a wallet but one isn't present or useable
func RegisterQuerylessGet ¶
func RegisterQuerylessGet[ContextType IQuerylessCallContext[DataType], DataType any]( router *mux.Router, functionName string, factory IQuerylessGetContextFactory[ContextType, DataType], logger *slog.Logger, serviceProvider *services.ServiceProvider, )
Registers a new route with the router, which will invoke the provided factory to create and execute the context for the route when it's called via GET; use this for typical general-purpose calls
func RegisterQuerylessPost ¶
func RegisterQuerylessPost[ContextType IQuerylessCallContext[DataType], BodyType any, DataType any]( router *mux.Router, functionName string, factory IQuerylessPostContextFactory[ContextType, BodyType, DataType], logger *slog.Logger, serviceProvider *services.ServiceProvider, )
Registers a new route with the router, which will invoke the provided factory to create and execute the context for the route when it's called via POST; use this for typical general-purpose calls
func RegisterSingleStagePost ¶
func RegisterSingleStagePost[ContextType ISingleStageCallContext[DataType], BodyType any, DataType any]( router *mux.Router, functionName string, factory ISingleStagePostContextFactory[ContextType, BodyType, DataType], logger *slog.Logger, serviceProvider *services.ServiceProvider, )
Registers a new route with the router, which will invoke the provided factory to create and execute the context for the route when it's called via POST; use this for typical general-purpose calls
func RegisterSingleStageRoute ¶
func RegisterSingleStageRoute[ContextType ISingleStageCallContext[DataType], DataType any]( router *mux.Router, functionName string, factory ISingleStageGetContextFactory[ContextType, DataType], logger *slog.Logger, serviceProvider *services.ServiceProvider, )
Registers a new route with the router, which will invoke the provided factory to create and execute the context for the route when it's called; use this for typical general-purpose calls
func ValidateArg ¶
func ValidateArg[ArgType any](name string, args url.Values, impl ArgValidator[ArgType], result_Out *ArgType) error
Validates an argument, ensuring it exists and can be converted to the required type
func ValidateArgBatch ¶
func ValidateArgBatch[ArgType any](name string, args url.Values, batchLimit int, impl ArgValidator[ArgType], result_Out *[]ArgType) error
Validates an argument representing a batch of inputs, ensuring it exists and the inputs can be converted to the required type. Use a limit of 0 for no limit.
func ValidateOptionalArg ¶
func ValidateOptionalArg[ArgType any](name string, args url.Values, impl ArgValidator[ArgType], result_Out *ArgType, exists_Out *bool) error
Validates an optional argument, converting to the required type if it exists
func ValidateOptionalArgBatch ¶ added in v0.5.0
func ValidateOptionalArgBatch[ArgType any](name string, args url.Values, batchLimit int, impl ArgValidator[ArgType], result_Out *[]ArgType, exists_Out *bool) error
Validates an optional argument representing a batch of inputs, converting them to the required type if it exists. Use a limit of 0 for no limit.
Types ¶
type ArgValidator ¶
Function for validating an argument (wraps the old CLI validators)
type IContextFactory ¶
Context factories can implement this generally so they can register themselves with an HTTP router.
type IQuerylessCallContext ¶
type IQuerylessCallContext[DataType any] interface { // Prepare the response data in whatever way the context needs to do //PrepareData(data *DataType, opts *bind.TransactOpts) error PrepareData(data *DataType, opts *bind.TransactOpts) (types.ResponseStatus, error) }
Wrapper for callbacks used by call runners that simply run without following a structured pattern of querying the chain. This is the most general form of context and can be used by anything as it doesn't add any scaffolding. Structs implementing this will handle the caller-specific functionality.
type IQuerylessGetContextFactory ¶
type IQuerylessGetContextFactory[ContextType IQuerylessCallContext[DataType], DataType any] interface { // Create the context for the route Create(args url.Values) (ContextType, error) }
Interface for queryless call context factories that handle GET calls. These will be invoked during route handling to create the unique context for the route.
type IQuerylessPostContextFactory ¶
type IQuerylessPostContextFactory[ContextType IQuerylessCallContext[DataType], BodyType any, DataType any] interface { // Create the context for the route Create(body BodyType) (ContextType, error) }
Interface for queryless call context factories that handle POST requests. These will be invoked during route handling to create the unique context for the route
type ISingleStageCallContext ¶
type ISingleStageCallContext[DataType any] interface { // Initialize the context with any bootstrapping, requirements checks, or bindings it needs to set up Initialize() (types.ResponseStatus, error) // Used to get any supplemental state required during initialization - anything in here will be fed into an hd.Query() multicall GetState(mc *batch.MultiCaller) // Prepare the response data in whatever way the context needs to do PrepareData(data *DataType, opts *bind.TransactOpts) (types.ResponseStatus, error) }
Wrapper for callbacks used by call runners that follow a common single-stage pattern: Create bindings, query the chain, and then do whatever else they want. Structs implementing this will handle the caller-specific functionality.
type ISingleStageGetContextFactory ¶
type ISingleStageGetContextFactory[ContextType ISingleStageCallContext[DataType], DataType any] interface { // Create the context for the route Create(args url.Values) (ContextType, error) }
Interface for single-stage call context factories - these will be invoked during route handling to create the unique context for the route
type ISingleStagePostContextFactory ¶
type ISingleStagePostContextFactory[ContextType ISingleStageCallContext[DataType], BodyType any, DataType any] interface { // Create the context for the route Create(body BodyType) (ContextType, error) }
Interface for queryless call context factories that handle POST requests. These will be invoked during route handling to create the unique context for the route
type NetworkSocketApiServer ¶ added in v0.3.1
type NetworkSocketApiServer struct {
// contains filtered or unexported fields
}
func NewNetworkSocketApiServer ¶ added in v0.3.1
func (*NetworkSocketApiServer) GetPort ¶ added in v0.4.0
func (s *NetworkSocketApiServer) GetPort() uint16
Get the port the server is running on - useful if the port was automatically assigned
func (*NetworkSocketApiServer) Start ¶ added in v0.3.1
func (s *NetworkSocketApiServer) Start(wg *sync.WaitGroup) error
Starts listening for incoming HTTP requests
func (*NetworkSocketApiServer) Stop ¶ added in v0.3.1
func (s *NetworkSocketApiServer) Stop() error
Stops the HTTP listener
type UnixSocketApiServer ¶ added in v0.3.1
type UnixSocketApiServer struct {
// contains filtered or unexported fields
}
func NewUnixSocketApiServer ¶ added in v0.3.1
func (*UnixSocketApiServer) Start ¶ added in v0.3.1
func (s *UnixSocketApiServer) Start(wg *sync.WaitGroup, socketOwnerUid uint32, socketOwnerGid uint32) error
Starts listening for incoming HTTP requests
func (*UnixSocketApiServer) Stop ¶ added in v0.3.1
func (s *UnixSocketApiServer) Stop() error
Stops the HTTP listener