"use strict";
/**
 * This code was AUTOGENERATED using the kinobi library.
 * Please DO NOT EDIT THIS FILE, instead use visitors
 * to add features, then rerun kinobi to update it.
 *
 * @see https://github.com/metaplex-foundation/kinobi
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.safeFetchEditionMarkerFromSeeds = exports.fetchEditionMarkerFromSeeds = exports.findEditionMarkerPda = exports.getEditionMarkerSize = exports.getEditionMarkerGpaBuilder = exports.safeFetchAllEditionMarker = exports.fetchAllEditionMarker = exports.safeFetchEditionMarker = exports.fetchEditionMarker = exports.deserializeEditionMarker = exports.getEditionMarkerAccountDataSerializer = void 0;
const umi_1 = require("@metaplex-foundation/umi");
const serializers_1 = require("@metaplex-foundation/umi/serializers");
const types_1 = require("../types");
function getEditionMarkerAccountDataSerializer() {
    return (0, serializers_1.mapSerializer)((0, serializers_1.struct)([
        ['key', (0, types_1.getKeySerializer)()],
        ['ledger', (0, serializers_1.array)((0, serializers_1.u8)(), { size: 31 })],
    ], { description: 'EditionMarkerAccountData' }), (value) => ({ ...value, key: types_1.Key.EditionMarker }));
}
exports.getEditionMarkerAccountDataSerializer = getEditionMarkerAccountDataSerializer;
function deserializeEditionMarker(rawAccount) {
    return (0, umi_1.deserializeAccount)(rawAccount, getEditionMarkerAccountDataSerializer());
}
exports.deserializeEditionMarker = deserializeEditionMarker;
async function fetchEditionMarker(context, publicKey, options) {
    const maybeAccount = await context.rpc.getAccount((0, umi_1.publicKey)(publicKey, false), options);
    (0, umi_1.assertAccountExists)(maybeAccount, 'EditionMarker');
    return deserializeEditionMarker(maybeAccount);
}
exports.fetchEditionMarker = fetchEditionMarker;
async function safeFetchEditionMarker(context, publicKey, options) {
    const maybeAccount = await context.rpc.getAccount((0, umi_1.publicKey)(publicKey, false), options);
    return maybeAccount.exists ? deserializeEditionMarker(maybeAccount) : null;
}
exports.safeFetchEditionMarker = safeFetchEditionMarker;
async function fetchAllEditionMarker(context, publicKeys, options) {
    const maybeAccounts = await context.rpc.getAccounts(publicKeys.map((key) => (0, umi_1.publicKey)(key, false)), options);
    return maybeAccounts.map((maybeAccount) => {
        (0, umi_1.assertAccountExists)(maybeAccount, 'EditionMarker');
        return deserializeEditionMarker(maybeAccount);
    });
}
exports.fetchAllEditionMarker = fetchAllEditionMarker;
async function safeFetchAllEditionMarker(context, publicKeys, options) {
    const maybeAccounts = await context.rpc.getAccounts(publicKeys.map((key) => (0, umi_1.publicKey)(key, false)), options);
    return maybeAccounts
        .filter((maybeAccount) => maybeAccount.exists)
        .map((maybeAccount) => deserializeEditionMarker(maybeAccount));
}
exports.safeFetchAllEditionMarker = safeFetchAllEditionMarker;
function getEditionMarkerGpaBuilder(context) {
    const programId = context.programs.getPublicKey('mplTokenMetadata', 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s');
    return (0, umi_1.gpaBuilder)(context, programId)
        .registerFields({
        key: [0, (0, types_1.getKeySerializer)()],
        ledger: [1, (0, serializers_1.array)((0, serializers_1.u8)(), { size: 31 })],
    })
        .deserializeUsing((account) => deserializeEditionMarker(account))
        .whereField('key', types_1.Key.EditionMarker);
}
exports.getEditionMarkerGpaBuilder = getEditionMarkerGpaBuilder;
function getEditionMarkerSize() {
    return 32;
}
exports.getEditionMarkerSize = getEditionMarkerSize;
function findEditionMarkerPda(context, seeds) {
    const programId = context.programs.getPublicKey('mplTokenMetadata', 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s');
    return context.eddsa.findPda(programId, [
        (0, serializers_1.string)({ size: 'variable' }).serialize('metadata'),
        (0, serializers_1.publicKey)().serialize(programId),
        (0, serializers_1.publicKey)().serialize(seeds.mint),
        (0, serializers_1.string)({ size: 'variable' }).serialize('edition'),
        (0, serializers_1.string)({ size: 'variable' }).serialize(seeds.editionMarker),
    ]);
}
exports.findEditionMarkerPda = findEditionMarkerPda;
async function fetchEditionMarkerFromSeeds(context, seeds, options) {
    return fetchEditionMarker(context, findEditionMarkerPda(context, seeds), options);
}
exports.fetchEditionMarkerFromSeeds = fetchEditionMarkerFromSeeds;
async function safeFetchEditionMarkerFromSeeds(context, seeds, options) {
    return safeFetchEditionMarker(context, findEditionMarkerPda(context, seeds), options);
}
exports.safeFetchEditionMarkerFromSeeds = safeFetchEditionMarkerFromSeeds;
//# sourceMappingURL=editionMarker.js.map