"use strict";
/**
 * This code was AUTOGENERATED using the codama library.
 * Please DO NOT EDIT THIS FILE, instead use visitors
 * to add features, then rerun codama to update it.
 *
 * @see https://github.com/codama-idl/codama
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.USED_NONCE_DISCRIMINATOR = void 0;
exports.getUsedNonceDiscriminatorBytes = getUsedNonceDiscriminatorBytes;
exports.getUsedNonceEncoder = getUsedNonceEncoder;
exports.getUsedNonceDecoder = getUsedNonceDecoder;
exports.getUsedNonceCodec = getUsedNonceCodec;
exports.decodeUsedNonce = decodeUsedNonce;
exports.fetchUsedNonce = fetchUsedNonce;
exports.fetchMaybeUsedNonce = fetchMaybeUsedNonce;
exports.fetchAllUsedNonce = fetchAllUsedNonce;
exports.fetchAllMaybeUsedNonce = fetchAllMaybeUsedNonce;
exports.getUsedNonceSize = getUsedNonceSize;
const kit_1 = require("@solana/kit");
exports.USED_NONCE_DISCRIMINATOR = new Uint8Array([
    212, 222, 157, 252, 130, 71, 179, 238,
]);
function getUsedNonceDiscriminatorBytes() {
    return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.USED_NONCE_DISCRIMINATOR);
}
function getUsedNonceEncoder() {
    return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
        ['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
        ['isUsed', (0, kit_1.getBooleanEncoder)()],
    ]), (value) => ({ ...value, discriminator: exports.USED_NONCE_DISCRIMINATOR }));
}
function getUsedNonceDecoder() {
    return (0, kit_1.getStructDecoder)([
        ['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
        ['isUsed', (0, kit_1.getBooleanDecoder)()],
    ]);
}
function getUsedNonceCodec() {
    return (0, kit_1.combineCodec)(getUsedNonceEncoder(), getUsedNonceDecoder());
}
function decodeUsedNonce(encodedAccount) {
    return (0, kit_1.decodeAccount)(encodedAccount, getUsedNonceDecoder());
}
async function fetchUsedNonce(rpc, address, config) {
    const maybeAccount = await fetchMaybeUsedNonce(rpc, address, config);
    (0, kit_1.assertAccountExists)(maybeAccount);
    return maybeAccount;
}
async function fetchMaybeUsedNonce(rpc, address, config) {
    const maybeAccount = await (0, kit_1.fetchEncodedAccount)(rpc, address, config);
    return decodeUsedNonce(maybeAccount);
}
async function fetchAllUsedNonce(rpc, addresses, config) {
    const maybeAccounts = await fetchAllMaybeUsedNonce(rpc, addresses, config);
    (0, kit_1.assertAccountsExist)(maybeAccounts);
    return maybeAccounts;
}
async function fetchAllMaybeUsedNonce(rpc, addresses, config) {
    const maybeAccounts = await (0, kit_1.fetchEncodedAccounts)(rpc, addresses, config);
    return maybeAccounts.map((maybeAccount) => decodeUsedNonce(maybeAccount));
}
function getUsedNonceSize() {
    return 9;
}
