/**
 * 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 { addDecoderSizePrefix, addEncoderSizePrefix, assertAccountExists, assertAccountsExist, combineCodec, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, transformEncoder, } from "@solana/kit";
export var ROOT_BUNDLE_DISCRIMINATOR = new Uint8Array([
    66, 221, 214, 231, 25, 222, 184, 219,
]);
export function getRootBundleDiscriminatorBytes() {
    return fixEncoderSize(getBytesEncoder(), 8).encode(ROOT_BUNDLE_DISCRIMINATOR);
}
/** Gets the encoder for {@link RootBundleArgs} account data. */
export function getRootBundleEncoder() {
    return transformEncoder(getStructEncoder([
        ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
        ["relayerRefundRoot", fixEncoderSize(getBytesEncoder(), 32)],
        ["slowRelayRoot", fixEncoderSize(getBytesEncoder(), 32)],
        [
            "claimedBitmap",
            addEncoderSizePrefix(getBytesEncoder(), getU32Encoder()),
        ],
    ]), function (value) { return (__assign(__assign({}, value), { discriminator: ROOT_BUNDLE_DISCRIMINATOR })); });
}
/** Gets the decoder for {@link RootBundle} account data. */
export function getRootBundleDecoder() {
    return getStructDecoder([
        ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
        ["relayerRefundRoot", fixDecoderSize(getBytesDecoder(), 32)],
        ["slowRelayRoot", fixDecoderSize(getBytesDecoder(), 32)],
        ["claimedBitmap", addDecoderSizePrefix(getBytesDecoder(), getU32Decoder())],
    ]);
}
/** Gets the codec for {@link RootBundle} account data. */
export function getRootBundleCodec() {
    return combineCodec(getRootBundleEncoder(), getRootBundleDecoder());
}
export function decodeRootBundle(encodedAccount) {
    return decodeAccount(encodedAccount, getRootBundleDecoder());
}
export function fetchRootBundle(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*/, fetchMaybeRootBundle(rpc, address, config)];
                case 1:
                    maybeAccount = _a.sent();
                    assertAccountExists(maybeAccount);
                    return [2 /*return*/, maybeAccount];
            }
        });
    });
}
export function fetchMaybeRootBundle(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*/, decodeRootBundle(maybeAccount)];
            }
        });
    });
}
export function fetchAllRootBundle(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*/, fetchAllMaybeRootBundle(rpc, addresses, config)];
                case 1:
                    maybeAccounts = _a.sent();
                    assertAccountsExist(maybeAccounts);
                    return [2 /*return*/, maybeAccounts];
            }
        });
    });
}
export function fetchAllMaybeRootBundle(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 decodeRootBundle(maybeAccount); })];
            }
        });
    });
}
//# sourceMappingURL=rootBundle.js.map