Skip to content

Commit

Permalink
finish attestation api chain of calls
Browse files Browse the repository at this point in the history
  • Loading branch information
bukata-sa committed Dec 2, 2024
1 parent 51f9182 commit 0ef7aec
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package lbtc

import (
"bytes"
"context"
"crypto/sha256"
"encoding/json"
"fmt"
"net/url"
"sync"
Expand Down Expand Up @@ -79,6 +81,10 @@ type messageAttestationResponse struct {
}

// TODO: Adjust after checking API docs
type attestationRequest struct {
PayloadHashes []string `json:"messageHash"`
}

type attestationResponse struct {
Attestations []messageAttestationResponse `json:"attestations"`
}
Expand Down Expand Up @@ -283,15 +289,24 @@ func (s *TokenDataReader) getLBTCPayloadAndHash(ctx context.Context, msg cciptyp
}

func (s *TokenDataReader) callAttestationApi(ctx context.Context, lbtcMessageHash [32]byte) (attestationResponse, error) {
_, _, _, err := s.httpClient.Get(ctx, "", s.attestationApiTimeout)
attestationUrl := fmt.Sprintf("%s/bridge/%s/%s", s.attestationApi.String(), apiVersion, attestationPath)
request := attestationRequest{PayloadHashes: []string{hexutil.Encode(lbtcMessageHash[:])}}
encodedRequest, err := json.Marshal(request)
requestBuffer := bytes.NewBuffer(encodedRequest)
if err != nil {
return attestationResponse{}, err
}
respRaw, _, _, err := s.httpClient.Post(ctx, attestationUrl, requestBuffer, s.attestationApiTimeout)
switch {
case errors.Is(err, tokendata.ErrRateLimit):
s.setCoolDownPeriod(defaultCoolDownDuration)
return attestationResponse{}, tokendata.ErrRateLimit
case err != nil:
return attestationResponse{}, err
}
return attestationResponse{}, nil
var attestationResp attestationResponse
err = json.Unmarshal(respRaw, &attestationResp)
return attestationResp, err
}

func encodePayloadAndProof(payload []byte, attestation string) ([]byte, error) {
Expand Down

0 comments on commit 0ef7aec

Please sign in to comment.