MCPcopy Index your code
hub / github.com/api3dao/airnode / encode

Function encode

packages/airnode-abi/src/encoding.ts:41–66  ·  view source on GitHub ↗
(parameters: InputParameter[])

Source from the content-addressed store, hash-verified

39}
40
41export function encode(parameters: InputParameter[]): string {
42 const types = parameters.map((parameter) => parameter.type) as ParameterType[];
43
44 // Each parameter name is represented by a `bytes32` string. The value
45 // types are what the user provides
46 const nameTypePairs = flatMap(types, (type) => {
47 const transformedType = TYPE_TRANSFORMATIONS[type];
48 return ['bytes32', transformedType ?? type];
49 });
50
51 // The first type is always a bytes32 as it represents the schema header
52 const allTypes = ['bytes32', ...nameTypePairs];
53
54 // Build the schema which includes the version and the abbreviated list of parameters
55 const schemaHeader = buildSchemaHeader(types as ParameterType[]);
56 const encodedHeader = ethers.utils.formatBytes32String(schemaHeader);
57
58 // Map and encode each name/value pair where necessary
59 const flatNameValues = buildNameValuePairs(parameters);
60
61 // The schema header is always the first value to be encoded
62 const allValues = [encodedHeader, ...flatNameValues];
63
64 const encoder = new ethers.utils.AbiCoder();
65 return encoder.encode(allTypes, allValues);
66}

Callers 11

createTemplatesFunction · 0.90
makeTemplateRequestFunction · 0.90
makeFullRequestFunction · 0.90
getEncodedParametersFunction · 0.90
getEncodedParametersFunction · 0.90
getEncodedParametersFunction · 0.90
getEncodedParametersFunction · 0.90
getEncodedParametersFunction · 0.90
getEncodedParametersFunction · 0.90
getEncodedParametersFunction · 0.90

Calls 2

buildSchemaHeaderFunction · 0.85
buildNameValuePairsFunction · 0.85

Tested by

no test coverage detected