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

Function buildOptions

packages/airnode-node/src/api/index.ts:26–80  ·  view source on GitHub ↗
(payload: ApiCallPayload)

Source from the content-addressed store, hash-verified

24} from '../types';
25
26export function buildOptions(payload: ApiCallPayload): adapter.BuildRequestOptions {
27 const { type, config, aggregatedApiCall } = payload;
28 const { endpointName, parameters, oisTitle } = aggregatedApiCall;
29
30 const ois = config.ois.find((o) => o.title === oisTitle)!;
31 const apiCredentials = config.apiCredentials
32 .filter((c) => c.oisTitle === oisTitle)
33 .map((c) => removeKey(c, 'oisTitle')) as adapter.BaseApiCredentials[];
34
35 // Gather the default endpoint parameter values
36 const endpoint = ois.endpoints.find((endpoint) => endpoint.name === endpointName)!;
37 const defaultParameters = endpoint.parameters
38 .filter((p) => p.default !== undefined)
39 .reduce((acc, p) => ({ ...acc, [p.name]: p.default! }), {} as ApiCallParameters);
40
41 // Override (and merge) the default endpoint parameters with the user parameters
42 const allParameters = { ...defaultParameters, ...parameters };
43
44 // Don't submit the reserved parameters to the API
45 const sanitizedParameters: adapter.Parameters = removeKeys(allParameters, RESERVED_PARAMETERS);
46
47 switch (type) {
48 case 'http-signed-data-gateway':
49 case 'http-gateway': {
50 return {
51 endpointName,
52 parameters: sanitizedParameters,
53 ois,
54 apiCredentials,
55 metadata: null,
56 };
57 }
58 case 'regular': {
59 const { requesterAddress, sponsorAddress, sponsorWalletAddress, id, chainId } = aggregatedApiCall;
60
61 // Find the chain config based on the aggregatedApiCall chainId
62 const chain = config.chains.find((c) => c.id === chainId);
63
64 return {
65 endpointName,
66 parameters: sanitizedParameters,
67 ois,
68 apiCredentials,
69 metadata: {
70 requesterAddress: requesterAddress,
71 sponsorAddress: sponsorAddress,
72 sponsorWalletAddress: sponsorWalletAddress,
73 requestId: id,
74 chainId: chainId,
75 chainType: chain?.type || 'evm',
76 },
77 };
78 }
79 }
80}
81
82export function signWithRequestId(requestId: string, data: string) {
83 const airnodeWallet = getAirnodeWalletFromPrivateKey();

Callers 1

performApiCallFunction · 0.85

Calls 2

removeKeyFunction · 0.90
removeKeysFunction · 0.90

Tested by

no test coverage detected