Documentation ¶
Overview ¶
Package rest provides RESTful API services for RFQ
Index ¶
- Constants
- Variables
- func APIVersionMiddleware(serverVersion string) gin.HandlerFunc
- func EIP191Auth(c *gin.Context, deadline int64) (accountRecovered common.Address, err error)
- type APIVersion
- type APIVersionHistory
- type Handler
- type PubSubManager
- type QuoterAPIServer
- func (r *QuoterAPIServer) AuthMiddleware() gin.HandlerFunc
- func (r *QuoterAPIServer) GetActiveRFQWebsocket(ctx context.Context, c *gin.Context)
- func (r *QuoterAPIServer) PutRFQRequest(c *gin.Context)
- func (r *QuoterAPIServer) PutRelayAck(c *gin.Context)
- func (r *QuoterAPIServer) Run(ctx context.Context) error
- type WsClient
Constants ¶
const ( // QuoteRoute is the API endpoint for handling quote related requests. QuoteRoute = "/quotes" // BulkQuotesRoute is the API endpoint for handling bulk quote related requests. BulkQuotesRoute = "/bulk_quotes" // AckRoute is the API endpoint for handling relay ack related requests. AckRoute = "/ack" // ContractsRoute is the API endpoint for returning a list of contracts. ContractsRoute = "/contracts" // RFQStreamRoute is the API endpoint for handling active quote requests via websocket. RFQStreamRoute = "/rfq_stream" // RFQRoute is the API endpoint for handling RFQ requests. RFQRoute = "/rfq" // ChainsHeader is the header for specifying chains during a websocket handshake. ChainsHeader = "Chains" // AuthorizationHeader is the header for specifying the authorization. AuthorizationHeader = "Authorization" )
const ( // PongOp is the operation for a pong message. PongOp = "pong" // PingOp is the operation for a ping message. PingOp = "ping" // SubscribeOp is the operation for a subscribe message. SubscribeOp = "subscribe" // UnsubscribeOp is the operation for an unsubscribe message. UnsubscribeOp = "unsubscribe" // RequestQuoteOp is the operation for a request quote message. RequestQuoteOp = "request_quote" // SendQuoteOp is the operation for a send quote message. SendQuoteOp = "send_quote" )
Variables ¶
var APIversions = APIVersionHistory{ Versions: []APIVersion{ { Version: "1.0", Date: "2024-01-01", Comments: "", Alerts: "", }, }, }
APIversions contains version information for the Synapse RFQ API. Deprecation notices & other alerts, if any, will be listed here. Note: Items must be listed in descending chronological order (current version index 0).
Functions ¶
func APIVersionMiddleware ¶ added in v1.22.0
func APIVersionMiddleware(serverVersion string) gin.HandlerFunc
APIVersionMiddleware adds the X-API-Version header to the response with the current version # from versions.json file.
func EIP191Auth ¶
EIP191Auth implements ethereum signed message authentication middleware for gin rest api For auth, relayer should pass in eth signed message following eip-191 with the message as the current unix timestamp in seconds i.e. signature (hex encoded) = keccak(bytes.concat("\x19Ethereum Signed Message:\n", len(strconv.Itoa(time.Now().Unix()), strconv.Itoa(time.Now().Unix()))) so that full auth header string: auth = strconv.Itoa(time.Now().Unix()) + ":" + signature see: https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign
Types ¶
type APIVersion ¶ added in v1.22.0
type APIVersion struct { Version string `json:"version"` Date string `json:"date"` Comments string `json:"comments"` Alerts string `json:"alerts"` }
APIVersion specifies the date of a particular API version along with any comments & alerts for integrators to review.
type APIVersionHistory ¶ added in v1.22.0
type APIVersionHistory struct {
Versions []APIVersion `json:"versions"`
}
APIVersionHistory lists historical ApiVersion structs in descending chronological order (current version index 0), each containing further detail about the version.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is the REST API handler.
func NewHandler ¶
NewHandler creates a new REST API handler.
func (*Handler) GetContracts ¶ added in v0.29.14
GetContracts retrieves all contracts api is currently enabled on. GET /contracts. PingExample godoc @Summary Get contract addresses @Description get quotes from all relayers. @Tags quotes @Accept json @Produce json @Success 200 {array} model.GetContractsResponse @Header 200 {string} X-Api-Version "API Version Number - See docs for more info" @Router /contracts [get].
func (*Handler) GetOpenQuoteRequests ¶ added in v1.29.0
GetOpenQuoteRequests retrieves all open quote requests. GET /open_quote_requests @Summary Get open quote requests @Description Get all open quote requests that are currently in Received or Pending status. @Tags quotes @Accept json @Produce json @Success 200 {array} model.GetOpenQuoteRequestsResponse @Header 200 {string} X-Api-Version "API Version Number - See docs for more info" @Router /open_quote_requests [get].
func (*Handler) GetQuotes ¶
GetQuotes retrieves all quotes from the database. GET /quotes. nolint: cyclop PingExample godoc @Summary Get quotes @Schemes @Param originChainID path int false "origin chain id to filter quotes by" @Param originTokenAddr path string false "origin chain id to filter quotes by" @Param destChainID path int false "destination chain id to filter quotes by" @Param destTokenAddr path string false "destination token address to filter quotes by" @Param relayerAddr path string false "relayer address to filter quotes by" @Description get quotes from all relayers. @Tags quotes @Accept json @Produce json @Success 200 {array} model.GetQuoteResponse @Header 200 {string} X-Api-Version "API Version Number - See docs for more info" @Router /quotes [get].
func (*Handler) ModifyBulkQuotes ¶ added in v0.29.13
ModifyBulkQuotes upserts multiple quotes
PUT /bulk_quotes @dev Protected Method: Authentication is handled through middleware in server.go. nolint: cyclop @Summary Upsert quotes @Schemes @Description upsert bulk quotes from relayer. @Param request body model.PutBulkQuotesRequest true "query params" @Tags quotes @Accept json @Produce json @Success 200 @Header 200 {string} X-Api-Version "API Version Number - See docs for more info" @Router /bulk_quotes [put].
func (*Handler) ModifyQuote ¶
ModifyQuote upserts a quote
PUT /quotes @dev Protected Method: Authentication is handled through middleware in server.go. nolint: cyclop @Summary Upsert quote @Schemes @Description upsert a quote from relayer. @Param request body model.PutRelayerQuoteRequest true "query params" @Tags quotes @Accept json @Produce json @Success 200 @Header 200 {string} X-Api-Version "API Version Number - See docs for more info" @Router /quotes [put].
type PubSubManager ¶ added in v1.29.0
type PubSubManager interface { AddSubscription(relayerAddr string, params model.SubscriptionParams) error RemoveSubscription(relayerAddr string, params model.SubscriptionParams) error IsSubscribed(relayerAddr string, origin, dest int) bool }
PubSubManager is a manager for a pubsub system.
func NewPubSubManager ¶ added in v1.29.0
func NewPubSubManager() PubSubManager
NewPubSubManager creates a new pubsub manager.
type QuoterAPIServer ¶ added in v0.0.15
type QuoterAPIServer struct {
// contains filtered or unexported fields
}
QuoterAPIServer is a struct that holds the configuration, database connection, gin engine, RPC client, metrics handler, and fast bridge contracts. It is used to initialize and run the API server.
func NewAPI ¶
func NewAPI( ctx context.Context, cfg config.Config, handler metrics.Handler, omniRPCClient omniClient.RPCClient, store db.APIDB, ) (*QuoterAPIServer, error)
NewAPI holds the configuration, database connection, gin engine, RPC client, metrics handler, and fast bridge contracts. It is used to initialize and run the API server.
func (*QuoterAPIServer) AuthMiddleware ¶ added in v0.0.15
func (r *QuoterAPIServer) AuthMiddleware() gin.HandlerFunc
AuthMiddleware is the Gin authentication middleware that authenticates requests using EIP191.
func (*QuoterAPIServer) GetActiveRFQWebsocket ¶ added in v1.29.0
func (r *QuoterAPIServer) GetActiveRFQWebsocket(ctx context.Context, c *gin.Context)
GetActiveRFQWebsocket handles the WebSocket connection for active quote requests. GET /rfq_stream. @Summary Listen for Active RFQs @Schemes @Description Establish a WebSocket connection to listen for streaming active quote requests. @Tags quotes @Produce json @Success 101 {string} string "Switching Protocols" @Header 101 {string} X-Api-Version "API Version Number - See docs for more info" @Router /rfq_stream [get].
func (*QuoterAPIServer) PutRFQRequest ¶ added in v1.29.0
func (r *QuoterAPIServer) PutRFQRequest(c *gin.Context)
PutRFQRequest handles a user request for a quote. PUT /rfq. @Summary Initiate an Active RFQ @Schemes @Description Initiate an Active Request-For-Quote and return the best quote available. @Param request body model.PutRFQRequest true "Initiate an Active Request-For-Quote" @Tags quotes @Accept json @Produce json @Success 200 {object} model.PutRFQResponse @Header 200 {string} X-Api-Version "API Version Number - See docs for more info" @Router /rfq [put].
func (*QuoterAPIServer) PutRelayAck ¶ added in v0.22.0
func (r *QuoterAPIServer) PutRelayAck(c *gin.Context)
PutRelayAck checks if a relay is pending or not. Note that the ack is not binding; that is, any relayer can still relay the transaction on chain if they ignore the response to this call. Also, this will not work if the API is run on multiple servers, since there is no inter-server communication to maintain the cache.
PUT /ack. @dev Protected Method: Authentication is handled through middleware in server.go. @Summary Relay ack @Schemes @Description cache an ack request to synchronize relayer actions. @Param request body model.PutRelayerQuoteRequest true "query params" @Tags ack @Accept json @Produce json @Success 200 @Header 200 {string} X-Api-Version "API Version Number - See docs for more info" @Router /ack [put].
type WsClient ¶ added in v1.29.0
type WsClient interface { Run(ctx context.Context) error SendQuoteRequest(ctx context.Context, quoteRequest *model.WsRFQRequest) error ReceiveQuoteResponse(ctx context.Context, requestID string) (*model.WsRFQResponse, error) }
WsClient is a client for the WebSocket API.