Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFQ API: add GET /ack endpoint #2643

Merged
merged 24 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions services/rfq/api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
// It provides methods for creating, retrieving and updating quotes.
type AuthenticatedClient interface {
PutQuote(ctx context.Context, q *model.PutQuoteRequest) error
PutRelayAck(ctx context.Context, req *model.PutAckRequest) (*model.PutRelayAckResponse, error)
UnauthenticatedClient
}

Expand Down Expand Up @@ -124,6 +125,25 @@
return err
}

func (c *clientImpl) PutRelayAck(ctx context.Context, req *model.PutAckRequest) (*model.PutRelayAckResponse, error) {
var ack *model.PutRelayAckResponse
resp, err := c.rClient.R().
SetContext(ctx).
SetBody(req).
SetResult(&ack).
Put(rest.AckRoute)

if err != nil {
return nil, fmt.Errorf("error from server: %s %w", resp.Status(), err)
}

Check warning on line 138 in services/rfq/api/client/client.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/api/client/client.go#L128-L138

Added lines #L128 - L138 were not covered by tests

if resp.IsError() {
return nil, fmt.Errorf("error from server: %s", resp.Status())
}

Check warning on line 142 in services/rfq/api/client/client.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/api/client/client.go#L140-L142

Added lines #L140 - L142 were not covered by tests
Comment on lines +136 to +142
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combine error checks for clarity.

-	if err != nil {
-		return nil, fmt.Errorf("error from server: %s %w", resp.Status(), err)
-	}
-
-	if resp.IsError() {
-		return nil, fmt.Errorf("error from server: %s", resp.Status())
-	}
+	if err != nil || resp.IsError() {
+		return nil, fmt.Errorf("error from server: %s %w", resp.Status(), err)
+	}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if err != nil {
return nil, fmt.Errorf("error from server: %s %w", resp.Status(), err)
}
if resp.IsError() {
return nil, fmt.Errorf("error from server: %s", resp.Status())
}
if err != nil || resp.IsError() {
return nil, fmt.Errorf("error from server: %s %w", resp.Status(), err)
}


return ack, nil

Check warning on line 144 in services/rfq/api/client/client.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/api/client/client.go#L144

Added line #L144 was not covered by tests
}
Comment on lines +128 to +145
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test coverage for PutRelayAck method.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?


// GetAllQuotes retrieves all quotes from the RFQ quoting API.
func (c *unauthenticatedClient) GetAllQuotes(ctx context.Context) ([]*model.GetQuoteResponse, error) {
var quotes []*model.GetQuoteResponse
Expand Down
16 changes: 14 additions & 2 deletions services/rfq/api/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/jftuga/ellipsis"
"gopkg.in/yaml.v2"
Expand All @@ -21,8 +22,19 @@ type Config struct {
Database DatabaseConfig `yaml:"database"`
OmniRPCURL string `yaml:"omnirpc_url"`
// bridges is a map of chainid->address
Bridges map[uint32]string `yaml:"bridges"`
Port string `yaml:"port"`
Bridges map[uint32]string `yaml:"bridges"`
Port string `yaml:"port"`
RelayAckTimeout time.Duration `yaml:"relay_ack_timeout"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a YAML tag for RelayAckTimeout.

- RelayAckTimeout time.Duration     `yaml:"relay_ack_timeout"`
+ RelayAckTimeout time.Duration     `yaml:"relay_ack_timeout" yaml:"relay_ack_timeout"`

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
RelayAckTimeout time.Duration `yaml:"relay_ack_timeout"`
RelayAckTimeout time.Duration `yaml:"relay_ack_timeout" yaml:"relay_ack_timeout"`

}

const defaultRelayAckTimeout = 10 * time.Second

// GetRelayAckTimeout returns the relay ack timeout.
func (c Config) GetRelayAckTimeout() time.Duration {
if c.RelayAckTimeout == 0 {
return defaultRelayAckTimeout
}
return c.RelayAckTimeout
}

// LoadConfig loads the config from the given path.
Expand Down
31 changes: 31 additions & 0 deletions services/rfq/api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,37 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/ack": {
"put": {
"description": "cache an ack request to synchronize relayer actions.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ack"
],
"summary": "Relay ack",
"parameters": [
{
"description": "query params",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/model.PutQuoteRequest"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/quotes": {
"get": {
"description": "get quotes from all relayers.",
Expand Down
31 changes: 31 additions & 0 deletions services/rfq/api/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,37 @@
"contact": {}
},
"paths": {
"/ack": {
"put": {
"description": "cache an ack request to synchronize relayer actions.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ack"
],
"summary": "Relay ack",
"parameters": [
{
"description": "query params",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/model.PutQuoteRequest"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/quotes": {
"get": {
"description": "get quotes from all relayers.",
Expand Down
20 changes: 20 additions & 0 deletions services/rfq/api/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ definitions:
info:
contact: {}
paths:
/ack:
put:
consumes:
- application/json
description: cache an ack request to synchronize relayer actions.
parameters:
- description: query params
in: body
name: request
required: true
schema:
$ref: '#/definitions/model.PutQuoteRequest'
produces:
- application/json
responses:
"200":
description: OK
summary: Relay ack
tags:
- ack
/quotes:
get:
consumes:
Expand Down
6 changes: 6 additions & 0 deletions services/rfq/api/model/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ type PutQuoteRequest struct {
DestFastBridgeAddress string `json:"dest_fast_bridge_address"`
}

// PutAckRequest contains the schema for a PUT /ack request.
type PutAckRequest struct {
TxID string `json:"tx_id"`
DestChainID int `json:"dest_chain_id"`
}

// GetQuoteSpecificRequest contains the schema for a GET /quote request with specific params.
type GetQuoteSpecificRequest struct {
OriginChainID int `json:"originChainId"`
Expand Down
10 changes: 10 additions & 0 deletions services/rfq/api/model/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ type GetQuoteResponse struct {
// UpdatedAt is the time that the quote was last upserted
UpdatedAt string `json:"updated_at"`
}

// PutRelayAckResponse contains the schema for a PUT /relay/ack response.
type PutRelayAckResponse struct {
// TxID is the transaction ID
TransactionID string `json:"tx_id"`
// ShouldRelay is a boolean indicating whether the transaction should be relayed
ShouldRelay bool `json:"should_relay"`
// RelayerAddress is the address of the relayer that is currently acked
RelayerAddress string `json:"relayer_address"`
}
Loading
Loading