Skip to content

Commit

Permalink
Add support to new vaa payload parser parse endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
walker-16 committed Jul 6, 2023
1 parent c4a55bd commit 51d1799
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
35 changes: 33 additions & 2 deletions parser/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"time"

sdk "github.com/wormhole-foundation/wormhole/sdk/vaa"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -60,8 +61,8 @@ type ParseData struct {
Fields interface{}
}

// ParseVaa invoke the endpoint to parse a VAA from the VAAParserAPI.
func (c ParserVAAAPIClient) Parse(chainID uint16, address, sequence string, vaa []byte) (*ParseVaaResponse, error) {
// ParsePayload invoke the endpoint to parse a VAA from the VAAParserAPI.
func (c ParserVAAAPIClient) ParsePayload(chainID uint16, address, sequence string, vaa []byte) (*ParseVaaResponse, error) {
endpointUrl := fmt.Sprintf("%s/vaa/parser/%v/%s/%v", c.BaseURL, chainID,
address, sequence)

Expand Down Expand Up @@ -102,3 +103,33 @@ func (c ParserVAAAPIClient) Parse(chainID uint16, address, sequence string, vaa
return nil, ErrInternalError
}
}

// ParseVaaStandardResponse represent a parse vaa payload and standard fields.
type ParseVaaStandardResponse struct {
}

// ParseVaa invoke the endpoint to parse a VAA from the VAAParserAPI to get payload and standard fields.
func (c *ParserVAAAPIClient) ParseVaa(vaa *sdk.VAA) (*ParseVaaStandardResponse, error) {
//endpointUrl := fmt.Sprintf("%s/vaas/parse", c.BaseURL)

// vaaBytes, err := vaa.Marshal()
// if err != nil {
// return nil, errors.New("error marshalling vaa")
// }

// body := struct {
// Body string `json: "body"`
// }{
// Body: string(vaaBytes),
// }

// response, err := c.Client.Post(endpointUrl, "application/json", bytes.NewBuffer(body))
// if err != nil {
// c.Logger.Error("error call parse vaa endpoint", zap.Error(err), zap.Uint16("chainID", uint16(vaa.EmitterChain)),
// zap.String("address", vaa.EmitterAddress.String()), zap.Uint64("sequence", vaa.Sequence))
// return nil, ErrCallEndpoint
// }
// defer response.Body.Close()

return nil, nil
}
10 changes: 5 additions & 5 deletions parser/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestSuccessVAAParser(t *testing.T) {
var chainID uint16 = 4
address := "000000000000000000000003ee18b2214aff97000d974cf647e7c347e8fa585"
sequence := "226769"
parserVaaResponse, err := parserVaaClient.Parse(chainID, address, sequence, []byte{})
parserVaaResponse, err := parserVaaClient.ParsePayload(chainID, address, sequence, []byte{})
if err != nil {
t.Error("expected err zero value, got %w", err)
}
Expand All @@ -67,7 +67,7 @@ func TestNotFoundVaaParser(t *testing.T) {
StatusCode: http.StatusNotFound,
}
})
parserVaaResponse, err := parserVaaClient.Parse(4, "000000000000000000000003ee18b2214aff97000d974cf647e7c347e8fa585", "226769", []byte{})
parserVaaResponse, err := parserVaaClient.ParsePayload(4, "000000000000000000000003ee18b2214aff97000d974cf647e7c347e8fa585", "226769", []byte{})
if err == nil {
t.Error("expected error, got nil")
}
Expand All @@ -86,7 +86,7 @@ func TestBadRequestVaaParser(t *testing.T) {
StatusCode: http.StatusBadRequest,
}
})
parserVaaResponse, err := parserVaaClient.Parse(4, "000000000000000000000003ee18b2214aff97000d974cf647e7c347e8fa585", "226769", []byte{})
parserVaaResponse, err := parserVaaClient.ParsePayload(4, "000000000000000000000003ee18b2214aff97000d974cf647e7c347e8fa585", "226769", []byte{})
if err == nil {
t.Error("expected error, got nil")
}
Expand All @@ -105,7 +105,7 @@ func TestUnprocessableVaaParser(t *testing.T) {
StatusCode: http.StatusUnprocessableEntity,
}
})
parserVaaResponse, err := parserVaaClient.Parse(4, "000000000000000000000003ee18b2214aff97000d974cf647e7c347e8fa585", "26769", []byte{})
parserVaaResponse, err := parserVaaClient.ParsePayload(4, "000000000000000000000003ee18b2214aff97000d974cf647e7c347e8fa585", "26769", []byte{})
if err == nil {
t.Error("expected error, got nil")
}
Expand All @@ -124,7 +124,7 @@ func TestInternalErrorVaaParser(t *testing.T) {
StatusCode: http.StatusInternalServerError,
}
})
parserVaaResponse, err := parserVaaClient.Parse(4, "000000000000000000000003ee18b2214aff97000d974cf647e7c347e8fa585", "226769", []byte{})
parserVaaResponse, err := parserVaaClient.ParsePayload(4, "000000000000000000000003ee18b2214aff97000d974cf647e7c347e8fa585", "226769", []byte{})
if err == nil {
t.Error("expected error, got nil")
}
Expand Down
2 changes: 1 addition & 1 deletion parser/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (p *Processor) Process(ctx context.Context, vaaBytes []byte) (*parser.Parse
sequence := fmt.Sprintf("%d", vaa.Sequence)

p.metrics.IncVaaPayloadParserRequestCount(chainID)
vaaParseResponse, err := p.parser.Parse(chainID, emitterAddress, sequence, vaa.Payload)
vaaParseResponse, err := p.parser.ParsePayload(chainID, emitterAddress, sequence, vaa.Payload)
if err != nil {
// split metrics error not found and others errors.
if errors.Is(err, parser.ErrNotFound) {
Expand Down

0 comments on commit 51d1799

Please sign in to comment.