* 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, data)
| 753 | * corresponding error. |
| 754 | */ |
| 755 | decodeFunctionResult(fragment, data) { |
| 756 | if (typeof (fragment) === "string") { |
| 757 | const f = this.getFunction(fragment); |
| 758 | assertArgument(f, "unknown function", "fragment", fragment); |
| 759 | fragment = f; |
| 760 | } |
| 761 | let message = "invalid length for result data"; |
| 762 | const bytes = getBytesCopy(data); |
| 763 | if ((bytes.length % 32) === 0) { |
| 764 | try { |
| 765 | return this.#abiCoder.decode(fragment.outputs, bytes); |
| 766 | } |
| 767 | catch (error) { |
| 768 | message = "could not decode result data"; |
| 769 | } |
| 770 | } |
| 771 | // Call returned data with no error, but the data is junk |
| 772 | assert(false, message, "BAD_DATA", { |
| 773 | value: hexlify(bytes), |
| 774 | info: { method: fragment.name, signature: fragment.format() } |
| 775 | }); |
| 776 | } |
| 777 | makeError(_data, tx) { |
| 778 | const data = getBytes(_data, "data"); |
| 779 | const error = AbiCoder.getBuiltinCallException("call", tx, data); |
no test coverage detected