@@ -33,16 +33,16 @@ type attestationRequest struct {
33
33
}
34
34
35
35
type AttestationResponse struct {
36
- Attestations []MessageAttestationResponse `json:"attestations"`
36
+ Attestations []Attestation `json:"attestations"`
37
37
// fields in case of error
38
38
Code int `json:"code,omitempty"`
39
39
Message string `json:"message,omitempty"`
40
40
}
41
41
42
- type MessageAttestationResponse struct {
42
+ type Attestation struct {
43
43
MessageHash string `json:"message_hash"`
44
44
Status AttestationStatus `json:"status"`
45
- Attestation string `json:"attestation,omitempty"` // Attestation represented by abi.encode(payload, proof)
45
+ Data string `json:"attestation,omitempty"` // Data is represented by abi.encode(payload, proof)
46
46
}
47
47
48
48
type LBTCAttestationClient struct {
@@ -60,7 +60,7 @@ func NewLBTCAttestationClient(
60
60
config .AttestationAPI ,
61
61
config .AttestationAPIInterval .Duration (),
62
62
config .AttestationAPITimeout .Duration (),
63
- 0 ,
63
+ 0 , // no LBTC API cooldown
64
64
)
65
65
if err != nil {
66
66
return nil , fmt .Errorf ("get http client: %w" , err )
@@ -74,6 +74,8 @@ func NewLBTCAttestationClient(
74
74
), nil
75
75
}
76
76
77
+ // Attestations is an AttestationClient method that accepts dict of messages and returns attestations under same keys.
78
+ // As values in input it accepts ExtraData bytes from incoming TokenData
77
79
func (c * LBTCAttestationClient ) Attestations (
78
80
ctx context.Context ,
79
81
messages map [cciptypes.ChainSelector ]map [reader.MessageTokenID ]cciptypes.Bytes ,
@@ -112,23 +114,25 @@ func (c *LBTCAttestationClient) Attestations(
112
114
return res , nil
113
115
}
114
116
115
- func (c * LBTCAttestationClient ) Token () string {
116
- return LBTCToken
117
+ func (c * LBTCAttestationClient ) Type () string {
118
+ return pluginconfig . LBTCHandlerType
117
119
}
118
120
121
+ // fetchBatch makes an HTTP Post request to Lombard Attestation API, requesting all messageHashes at once.
122
+ // This method doesn't check for input batch size.
119
123
func (c * LBTCAttestationClient ) fetchBatch (
120
124
ctx context.Context ,
121
- batch []string ,
125
+ messageHashes []string ,
122
126
) (map [string ]tokendata.AttestationStatus , error ) {
123
- request := attestationRequest {PayloadHashes : batch }
127
+ request := attestationRequest {PayloadHashes : messageHashes }
124
128
encodedRequest , err := json .Marshal (request )
125
129
if err != nil {
126
130
return nil , fmt .Errorf ("failed to marshal attestation request: %w" , err )
127
131
}
128
132
attestations := make (map [string ]tokendata.AttestationStatus )
129
133
respRaw , _ , err := c .httpClient .Post (ctx , fmt .Sprintf ("bridge/%s/%s" , apiVersion , attestationPath ), encodedRequest )
130
134
if err != nil {
131
- for _ , inputMessageHash := range batch {
135
+ for _ , inputMessageHash := range messageHashes {
132
136
attestations [inputMessageHash ] = tokendata .ErrorAttestationStatus (err )
133
137
}
134
138
// absorb api error to each token data status
@@ -140,16 +144,16 @@ func (c *LBTCAttestationClient) fetchBatch(
140
144
return nil , fmt .Errorf ("failed to unmarshal attestation response: %w" , err )
141
145
}
142
146
if attestationResp .Code != 0 {
143
- for _ , inputMessageHash := range batch {
147
+ for _ , inputMessageHash := range messageHashes {
144
148
attestations [inputMessageHash ] = tokendata .ErrorAttestationStatus (
145
149
fmt .Errorf ("attestation request failed: %s" , attestationResp .Message ),
146
150
)
147
151
}
148
152
}
149
153
for _ , attestation := range attestationResp .Attestations {
150
- attestations [attestation .MessageHash ] = attestationToTokenData (attestation )
154
+ attestations [attestation .MessageHash ] = attestationToAttestationStatus (attestation )
151
155
}
152
- for _ , inputMessageHash := range batch {
156
+ for _ , inputMessageHash := range messageHashes {
153
157
if _ , ok := attestations [inputMessageHash ]; ! ok {
154
158
c .lggr .Warnw (
155
159
"Requested messageHash is missing in the response. Considering tokendata.ErrDataMissing" ,
@@ -160,7 +164,7 @@ func (c *LBTCAttestationClient) fetchBatch(
160
164
return attestations , nil
161
165
}
162
166
163
- func attestationToTokenData (attestation MessageAttestationResponse ) tokendata.AttestationStatus {
167
+ func attestationToAttestationStatus (attestation Attestation ) tokendata.AttestationStatus {
164
168
if attestation .Status == attestationStatusSubmitted || attestation .Status == attestationStatusPending {
165
169
return tokendata .ErrorAttestationStatus (tokendata .ErrNotReady )
166
170
}
@@ -171,7 +175,7 @@ func attestationToTokenData(attestation MessageAttestationResponse) tokendata.At
171
175
if err != nil {
172
176
return tokendata .ErrorAttestationStatus (fmt .Errorf ("failed to decode message hash in attestation: %w" , err ))
173
177
}
174
- attestationBytes , err := cciptypes .NewBytesFromString (attestation .Attestation )
178
+ attestationBytes , err := cciptypes .NewBytesFromString (attestation .Data )
175
179
if err != nil {
176
180
return tokendata .ErrorAttestationStatus (fmt .Errorf ("failed to decode attestation: %w" , err ))
177
181
}
0 commit comments