var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { ethers } from "ethers";
import { triggerContract, viewContract, getContract } from "../../../utils/tronweb/contractHelper";
import ERC1155ABI from "../../../config/abi/common/abi-erc1155.json";
export const erc1155IsApprovedForAll = (provider, owner, spender, tokenContractAddress, callback) => __awaiter(void 0, void 0, void 0, function* () {
    const contract = yield getContract(provider, tokenContractAddress, ERC1155ABI);
    const results = yield viewContract(contract, "isApprovedForAll", [owner, spender]);
    return results.length ? results[0] : false;
});
export const erc1155BalanceOf = (provider, owner, tokenId, tokenContractAddress, callback) => __awaiter(void 0, void 0, void 0, function* () {
    const contract = yield getContract(provider, tokenContractAddress, ERC1155ABI);
    const results = yield viewContract(contract, "balanceOf", [owner, tokenId]);
    return results.length ? results[0].toHexString() : ethers.utils.hexValue(0);
});
export const erc1155BalanceOfBatch = (provider, owners, tokenIds, tokenContractAddress, callback) => __awaiter(void 0, void 0, void 0, function* () {
    const contract = yield getContract(provider, tokenContractAddress, ERC1155ABI);
    const results = yield viewContract(contract, "balanceOfBatch", [owners, tokenIds]);
    return results.length
        ? results[0].map((item) => {
            return item.toHexString();
        })
        : [ethers.utils.hexValue(0)];
});
export const erc1155SetApprovalForAll = (signer, contractAddress, spender, approved, callback) => __awaiter(void 0, void 0, void 0, function* () {
    const contract = yield getContract(signer, contractAddress, ERC1155ABI);
    return triggerContract(contract, "setApprovalForAll", [spender, approved], callback);
});
export const erc1155SafeBatchTransferFrom = (signer, contractAddress, spender, approved, callback) => __awaiter(void 0, void 0, void 0, function* () {
    const contract = yield getContract(signer, contractAddress, ERC1155ABI);
    return triggerContract(contract, "safeBatchTransferFrom", [spender, approved], callback);
});
