MCPcopy Create free account
hub / github.com/PageLeay/celestial-runtime / encodeTopic

Method encodeTopic

src.ts/abi/interface.ts:1021–1040  ·  view source on GitHub ↗
(param: ParamType, value: any)

Source from the content-addressed store, hash-verified

1019
1020 // @TODO: Use the coders for this; to properly support tuples, etc.
1021 const encodeTopic = (param: ParamType, value: any): string => {
1022 if (param.type === "string") {
1023 return id(value);
1024 } else if (param.type === "bytes") {
1025 return keccak256(hexlify(value));
1026 }
1027
1028 if (param.type === "bool" && typeof(value) === "boolean") {
1029 value = (value ? "0x01": "0x00");
1030 } else if (param.type.match(/^u?int/)) {
1031 value = toBeHex(value); // @TODO: Should this toTwos??
1032 } else if (param.type.match(/^bytes/)) {
1033 value = zeroPadBytes(value, 32);
1034 } else if (param.type === "address") {
1035 // Check addresses are valid
1036 this.#abiCoder.encode( [ "address" ], [ value ]);
1037 }
1038
1039 return zeroPadValue(hexlify(value), 32);
1040 };
1041
1042 values.forEach((value, index) => {
1043

Callers

nothing calls this directly

Calls 7

idFunction · 0.90
keccak256Function · 0.90
hexlifyFunction · 0.90
toBeHexFunction · 0.90
zeroPadBytesFunction · 0.90
zeroPadValueFunction · 0.90
encodeMethod · 0.45

Tested by

no test coverage detected