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

Method decodeFunctionResult

ts/src/static_dependencies/ethers/interface.ts:896–919  ·  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

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

Callers

nothing calls this directly

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