"use strict";
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());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.name = name;
exports.symbol = symbol;
exports.tokenUri = tokenUri;
exports.balanceOf = balanceOf;
exports.ownerOf = ownerOf;
exports.tokenOfOwnerByIndex = tokenOfOwnerByIndex;
exports.setApprovalForAll = setApprovalForAll;
const interface_1 = require("./interface");
function name(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const data = interface_1.erc721Iface.encodeFunctionData("name");
        const result = yield args.web3Lib.call({
            to: args.contractAddress,
            data: data
        });
        const [name] = interface_1.erc721Iface.decodeFunctionResult("name", result);
        return String(name);
    });
}
function symbol(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const data = interface_1.erc721Iface.encodeFunctionData("symbol");
        const result = yield args.web3Lib.call({
            to: args.contractAddress,
            data: data
        });
        const [symbol] = interface_1.erc721Iface.decodeFunctionResult("symbol", result);
        return String(symbol);
    });
}
function tokenUri(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const data = interface_1.erc721Iface.encodeFunctionData("tokenURI", [args.tokenId]);
        const result = yield args.web3Lib.call({
            to: args.contractAddress,
            data: data
        });
        const [tokenUri] = interface_1.erc721Iface.decodeFunctionResult("tokenURI", result);
        return String(tokenUri);
    });
}
function balanceOf(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const data = interface_1.erc721Iface.encodeFunctionData("balanceOf", [args.owner]);
        const result = yield args.web3Lib.call({
            to: args.contractAddress,
            data: data
        });
        const [balance] = interface_1.erc721Iface.decodeFunctionResult("balanceOf", result);
        return String(balance);
    });
}
function ownerOf(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const result = yield args.web3Lib.call({
            to: args.contractAddress,
            data: interface_1.erc721Iface.encodeFunctionData("ownerOf", [args.tokenId])
        });
        const [owner] = interface_1.erc721Iface.decodeFunctionResult("ownerOf", result);
        return String(owner);
    });
}
function tokenOfOwnerByIndex(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const result = yield args.web3Lib.call({
            to: args.contractAddress,
            data: interface_1.erc721Iface.encodeFunctionData("tokenOfOwnerByIndex", [
                args.owner,
                args.index
            ])
        });
        const [tokenId] = interface_1.erc721Iface.decodeFunctionResult("tokenOfOwnerByIndex", result);
        return String(tokenId);
    });
}
function setApprovalForAll(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const transactionRequest = Object.assign(Object.assign({}, args.txRequest), { to: args.contractAddress, data: interface_1.erc721Iface.encodeFunctionData("setApprovalForAll", [
                args.operator,
                args.approved
            ]) });
        if (args.returnTxInfo) {
            return transactionRequest;
        }
        else {
            return args.web3Lib.sendTransaction(transactionRequest);
        }
    });
}
//# sourceMappingURL=handler.js.map