MCPcopy Create free account
hub / github.com/api3dao/airnode / processSuccessfulApiCall

Function processSuccessfulApiCall

packages/airnode-node/src/api/index.ts:214–295  ·  view source on GitHub ↗
(
  payload: ApiCallPayload,
  rawResponse: PerformApiCallSuccess
)

Source from the content-addressed store, hash-verified

212}
213
214export async function processSuccessfulApiCall(
215 payload: ApiCallPayload,
216 rawResponse: PerformApiCallSuccess
217): Promise<LogsData<ApiCallResponse>> {
218 const { type, config, aggregatedApiCall } = payload;
219 const { endpointName, oisTitle, parameters } = aggregatedApiCall;
220 const ois = config.ois.find((o) => o.title === oisTitle)!;
221 const endpoint = ois.endpoints.find((e) => e.name === endpointName)!;
222 // _minConfirmations is handled prior to the API call
223 const { _type, _path, _times, _gasPrice } = getReservedParameters(endpoint, parameters);
224
225 const goPostProcessApiSpecifications = await go(() =>
226 postProcessResponse(rawResponse.data, endpoint, aggregatedApiCall.parameters, {
227 totalTimeoutMs: PROCESSING_TIMEOUT,
228 })
229 );
230 if (!goPostProcessApiSpecifications.success) {
231 const log = logger.pend('ERROR', goPostProcessApiSpecifications.error.message);
232 return [[log], { success: false, errorMessage: goPostProcessApiSpecifications.error.message }];
233 }
234 const postProcessedData = goPostProcessApiSpecifications.data;
235
236 const goExtractAndEncodeResponse = goSync(() =>
237 adapter.extractAndEncodeResponse(postProcessedData.response, {
238 _type,
239 _path,
240 _times,
241 } as adapter.ResponseReservedParameters)
242 );
243 if (!goExtractAndEncodeResponse.success) {
244 const log = logger.pend('ERROR', goExtractAndEncodeResponse.error.message);
245 // The HTTP gateway is a special case for ChainAPI where we return data from a successful API call that failed processing
246 if (type === 'http-gateway') {
247 return [
248 [log],
249 { success: true, errorMessage: goExtractAndEncodeResponse.error.message, data: { rawValue: rawResponse.data } },
250 ];
251 }
252 return [[log], { success: false, errorMessage: goExtractAndEncodeResponse.error.message }];
253 }
254
255 const response = goExtractAndEncodeResponse.data;
256
257 switch (type) {
258 case 'http-gateway':
259 return [[], { success: true, data: response }];
260 case 'regular': {
261 const goSignWithRequestId = await go(() => signWithRequestId(aggregatedApiCall.id, response.encodedValue));
262 if (!goSignWithRequestId.success) {
263 const log = logger.pend('ERROR', goSignWithRequestId.error.message);
264 return [[log], { success: false, errorMessage: goSignWithRequestId.error.message }];
265 }
266
267 return [
268 [],
269 {
270 success: true,
271 data: { encodedValue: response.encodedValue, signature: goSignWithRequestId.data },

Callers 1

callApiFunction · 0.85

Calls 3

getReservedParametersFunction · 0.90
signWithRequestIdFunction · 0.85
signWithTemplateIdFunction · 0.85

Tested by

no test coverage detected