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

Method decodeFunctionResult

src.ts/abi/interface.ts:897–920  ·  view source on GitHub ↗

* Decodes the result %%data%% (e.g. from an ``eth_call``) for the * specified function (see [[getFunction]] for valid values for * %%key%%). * * Most developers should prefer the [[parseCallResult]] method instead, * which will automatically detect a ``CALL_EXCEPTION``

(fragment: FunctionFragment | string, data: BytesLike)

Source from the content-addressed store, hash-verified

895 * corresponding error.
896 */
897 decodeFunctionResult(fragment: FunctionFragment | string, data: BytesLike): Result {
898 if (typeof(fragment) === "string") {
899 const f = this.getFunction(fragment);
900 assertArgument(f, "unknown function", "fragment", fragment);
901 fragment = f;
902 }
903
904 let message = "invalid length for result data";
905
906 const bytes = getBytesCopy(data);
907 if ((bytes.length % 32) === 0) {
908 try {
909 return this.#abiCoder.decode(fragment.outputs, bytes);
910 } catch (error) {
911 message = "could not decode result data";
912 }
913 }
914
915 // Call returned data with no error, but the data is junk
916 assert(false, message, "BAD_DATA", {
917 value: hexlify(bytes),
918 info: { method: fragment.name, signature: fragment.format() }
919 });
920 }
921
922 makeError(_data: BytesLike, tx: CallExceptionTransaction): CallExceptionError {
923 const data = getBytes(_data, "data");

Callers 3

#fetchMethod · 0.45
staticCallResultFunction · 0.45
test-abi.tsFile · 0.45

Calls 7

getFunctionMethod · 0.95
assertArgumentFunction · 0.90
getBytesCopyFunction · 0.90
assertFunction · 0.90
hexlifyFunction · 0.90
decodeMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected