// SPDX-License-Identifier: Apache-2.0
import { ethers } from "ethers";
import LogService from "../../app/service/log/LogService";
import { TransactionResponseError } from "./error/TransactionResponseError";
export class TransactionResponseAdapter {
    manageResponse() {
        throw new Error("Method not implemented.");
    }
    static decodeFunctionResult(functionName, resultAsBytes, abi, // eslint-disable-line
    network) {
        try {
            const iface = new ethers.Interface(abi);
            if (!iface.getFunction(functionName)) {
                throw new TransactionResponseError({
                    message: `Contract function ${functionName} not found in ABI, are you using the right version?`,
                    network: network,
                });
            }
            const resultHex = "0x".concat(Buffer.from(resultAsBytes).toString("hex"));
            const result = iface.decodeFunctionResult(functionName, resultHex);
            const jsonParsedArray = JSON.parse(JSON.stringify(result));
            return jsonParsedArray;
        }
        catch (error) {
            LogService.logError(error);
            throw new TransactionResponseError({
                message: "Could not decode function result",
                network: network,
            });
        }
    }
}
