* 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)
| 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 |
nothing calls this directly
no test coverage detected