MCPcopy Create free account
hub / github.com/ccxt/ccxt / pack

Function pack

js/src/static_dependencies/ethers/coders/array.js:8–52  ·  view source on GitHub ↗
(writer, coders, values)

Source from the content-addressed store, hash-verified

6 * @_ignore
7 */
8export function pack(writer, coders, values) {
9 let arrayValues = [];
10 if (Array.isArray(values)) {
11 arrayValues = values;
12 }
13 else if (values && typeof (values) === "object") {
14 let unique = {};
15 arrayValues = coders.map((coder) => {
16 const name = coder.localName;
17 assert(name, "cannot encode object for signature with missing names", "INVALID_ARGUMENT", { argument: "values", info: { coder }, value: values });
18 assert(!unique[name], "cannot encode object for signature with duplicate names", "INVALID_ARGUMENT", { argument: "values", info: { coder }, value: values });
19 unique[name] = true;
20 return values[name];
21 });
22 }
23 else {
24 assertArgument(false, "invalid tuple value", "tuple", values);
25 }
26 assertArgument(coders.length === arrayValues.length, "types/value length mismatch", "tuple", values);
27 let staticWriter = new Writer();
28 let dynamicWriter = new Writer();
29 let updateFuncs = [];
30 coders.forEach((coder, index) => {
31 let value = arrayValues[index];
32 if (coder.dynamic) {
33 // Get current dynamic offset (for the future pointer)
34 let dynamicOffset = dynamicWriter.length;
35 // Encode the dynamic value into the dynamicWriter
36 coder.encode(dynamicWriter, value);
37 // Prepare to populate the correct offset once we are done
38 let updateFunc = staticWriter.writeUpdatableValue();
39 updateFuncs.push((baseOffset) => {
40 updateFunc(baseOffset + dynamicOffset);
41 });
42 }
43 else {
44 coder.encode(staticWriter, value);
45 }
46 });
47 // Backfill all the dynamic offsets, now that we know the static length
48 updateFuncs.forEach((func) => { func(staticWriter.length); });
49 let length = writer.appendWriter(staticWriter);
50 length += writer.appendWriter(dynamicWriter);
51 return length;
52}
53/**
54 * @_ignore
55 */

Callers 3

encodeMethod · 0.90
encodeMethod · 0.90
encodeMethod · 0.70

Calls 9

writeUpdatableValueMethod · 0.95
assertFunction · 0.90
assertArgumentFunction · 0.90
pushMethod · 0.80
isArrayMethod · 0.45
mapMethod · 0.45
forEachMethod · 0.45
encodeMethod · 0.45
appendWriterMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…