Fix and change relays response for the relays endpoint (#805)

Co-authored-by: walker-16 <agpazos85@gmail.com>
This commit is contained in:
ftocal 2023-11-16 15:28:07 -03:00 committed by GitHub
parent 11b162ca54
commit c2f02bab2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 639 additions and 142 deletions

View File

@ -1,4 +1,5 @@
// Code generated by swaggo/swag. DO NOT EDIT
// Code generated by swaggo/swag. DO NOT EDIT.
package docs
import "github.com/swaggo/swag"
@ -574,19 +575,12 @@ const docTemplate = `{
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"type": "object"
},
{
"type": "object",
"properties": {
"status": {
"type": "string"
}
}
"type": "object",
"properties": {
"status": {
"type": "string"
}
]
}
}
},
"400": {
@ -899,19 +893,12 @@ const docTemplate = `{
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"type": "object"
},
{
"type": "object",
"properties": {
"ready": {
"type": "string"
}
}
"type": "object",
"properties": {
"ready": {
"type": "string"
}
]
}
}
},
"400": {
@ -1736,22 +1723,15 @@ const docTemplate = `{
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"type": "object"
},
{
"type": "object",
"properties": {
"vaaBytes": {
"type": "array",
"items": {
"type": "integer"
}
}
"type": "object",
"properties": {
"vaaBytes": {
"type": "array",
"items": {
"type": "integer"
}
}
]
}
}
},
"400": {
@ -1797,22 +1777,15 @@ const docTemplate = `{
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"type": "object"
},
{
"type": "object",
"properties": {
"vaaBytes": {
"type": "array",
"items": {
"type": "integer"
}
}
"type": "object",
"properties": {
"vaaBytes": {
"type": "array",
"items": {
"type": "integer"
}
}
]
}
}
},
"400": {
@ -2435,9 +2408,137 @@ const docTemplate = `{
}
}
},
"relays.DeliveryReponse": {
"type": "object",
"properties": {
"execution": {
"$ref": "#/definitions/relays.ResultExecutionResponse"
},
"relayGasUsed": {
"type": "integer"
}
}
},
"relays.InstructionsResponse": {
"type": "object",
"properties": {
"encodedExecutionInfo": {
"type": "string"
},
"extraReceiverValue": {
"type": "object",
"properties": {
"_hex": {
"type": "string"
},
"_isBigNumber": {
"type": "boolean"
}
}
},
"refundAddress": {
"type": "string"
},
"refundChainId": {
"type": "integer"
},
"refundDeliveryProvider": {
"type": "string"
},
"requestedReceiverValue": {
"type": "object",
"properties": {
"_hex": {
"type": "string"
},
"_isBigNumber": {
"type": "boolean"
}
}
},
"senderAddress": {
"type": "string"
},
"sourceDeliveryProvider": {
"type": "string"
},
"targetAddress": {
"type": "string"
},
"targetChainId": {
"type": "integer"
},
"vaaKeys": {
"type": "array",
"items": {}
}
}
},
"relays.RelayDataResponse": {
"type": "object",
"properties": {
"delivery": {
"$ref": "#/definitions/relays.DeliveryReponse"
},
"fromTxHash": {
"type": "string"
},
"instructions": {
"$ref": "#/definitions/relays.InstructionsResponse"
},
"toTxHash": {
"type": "string"
}
}
},
"relays.RelayResponse": {
"type": "object",
"additionalProperties": true
"properties": {
"completedAt": {
"type": "string"
},
"data": {
"$ref": "#/definitions/relays.RelayDataResponse"
},
"failedAt": {
"type": "string"
},
"id": {
"type": "string"
},
"receivedAt": {
"type": "string"
},
"relayer": {
"type": "string"
},
"status": {
"type": "string"
}
}
},
"relays.ResultExecutionResponse": {
"type": "object",
"properties": {
"detail": {
"type": "string"
},
"gasUsed": {
"type": "string"
},
"refundStatus": {
"type": "string"
},
"revertString": {
"type": "string"
},
"status": {
"type": "string"
},
"transactionHash": {
"type": "string"
}
}
},
"response.Response-address_AddressOverview": {
"type": "object",
@ -3046,6 +3147,8 @@ var SwaggerInfo = &swag.Spec{
Description: "Wormhole Guardian API\nThis is the API for the Wormhole Guardian and Explorer.\nThe API has two namespaces: wormholescan and guardian.\nwormholescan is the namespace for the explorer and the new endpoints. The prefix is /api/v1.\nguardian is the legacy namespace backguard compatible with guardian node API. The prefix is /v1.\nThis API is public and does not require authentication although some endpoints are rate limited.\nCheck each endpoint documentation for more information.",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}
func init() {

View File

@ -567,19 +567,12 @@
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"type": "object"
},
{
"type": "object",
"properties": {
"status": {
"type": "string"
}
}
"type": "object",
"properties": {
"status": {
"type": "string"
}
]
}
}
},
"400": {
@ -892,19 +885,12 @@
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"type": "object"
},
{
"type": "object",
"properties": {
"ready": {
"type": "string"
}
}
"type": "object",
"properties": {
"ready": {
"type": "string"
}
]
}
}
},
"400": {
@ -1729,22 +1715,15 @@
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"type": "object"
},
{
"type": "object",
"properties": {
"vaaBytes": {
"type": "array",
"items": {
"type": "integer"
}
}
"type": "object",
"properties": {
"vaaBytes": {
"type": "array",
"items": {
"type": "integer"
}
}
]
}
}
},
"400": {
@ -1790,22 +1769,15 @@
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"type": "object"
},
{
"type": "object",
"properties": {
"vaaBytes": {
"type": "array",
"items": {
"type": "integer"
}
}
"type": "object",
"properties": {
"vaaBytes": {
"type": "array",
"items": {
"type": "integer"
}
}
]
}
}
},
"400": {
@ -2428,9 +2400,137 @@
}
}
},
"relays.DeliveryReponse": {
"type": "object",
"properties": {
"execution": {
"$ref": "#/definitions/relays.ResultExecutionResponse"
},
"relayGasUsed": {
"type": "integer"
}
}
},
"relays.InstructionsResponse": {
"type": "object",
"properties": {
"encodedExecutionInfo": {
"type": "string"
},
"extraReceiverValue": {
"type": "object",
"properties": {
"_hex": {
"type": "string"
},
"_isBigNumber": {
"type": "boolean"
}
}
},
"refundAddress": {
"type": "string"
},
"refundChainId": {
"type": "integer"
},
"refundDeliveryProvider": {
"type": "string"
},
"requestedReceiverValue": {
"type": "object",
"properties": {
"_hex": {
"type": "string"
},
"_isBigNumber": {
"type": "boolean"
}
}
},
"senderAddress": {
"type": "string"
},
"sourceDeliveryProvider": {
"type": "string"
},
"targetAddress": {
"type": "string"
},
"targetChainId": {
"type": "integer"
},
"vaaKeys": {
"type": "array",
"items": {}
}
}
},
"relays.RelayDataResponse": {
"type": "object",
"properties": {
"delivery": {
"$ref": "#/definitions/relays.DeliveryReponse"
},
"fromTxHash": {
"type": "string"
},
"instructions": {
"$ref": "#/definitions/relays.InstructionsResponse"
},
"toTxHash": {
"type": "string"
}
}
},
"relays.RelayResponse": {
"type": "object",
"additionalProperties": true
"properties": {
"completedAt": {
"type": "string"
},
"data": {
"$ref": "#/definitions/relays.RelayDataResponse"
},
"failedAt": {
"type": "string"
},
"id": {
"type": "string"
},
"receivedAt": {
"type": "string"
},
"relayer": {
"type": "string"
},
"status": {
"type": "string"
}
}
},
"relays.ResultExecutionResponse": {
"type": "object",
"properties": {
"detail": {
"type": "string"
},
"gasUsed": {
"type": "string"
},
"refundStatus": {
"type": "string"
},
"revertString": {
"type": "string"
},
"status": {
"type": "string"
},
"transactionHash": {
"type": "string"
}
}
},
"response.Response-address_AddressOverview": {
"type": "object",

View File

@ -396,8 +396,91 @@ definitions:
tokenChain:
$ref: '#/definitions/vaa.ChainID'
type: object
relays.DeliveryReponse:
properties:
execution:
$ref: '#/definitions/relays.ResultExecutionResponse'
relayGasUsed:
type: integer
type: object
relays.InstructionsResponse:
properties:
encodedExecutionInfo:
type: string
extraReceiverValue:
properties:
_hex:
type: string
_isBigNumber:
type: boolean
type: object
refundAddress:
type: string
refundChainId:
type: integer
refundDeliveryProvider:
type: string
requestedReceiverValue:
properties:
_hex:
type: string
_isBigNumber:
type: boolean
type: object
senderAddress:
type: string
sourceDeliveryProvider:
type: string
targetAddress:
type: string
targetChainId:
type: integer
vaaKeys:
items: {}
type: array
type: object
relays.RelayDataResponse:
properties:
delivery:
$ref: '#/definitions/relays.DeliveryReponse'
fromTxHash:
type: string
instructions:
$ref: '#/definitions/relays.InstructionsResponse'
toTxHash:
type: string
type: object
relays.RelayResponse:
additionalProperties: true
properties:
completedAt:
type: string
data:
$ref: '#/definitions/relays.RelayDataResponse'
failedAt:
type: string
id:
type: string
receivedAt:
type: string
relayer:
type: string
status:
type: string
type: object
relays.ResultExecutionResponse:
properties:
detail:
type: string
gasUsed:
type: string
refundStatus:
type: string
revertString:
type: string
status:
type: string
transactionHash:
type: string
type: object
response.Response-address_AddressOverview:
properties:
@ -1204,12 +1287,10 @@ paths:
"200":
description: OK
schema:
allOf:
- type: object
- properties:
status:
type: string
type: object
properties:
status:
type: string
type: object
"400":
description: Bad Request
"500":
@ -1421,12 +1502,10 @@ paths:
"200":
description: OK
schema:
allOf:
- type: object
- properties:
ready:
type: string
type: object
properties:
ready:
type: string
type: object
"400":
description: Bad Request
"500":
@ -1998,14 +2077,12 @@ paths:
"200":
description: OK
schema:
allOf:
- type: object
- properties:
vaaBytes:
items:
type: integer
type: array
type: object
properties:
vaaBytes:
items:
type: integer
type: array
type: object
"400":
description: Bad Request
"500":
@ -2036,14 +2113,12 @@ paths:
"200":
description: OK
schema:
allOf:
- type: object
- properties:
vaaBytes:
items:
type: integer
type: array
type: object
properties:
vaaBytes:
items:
type: integer
type: array
type: object
"400":
description: Bad Request
"500":

View File

@ -3,6 +3,7 @@ package relays
import (
"context"
"fmt"
"time"
"github.com/pkg/errors"
errs "github.com/wormhole-foundation/wormhole-explorer/api/internal/errors"
@ -31,8 +32,8 @@ func NewRepository(db *mongo.Database, logger *zap.Logger) *Repository {
}
}
func (r *Repository) FindOne(ctx context.Context, q *RelaysQuery) (*RelayResponse, error) {
response := make(RelayResponse)
func (r *Repository) FindOne(ctx context.Context, q *RelaysQuery) (*RelayDoc, error) {
var response RelayDoc
err := r.collections.relays.FindOne(ctx, q.toBSON()).Decode(&response)
if err != nil {
if errors.Is(err, mongo.ErrNoDocuments) {
@ -53,12 +54,122 @@ type RelaysQuery struct {
sequence string
}
type RelayResponse map[string]interface{}
type RelayDoc struct {
ID string `bson:"id"`
Data struct {
Status string `bson:"status"`
ReceivedAt time.Time `bson:"receivedAt"`
CompletedAt *time.Time `bson:"completedAt"`
ToTxHash *string `bson:"toTxHash"`
Metadata *struct {
Attempts int `bson:"attempts"`
ExecutionStartTime int64 `bson:"executionStartTime"`
EmitterChain int `bson:"emitterChain"`
DidMatchDeliveryProvider bool `bson:"didMatchDeliveryProvider"`
DidParse bool `bson:"didParse"`
Instructions struct {
EncodedExecutionInfo string `bson:"encodedExecutionInfo"`
RefundAddress string `bson:"refundAddress"`
SourceDeliveryProvider string `bson:"sourceDeliveryProvider"`
SenderAddress string `bson:"senderAddress"`
VaaKeys []any `bson:"vaaKeys"`
ExtraReceiverValue struct {
Hex string `bson:"_hex"`
IsBigNumber bool `bson:"_isBigNumber"`
} `bson:"extraReceiverValue"`
TargetAddress string `bson:"targetAddress"`
RequestedReceiverValue struct {
Hex string `bson:"_hex"`
IsBigNumber bool `bson:"_isBigNumber"`
} `bson:"requestedReceiverValue"`
RefundChainID int `bson:"refundChainId"`
RefundDeliveryProvider string `bson:"refundDeliveryProvider"`
TargetChainID int `bson:"targetChainId"`
} `bson:"instructions"`
DeliveryRecord struct {
MaxRefund string `bson:"maxRefund"`
Budget string `bson:"budget"`
TargetChainAssetPriceUSD float64 `bson:"targetChainAssetPriceUSD"`
WalletNonce int `bson:"walletNonce"`
TransactionHashes []string `bson:"transactionHashes"`
HasAdditionalVaas bool `bson:"hasAdditionalVaas"`
AdditionalVaasDidFetch bool `bson:"additionalVaasDidFetch"`
WalletAcquisitionEndTime int64 `bson:"walletAcquisitionEndTime"`
WalletAcquisitionDidSucceed bool `bson:"walletAcquisitionDidSucceed"`
WalletBalanceAfter string `bson:"walletBalanceAfter"`
ResultLog struct {
TransactionHash string `bson:"transactionHash"`
VaaHash string `bson:"vaaHash"`
RefundStatus string `bson:"refundStatus"`
RevertString string `bson:"revertString"`
Status string `bson:"status"`
GasUsed string `bson:"gasUsed"`
SourceChain string `bson:"sourceChain"`
SourceVaaSequence string `bson:"sourceVaaSequence"`
} `bson:"resultLog"`
ResultString string `bson:"resultString"`
AdditionalVaaKeysPrintable string `bson:"additionalVaaKeysPrintable"`
BudgetUsd float64 `bson:"budgetUsd"`
WalletAcquisitionStartTime int64 `bson:"walletAcquisitionStartTime"`
GasUnitsEstimate int `bson:"gasUnitsEstimate"`
EstimatedTransactionFeeEther string `bson:"estimatedTransactionFeeEther"`
TargetChainDecimals int `bson:"targetChainDecimals"`
DeliveryInstructionsPrintable struct {
Payload string `bson:"payload"`
EncodedExecutionInfo string `bson:"encodedExecutionInfo"`
RefundDeliveryProvider string `bson:"refundDeliveryProvider"`
SourceDeliveryProvider string `bson:"sourceDeliveryProvider"`
SenderAddress string `bson:"senderAddress"`
TargetAddress string `bson:"targetAddress"`
RequestedReceiverValue string `bson:"requestedReceiverValue"`
ExtraReceiverValue string `bson:"extraReceiverValue"`
RefundChainID string `bson:"refundChainId"`
RefundAddress string `bson:"refundAddress"`
VaaKeys []any `bson:"vaaKeys"`
TargetChainID string `bson:"targetChainId"`
} `bson:"deliveryInstructionsPrintable"`
WalletAddress string `bson:"walletAddress"`
GasUsed int `bson:"gasUsed"`
GasPrice string `bson:"gasPrice"`
ReceiverValue string `bson:"receiverValue"`
MaxRefundUsd float64 `bson:"maxRefundUsd"`
GasPriceEstimate string `bson:"gasPriceEstimate"`
TransactionDidSubmit bool `bson:"transactionDidSubmit"`
EstimatedTransactionFee string `bson:"estimatedTransactionFee"`
TransactionSubmitTimeStart int64 `bson:"transactionSubmitTimeStart"`
TransactionSubmitTimeEnd int64 `bson:"transactionSubmitTimeEnd"`
ResultLogDidParse bool `bson:"resultLogDidParse"`
ChainID int `bson:"chainId"`
ReceiverValueUsd float64 `bson:"receiverValueUsd"`
WalletBalanceBefore string `bson:"walletBalanceBefore"`
} `bson:"deliveryRecord"`
RawVaaHex string `bson:"rawVaaHex"`
PayloadType int `bson:"payloadType"`
MaxAttempts int `bson:"maxAttempts"`
DidError bool `bson:"didError"`
ExecutionEndTime int64 `bson:"executionEndTime"`
EmitterAddress string `bson:"emitterAddress"`
DidSubmitTransaction bool `bson:"didSubmitTransaction"`
Sequence string `bson:"sequence"`
} `bson:"metadata"`
Sequence string `bson:"sequence"`
Vaa string `bson:"vaa"`
FromTxHash string `bson:"fromTxHash"`
MaxAttempts int `bson:"maxAttempts"`
AddedTimes int `bson:"addedTimes"`
ErrorMessage any `bson:"errorMessage"`
EmitterChain int `bson:"emitterChain"`
EmitterAddress string `bson:"emitterAddress"`
FailedAt *time.Time `bson:"failedAt"`
} `bson:"data"`
Event string `bson:"event"`
Origin string `bson:"origin"`
}
func (q *RelaysQuery) toBSON() *bson.D {
r := bson.D{}
id := fmt.Sprintf("%d/%s/%s", q.chainId, q.emitter, q.sequence)
r = append(r, bson.E{Key: "_id", Value: id})
r = append(r, bson.E{Key: "id", Value: id})
return &r
}

View File

@ -24,7 +24,7 @@ func (s *Service) FindByVAA(
chainID vaa.ChainID,
emitterAddr *types.Address,
seq string,
) (*RelayResponse, error) {
) (*RelayDoc, error) {
query := Query().
SetChain(chainID).

View File

@ -2,6 +2,7 @@ package relays
import (
"strconv"
"time"
"github.com/gofiber/fiber/v2"
"github.com/wormhole-foundation/wormhole-explorer/api/handlers/relays"
@ -40,5 +41,112 @@ func (c *Controller) FindOne(ctx *fiber.Ctx) error {
if err != nil {
return err
}
return ctx.JSON(relay)
response := c.makeResponse(relay)
return ctx.JSON(response)
}
func (c *Controller) makeResponse(doc *relays.RelayDoc) *RelayResponse {
var data *RelayDataResponse
if doc.Data.Metadata != nil {
data = &RelayDataResponse{
FromTxHash: doc.Data.FromTxHash,
ToTxHash: doc.Data.ToTxHash,
Delivery: DeliveryReponse{
ResultExecution: ResultExecutionResponse{
TransactionHash: doc.Data.Metadata.DeliveryRecord.ResultLog.TransactionHash,
RefundStatus: doc.Data.Metadata.DeliveryRecord.ResultLog.RefundStatus,
RevertString: doc.Data.Metadata.DeliveryRecord.ResultLog.RevertString,
Status: doc.Data.Metadata.DeliveryRecord.ResultLog.Status,
GasUsed: doc.Data.Metadata.DeliveryRecord.ResultLog.GasUsed,
Detail: doc.Data.Metadata.DeliveryRecord.ResultString,
},
RelayGasUsed: doc.Data.Metadata.DeliveryRecord.GasUsed,
},
Instructions: InstructionsResponse{
EncodedExecutionInfo: doc.Data.Metadata.Instructions.EncodedExecutionInfo,
RefundAddress: doc.Data.Metadata.Instructions.RefundAddress,
SourceDeliveryProvider: doc.Data.Metadata.Instructions.SourceDeliveryProvider,
SenderAddress: doc.Data.Metadata.Instructions.SenderAddress,
VaaKeys: doc.Data.Metadata.Instructions.VaaKeys,
ExtraReceiverValue: struct {
Hex string `json:"_hex"`
IsBigNumber bool `json:"_isBigNumber"`
}{
Hex: doc.Data.Metadata.Instructions.ExtraReceiverValue.Hex,
IsBigNumber: doc.Data.Metadata.Instructions.ExtraReceiverValue.IsBigNumber,
},
TargetAddress: doc.Data.Metadata.Instructions.TargetAddress,
RequestedReceiverValue: struct {
Hex string `json:"_hex"`
IsBigNumber bool `json:"_isBigNumber"`
}{
Hex: doc.Data.Metadata.Instructions.RequestedReceiverValue.Hex,
IsBigNumber: doc.Data.Metadata.Instructions.RequestedReceiverValue.IsBigNumber,
},
RefundChainID: doc.Data.Metadata.Instructions.RefundChainID,
RefundDeliveryProvider: doc.Data.Metadata.Instructions.RefundDeliveryProvider,
TargetChainID: doc.Data.Metadata.Instructions.TargetChainID,
},
}
}
return &RelayResponse{
ID: doc.ID,
Relayer: doc.Origin,
ReceivedAt: doc.Data.ReceivedAt,
Status: doc.Data.Status,
CompletedAt: doc.Data.CompletedAt,
FailedAt: doc.Data.FailedAt,
Data: data,
}
}
type RelayResponse struct {
ID string `json:"id"`
Relayer string `json:"relayer"`
Status string `json:"status"`
ReceivedAt time.Time `json:"receivedAt"`
CompletedAt *time.Time `json:"completedAt"`
FailedAt *time.Time `json:"failedAt"`
Data *RelayDataResponse `json:"data"`
}
type RelayDataResponse struct {
FromTxHash string `json:"fromTxHash"`
ToTxHash *string `json:"toTxHash"`
Instructions InstructionsResponse `json:"instructions"`
Delivery DeliveryReponse `json:"delivery"`
}
type DeliveryReponse struct {
ResultExecution ResultExecutionResponse `json:"execution"`
RelayGasUsed int `json:"relayGasUsed"`
}
type ResultExecutionResponse struct {
TransactionHash string `json:"transactionHash"`
RefundStatus string `json:"refundStatus"`
RevertString string `json:"revertString"`
Status string `json:"status"`
GasUsed string `json:"gasUsed"`
Detail string `json:"detail"`
}
type InstructionsResponse struct {
EncodedExecutionInfo string `json:"encodedExecutionInfo"`
RefundAddress string `json:"refundAddress"`
SourceDeliveryProvider string `json:"sourceDeliveryProvider"`
SenderAddress string `json:"senderAddress"`
VaaKeys []any `json:"vaaKeys"`
ExtraReceiverValue struct {
Hex string `json:"_hex"`
IsBigNumber bool `json:"_isBigNumber"`
} `json:"extraReceiverValue"`
TargetAddress string `json:"targetAddress"`
RequestedReceiverValue struct {
Hex string `json:"_hex"`
IsBigNumber bool `json:"_isBigNumber"`
} `json:"requestedReceiverValue"`
RefundChainID int `json:"refundChainId"`
RefundDeliveryProvider string `json:"refundDeliveryProvider"`
TargetChainID int `json:"targetChainId"`
}