/**
 * 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
 */
import { __assign, __awaiter, __generator } from "tslib";
import { assertAccountExists, assertAccountsExist, combineCodec, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fixDecoderSize, fixEncoderSize, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, getU64Decoder, getU64Encoder, transformEncoder, } from "@solana/kit";
export var USED_NONCES_DISCRIMINATOR = new Uint8Array([
    60, 112, 18, 72, 138, 181, 100, 138,
]);
export function getUsedNoncesDiscriminatorBytes() {
    return fixEncoderSize(getBytesEncoder(), 8).encode(USED_NONCES_DISCRIMINATOR);
}
/** Gets the encoder for {@link UsedNoncesArgs} account data. */
export function getUsedNoncesEncoder() {
    return transformEncoder(getStructEncoder([
        ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
        ["remoteDomain", getU32Encoder()],
        ["firstNonce", getU64Encoder()],
        ["usedNonces", getArrayEncoder(getU64Encoder(), { size: 100 })],
    ]), function (value) { return (__assign(__assign({}, value), { discriminator: USED_NONCES_DISCRIMINATOR })); });
}
/** Gets the decoder for {@link UsedNonces} account data. */
export function getUsedNoncesDecoder() {
    return getStructDecoder([
        ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
        ["remoteDomain", getU32Decoder()],
        ["firstNonce", getU64Decoder()],
        ["usedNonces", getArrayDecoder(getU64Decoder(), { size: 100 })],
    ]);
}
/** Gets the codec for {@link UsedNonces} account data. */
export function getUsedNoncesCodec() {
    return combineCodec(getUsedNoncesEncoder(), getUsedNoncesDecoder());
}
export function decodeUsedNonces(encodedAccount) {
    return decodeAccount(encodedAccount, getUsedNoncesDecoder());
}
export function fetchUsedNonces(rpc, address, config) {
    return __awaiter(this, void 0, void 0, function () {
        var maybeAccount;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, fetchMaybeUsedNonces(rpc, address, config)];
                case 1:
                    maybeAccount = _a.sent();
                    assertAccountExists(maybeAccount);
                    return [2 /*return*/, maybeAccount];
            }
        });
    });
}
export function fetchMaybeUsedNonces(rpc, address, config) {
    return __awaiter(this, void 0, void 0, function () {
        var maybeAccount;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, fetchEncodedAccount(rpc, address, config)];
                case 1:
                    maybeAccount = _a.sent();
                    return [2 /*return*/, decodeUsedNonces(maybeAccount)];
            }
        });
    });
}
export function fetchAllUsedNonces(rpc, addresses, config) {
    return __awaiter(this, void 0, void 0, function () {
        var maybeAccounts;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, fetchAllMaybeUsedNonces(rpc, addresses, config)];
                case 1:
                    maybeAccounts = _a.sent();
                    assertAccountsExist(maybeAccounts);
                    return [2 /*return*/, maybeAccounts];
            }
        });
    });
}
export function fetchAllMaybeUsedNonces(rpc, addresses, config) {
    return __awaiter(this, void 0, void 0, function () {
        var maybeAccounts;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, fetchEncodedAccounts(rpc, addresses, config)];
                case 1:
                    maybeAccounts = _a.sent();
                    return [2 /*return*/, maybeAccounts.map(function (maybeAccount) { return decodeUsedNonces(maybeAccount); })];
            }
        });
    });
}
export function getUsedNoncesSize() {
    return 820;
}
//# sourceMappingURL=usedNonces.js.map